<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Testing visual parts in JBT
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/jpeterka">Jiri Peterka</a> in <i>JBoss Tools</i> - <a href="http://community.jboss.org/docs/DOC-16691">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><h1>Testing visual parts in JBT</h1><h4>Document goal</h4><p>This article should provide basic overview of <a class="jive-link-external-small" href="http://www.eclipse.org/swtbot/">SWTBot</a> test development for various <a class="jive-link-external-small" href="http://www.eclipse.org/gef/">GEF</a> based eclipse parts and other graphical representations.</p><h4>GEF Introduction for SWTBot test developers</h4><p>Graphical Editing Framework (GEF) is widely used in <a class="jive-link-external-small" href="http://www.jboss.org/tools">JBoss Tools</a> 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 <a class="jive-link-external-small" href="http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/">org.eclipse.swtbot.eclipse.gef* packages</a>. Top classes are:</p><ul><li>SWTBotEclipseTestCase</li><li>SWTGefBot</li></ul><p>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 <a class="jive-link-external-small" href="http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/">gef.finder.widgets package</a>, namely:</p><ul><li>SWTBotGefEditor</li><li>SWTBotGefView</li><li>SWTBotGefViewer</li></ul><h4>Usual scenario for GEF bot test:</h4><ul><li>Locate GEF editor</li><li>Access some element</li><li>Check state</li><li>Perform operation on it</li><li>Check if operation is done</li></ul><h4>Example of basic GEF usage</h4><p><code> SWTGefBot gefBot = new SWTGefBot();<br/>SWTBotGefEditor editor = gefBot.gefEditor("simple");<br/>SWTBotMultiPageEditor multi = new SWTBotMultiPageEditor(editor.getReference(), gefBot);<br/>multi.activatePage("Diagram");<br/>editor.getEditPart("start").select();<br/></code></p><h4>SWTBotExt Limitations</h4><p>There are several known issues related to GEF SWTBot:</p><ul><li>some elements can't be found via SWTGefBot</li><li>context menu item is not always triggered successfully</li><li>different platform issues</li><li>timing and synchronization</li><li>missing API for particular operations</li><li>unreachable elements attributes from the bot</li></ul><h4>SWTBotExt GEF</h4><p>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:</p><ul><li>SWTBotGefEditorExt - uses SWTBotGefEditor and provides &#160;&#160;&#160;&#160;&#160;additional routines for figures manipulation</li><li>SWTBotGefViewerExt - provides methods for finding root figure </li><li>SWTBotGefFigure - provides access to GEF figure and it's &#160;&#160;&#160;&#160;&#160;attributes</li><li>SWTBotGefFinder - can finds particular elements like editor &#160;&#160;&#160;&#160;&#160;canvas, etc.</li><li>SWTBotGefMouse - general mouse controller for GEF Canvas. Can &#160;&#160;&#160;&#160;&#160;be used in your GEF api or outside as well</li><li>SWTGefContextMenuExt - context menu controller resolving bot &#160;&#160;&#160;&#160;&#160;GEF context menu issues</li><li>SWTArranger - provides facility for arranging figures on &#160;&#160;&#160;&#160;&#160;canvas like resolving empty area, etc.</li></ul><h4>Example changing label on a figure</h4><p><code> SWTBotGefEditorExt editor = new SWTBotGefEditorExt("simple");<br/>SWTBotGefFigure label = editor.labelFigure("text");<br/>editor.setLabelText(label, "new_text");<br/>editor.save();<br/></code></p><h4>Zest components</h4><p><a class="jive-link-external-small" href="http://www.eclipse.org/gef/zest/">GEF Zest</a> 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</p><ul><li>SWTBotZestBot</li><li>SWTBotZestGraph</li><li>SWTBotZestContextMenu</li><li>SWTBotZestNode</li><li>SWTBotZestConnection</li></ul><h4>Basic example of Zest Bot usage</h4><p><code> SWTZestBot zestBot = new SWTZestBot();<br/>SWTBotZestGraph graph = zestBot.getZestGraph(0);<br/>SWTBotZestNode node = graph.node("Input Task");<br/>node.click();<br/>SWTBotZestContextMenu menu = node.contextMenu();<br/>menu.clickMenu("Add Task","Java Mapping");<br/>graph.node("Input Task").click();<br/>graph.connection(graph.node("Input Task"), graph.node("Java Mapping")).click();<br/></code></p><h4>General approach for resolving issues</h4><p>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:</p><ul><li>Get as deep as possible via SWTBot or SWTBotExt - to get at &#160;&#160;&#160;&#160;&#160;least an editor</li><li>Find root figure - to be able to access rest of the element &#160;&#160;&#160;&#160;&#160;figures</li><li>Find particular figures and get their boundaries</li><li>Perform needed operation (via SWTBotMouse for example)</li><li>if it's general problem, implement some API for further usage</li></ul><h4>Other notes</h4><p>Since there are quite often changes related to SWTBot GEF API not everything described here must be necessary best approach. So please watch <a class="jive-link-external-small" href="http://www.eclipse.org/swtbot/downloads.php">SWTBot for latest updates</a> or use an approach which fits you best.</p><h4>Related links</h4><ul><li><a class="jive-link-external-small" href="http://www.eclipse.org/swtbot/">SWTBot Main Page</a></li><li><a class="jive-link-external-small" href="http://download.eclipse.org/technology/swtbot/galileo/dev-build/apidocs/">SWTBot Javadoc</a></li><li><a class="jive-link-external-small" href="http://www.eclipse.org/gef/">Eclipse GEF</a></li><li><a class="jive-link-external-small" href="http://www.eclipse.org/gef/zest/">Eclipse Zest</a></li></ul><h4>Further tasks related to GEF Bot Ext</h4><ul><li>Refactor and clean API</li><li>More generic approach</li><li>Separate from main BotExt plugin</li><li>Contribute into SWTBot if possible</li></ul></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-16691">going to Community</a></p>

        <p style="margin: 0;">Create a new document in JBoss Tools at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2128">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>