Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Swtbot

2,433 views

Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

Swtbot

  1. 1. SWTBot UI test automation framework Cristian Tepus – Software Engineer
  2. 2. Introduction <ul><li>SWTBot is an open-source Java based UI/functional testing tool for testing SWT and Eclipse based applications. </li></ul><ul><li>SWTBot project is in Incubation Phase in Eclipse </li></ul><ul><li>Latest version is 2.0.0.568 </li></ul><ul><li>Similar to a click-robot, it solves SWT handling complexity by providing easy UI API </li></ul><ul><li>SWTBot’s API can integrate in JUnit framework in order to develop and run test cases </li></ul>
  3. 3. Starting with example <ul><li>SWTWorkbenchBot bot = new SWTWorkbenchBot(); </li></ul><ul><li>// click on a button with the given text </li></ul><ul><li>SWTBotButton button = bot. button ( &quot;Hello, World!&quot; ); </li></ul><ul><li>button. click (); </li></ul><ul><li>// click on the File>New menu item </li></ul><ul><li>SWTBotMenu file = bot. menu ( &quot;File&quot; ); </li></ul><ul><li>SWTBotMenu new = file. menu ( &quot;New&quot; ); new. click (); </li></ul>
  4. 4. Finding widgets <ul><li>// find the textbox that has a label 'Username:‘ </li></ul><ul><li>SWTBotText username = bot.textWithLabel(&quot;Username:&quot;); </li></ul><ul><li>// Easily identify buttons using the tooltip </li></ul><ul><li>SWTBotToolbarButton save = bot.toolbarButtonWithTooltip(&quot;Save&quot;); </li></ul><ul><li>// find windows using the window title </li></ul><ul><li>SWTBotShell shell = bot.shell(&quot;New Project Wizard&quot;); </li></ul><ul><li>You can find controls using: </li></ul><ul><li>text </li></ul><ul><li>label </li></ul><ul><li>group </li></ul><ul><li>tooltip </li></ul><ul><li>ids </li></ul><ul><li>combination of all or any of the above </li></ul>
  5. 5. Custom matchers <ul><li>import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory .*; </li></ul><ul><li>// match : </li></ul><ul><li>// widgets of type 'Label' </li></ul><ul><li>// with regular expression 'Welcome, <USERNAME>' </li></ul><ul><li>Matcher matcher = allOf( </li></ul><ul><li>widgetOfType(Label. class ), </li></ul><ul><li>withRegex( &quot;Welcome, .*&quot; ) ); </li></ul><ul><li>// get the label that matches the matcher </li></ul><ul><li>SWTBotLabel label = new SWTBotLabel((Label) bot. widget (matcher)); </li></ul>
  6. 6. Perform actions on widgets <ul><li>button. click (); </li></ul><ul><li>radioButton. select (); </li></ul><ul><li>comboBox. select ( “Option 12&quot; ); </li></ul><ul><li>text. typeText ( “This is a demo string&quot; ); </li></ul><ul><li>tree. expandNode ( &quot;MyProject&quot; , &quot;src&quot; , &quot;com&quot; , &quot;example&quot; , &quot;MyClass.java&quot; ); </li></ul>
  7. 7. Querying widgets for state <ul><li>SWTBot provides a few operations to query the state of widgets. Some generic queries like: getText(), isEnabled(), isVisible() are available on all widgets </li></ul><ul><li>Ex. </li></ul><ul><li>boolean checked = checkbox. isChecked (); </li></ul><ul><li>boolean selected = radio. isSelected (); </li></ul>
  8. 8. Screenshots <ul><li>SWTBot generates a screenshot when an error occurs. The screenshot will be saved and available within the test plugin’s directory </li></ul>
  9. 9. Test Execution <ul><li>SWTBot framework allows for tests to be executed in 2 ways: </li></ul><ul><li>Manually, by launching them from launch configuration (similar with junit tests); </li></ul><ul><li>From command line, using shell script or ant. For this mode, headless execution framework is necessary (see http://wiki.eclipse.org/SWTBot/Ant for more details) </li></ul>
  10. 10. What’s new in Eclipse Helios <ul><li>Updated to support Junit 4.8 instead 4.7 (included Categories). </li></ul><ul><li>Bug Fixes: </li></ul><ul><ul><li>300103 - SWTBotGefEditor.directEditType does not work </li></ul></ul><ul><ul><li>301260 - SWTBotGefEditor.mouseDrag(String,int,int) doesn't drag node, it reduces them </li></ul></ul><ul><ul><li>305430 - Create the parent screenshot dir when capturing the screenshot. </li></ul></ul>
  11. 11. Useful links <ul><li>http://www.eclipse.org/swtbot/ </li></ul><ul><li>http://download.eclipse.org/technology/swtbot/helios/dev-build/apidocs/ </li></ul><ul><li>http://swtbot.org/user-guide/basics-of-swtbot.html </li></ul><ul><li>http://wiki.eclipse.org/SWTBot/Ant </li></ul><ul><li>http://github.com/ketan/swtbot </li></ul><ul><li>https://publications.theseus.fi/bitstream/handle/10024/7470/Mazurkiewicz_Milosz.pdf?sequence=2 </li></ul>

×