[jboss-user] [JBoss Tools] - Testing visual parts in JBT

Jiri Peterka do-not-reply at jboss.com
Tue Apr 5 07:16:36 EDT 2011


Jiri Peterka [http://community.jboss.org/people/jpeterka] created the document:

"Testing visual parts in JBT"

To view the document, visit: http://community.jboss.org/docs/DOC-16691

--------------------------------------------------------------
h1. Testing visual parts in JBT
h4. Document goal
This article should provide basic overview of  http://www.eclipse.org/swtbot/ SWTBot test development for various  http://www.eclipse.org/gef/ GEF based eclipse parts and other graphical representations.
h4. GEF Introduction for SWTBot test developers
Graphical Editing Framework (GEF) is widely used in  http://www.jboss.org/tools JBoss Tools Editors as well as many others 3rd party plugins. So there is a need for testing GUI based on it. API provided by SWTBot for GEF parts is available in  http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/ org.eclipse.swtbot.eclipse.gef* packages. Top classes are:
* SWTBotEclipseTestCase
* SWTGefBot
SWTBotEclipseTestCase encapsulates SWTGefBot for usage in GEF based tests. SWTBotGef provides high level methods for finding editor, view and viewer. These particular classes are located in  http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/ gef.finder.widgets package, namely:
* SWTBotGefEditor
* SWTBotGefView
* SWTBotGefViewer
h4. Usual scenario for GEF bot test:
* Locate GEF editor
* Access some element
* Check state
* Perform operation on it
* Check if operation is done
h4. Example of basic GEF usage
 SWTGefBot gefBot = new SWTGefBot();
SWTBotGefEditor editor = gefBot.gefEditor("simple");
SWTBotMultiPageEditor multi = new SWTBotMultiPageEditor(editor.getReference(), gefBot);
multi.activatePage("Diagram");
editor.getEditPart("start").select();

h4. SWTBotExt Limitations
There are several known issues related to GEF SWTBot:
* some elements can't be found via SWTGefBot
* context menu item is not always triggered successfully
* different platform issues
* timing and synchronization
* missing API for particular operations
* unreachable elements attributes from the bot
h4. SWTBotExt GEF
SWTBotExt GEF API tries to solve/workaround some of these limitations/issues and provides fine-grained approach for some operations. It can be found in org.jboss.tools.ui.bot.ext.gef package in org.jboss.tools.ui.bot.ext plug-in. It provides these basic classes:
* SWTBotGefEditorExt - uses SWTBotGefEditor and provides      additional routines for figures manipulation
* SWTBotGefViewerExt - provides methods for finding root figure 
* SWTBotGefFigure - provides access to GEF figure and it's      attributes
* SWTBotGefFinder - can finds particular elements like editor      canvas, etc.
* SWTBotGefMouse - general mouse controller for GEF Canvas. Can      be used in your GEF api or outside as well
* SWTGefContextMenuExt - context menu controller resolving bot      GEF context menu issues
* SWTArranger - provides facility for arranging figures on      canvas like resolving empty area, etc.
h4. Example changing label on a figure
 SWTBotGefEditorExt editor = new SWTBotGefEditorExt("simple");
SWTBotGefFigure label = editor.labelFigure("text");
editor.setLabelText(label, "new_text");
editor.save();

h4. Zest components
 http://www.eclipse.org/gef/zest/ GEF Zest API provides draw2d based components for visual data representation without editing features. Since SWTBot doesn't provide API for Zest manipulation SWTBotExt tries to cover this area
* SWTBotZestBot
* SWTBotZestGraph
* SWTBotZestContextMenu
* SWTBotZestNode
* SWTBotZestConnection
h4. Basic example of Zest Bot usage
 SWTZestBot zestBot = new SWTZestBot();
SWTBotZestGraph graph = zestBot.getZestGraph(0);
SWTBotZestNode node = graph.node("Input Task");
node.click();
SWTBotZestContextMenu menu = node.contextMenu();
menu.clickMenu("Add Task","Java Mapping");
graph.node("Input Task").click();
graph.connection(graph.node("Input Task"), graph.node("Java Mapping")).click();

h4. General approach for resolving issues
Area of Visual representation used in Eclipse editors and viewers is quite wide and there can scenarios where SWTBot and even SWTBotExt API can fail (based on editors implementations, platform issues, etc). Specific treatment for these cases is often needed so there is some general approach how to resolve them. Let's say we need to manipulate some element on editor and we are not able to do that via SWTBot. General approach is to:
* Get as deep as possible via SWTBot or SWTBotExt - to get at      least an editor
* Find root figure - to be able to access rest of the element      figures
* Find particular figures and get their boundaries
* Perform needed operation (via SWTBotMouse for example)
* if it's general problem, implement some API for further usage
h4. Other notes
Since there are quite often changes related to SWTBot GEF API not everything described here must be necessary best approach. So please watch  http://www.eclipse.org/swtbot/downloads.php SWTBot for latest updates or use an approach which fits you best.
h4. Related links
*  http://www.eclipse.org/swtbot/ SWTBot Main Page
*  http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/ SWTBot Javadoc
*  http://www.eclipse.org/gef/ Eclipse GEF
*  http://www.eclipse.org/gef/zest/ Eclipse Zest
h4. Further tasks related to GEF Bot Ext
* Refactor and clean API
* More generic approach
* Separate from main BotExt plugin
* Contribute into SWTBot if possible
--------------------------------------------------------------

Comment by going to Community
[http://community.jboss.org/docs/DOC-16691]

Create a new document in JBoss Tools at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2128]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110405/371c0ec3/attachment-0001.html 


More information about the jboss-user mailing list