SWTBot is a open source UI testing tool for SWT and Eclipse based applications. It requires bare minimum learning since it is Java based and integrates well with the JUnit framework.
An ideal unit testing tool for SWT and Eclipse based applications developers.
2. Agenda PART I – About SWTBot Introduction to SWTBot SWTBot Features Supported Widgets Test Executions PART II - Integrating SWTBot tests execution with continuous build system What more? Limitations
4. Introduction – What is SWTBot? Java based UI/functional testing tool for testing SWT and Eclipse based applications Set of API’s to access and manipulate widgets Cross platform Free and open source Still in Incubation Phase in Eclipse
5. Introduction – Why SWTBot? Why not QTP? Why not PDE Junit? Why not… Provides an intuitive way to access and test UI components in Eclipse UI Testing covers all layers of software Easy to learn if someone is already familiar with Java and JUnit Can integrate very well within the IDE and provides excellent support for integration with Ant
6. Introduction – Who is it for? Developers Unit tests Integration with build ensures quality builds QA Test automation Quality product
7. Setting up Eclipse environment SWTBot update site http://www.eclipse.org/swtbot/downloads.php Create a plugin project and setup dependencies org.eclipse.ui org.eclipse.core.runtime org.eclipse.swtbot.eclipse.finder org.eclipse.swtbot.junit4_x org.eclipse.swtbot.swt.finder org.junit4 org.hamcrest Or, create a SWTBot test plugin
8. How does it work? SWTBot = bot which acts on SWT components Entry point: org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot Helper classes for widgets To test: Instantiate bot SWTWorkbenchBotbot = new SWTWorkbenchBot(); Click on button SWTBotButton button = bot.button("Hello, World!“); button.click(); Congrats! You have just written your first SWTBOT test
9. SWTBot Features Finding controls based on visual cues Support for simulated mouse and keyboard input Querying widgets for state UI specific assertions like: assertEnabled(Widget) Investigating test failures
10. SWTBot Features – Finding Controls Controls can be found based on visual cues like: Text Label Group Tooltip Ids Combination of all or any of the above (Using matchers) Eg: Find textbox that has a label 'Username:‘ SWTBotText username = bot.textWithLabel("Username:"); Identify button using tooltip SWTBotToolbarButton save = bot.toolbarButtonWithTooltip("Save");
11. SWTBot Features – Using matchers Simple matchers withText(“Finish”) withLabel(“Username:”) withRegex(“Proceed to step * ”) widgetOfType(Button.class) withStyle(SWT.ARROW, “SWT.ARROW”) Combination of matchers allOf(matchers) anyOf(matchers) not(matchers)
12. Filtering controls using Matchers Match : widgets of type 'Label' with regular expression 'Welcome, <USERNAME>' Matcher matcher = allOf( widgetOfType(Label.class), withRegex("Welcome, .*") ); Get the label that matches the matcher SWTBotLabel label = new SWTBotLabel((Label) bot.widget(matcher));
13. SWTBot Features – Simulate input SWTBot provides API to simulate actions on widgets Eg: Click a button button.click(); Select a item in combobox comboBox.select(“Option 12"); Type in a textbox text.typeText(“This is a demo string"); Expand tree tree.expandNode("MyProject", "src", "com", "example", "MyClass.java");
14. SWTBot Features – Querying widgets Provides operations to query the state of widgets Some generic queries like: getText(), isEnabled(), isVisible() are available on all widgets Eg: Check state of a checkbox booleanchecked = checkbox.isChecked(); Check if a radio button is selected boolean selected = radio.isSelected();
15. SWTBot Features – Investigating test failures Stack trace in Junit view Capturing screen shot when test case fails @RunWith(SWTBotJunit4ClassRunner.class) publicclassMessageCreateTest{ ... … }
16. Supported Widgets Support for most SWT controls Support for most UI operations on SWT controls Support for Eclipse based contributions: Views Text Editors (autocompletion, typing, etc) View Toolbars and View Menus
17. SWT Test Execution By launching them from launch configuration (same as Junit execution) From command line, using shell script or ant
18. Demo A small SWTBot example illustrating the simplicity of SWTBot Your first SWTBot
19. PART II – Integrating SWTBot tests execution with continuous build system
20. Integration of test execution with continuous build Build plugins to be tested Build SWTBot test plugins Install plugins to be tested, test plugins and headless testing framework (http://www.eclipse.org/swtbot/downloads.php) into eclipse Start SWTBot test case execution Format the generated report and mail if required
21. Pre-requisite Each test plugin must contain test.xml Set appropriate properties Delegate execution of test to a library file Test plugins should always be ‘unpacked’
22. Under the covers… For each test plugin Invoke test.xml which will Set required properties like class name, plugin name, directory to use as temp workspace etc Invoke target ‘swtbot-test’ of library file located in ‘org.eclipse.swtbot.eclipse.junit4.headless’ plugin which will then launch and execute all test cases Invoke target ‘collect’ of library file located in ‘org.eclipse.swtbot.eclipse.junit4.headless’ plugin which will consolidate test case results in one file Format the generated results file (xml file) into desired format (usually html)
25. What more? Parse results file and fail build if any of the test fails – ensuring only quality builds go to QA Code Coverage – write more tests to test uncovered code
26. Limitations Less documentation available Some SWT widgets not supported yet! No support for other UI toolkits – GEF, Nebula etc
Notes de l'éditeur
QTP:Pre-work required – repositoryNot cross platform – runs only on windows – no linux supportEven though its one of the fastest tools in the market – its still slower than SWTBotLearning requiredBetter because multiple types of apps can be supportedSWTBot provides APIs that are simple to read and write.No-hassle tool for writing powerful tests
SWTBot provides APIs that are simple to read and write. These APIs hide away the complexities of SWT and Eclipse. This makes it suitable for use by everyone and not just developers.
If you scroll down the stack trace in the JUnit view, you’ll see the cause of the error.The@RunWith(SWTBotJunit4ClassRunner.class)annotation captures a screenshot in a screenshots directory in your project. Refresh your project to see the new folder.
List of Not Yet Supported SWT WidgetsButton Arrow,Browser,Canvas,Composite,CTabFolder,Link,ProgressBar,Sash,Scale, ScrolledComposite,Slider,Spinner,TabFolderNot Yet Supported UI ToolkitsGEFEclipse FormsNebulaeSWT & eRCPRAP (work in progress)Native Dialogs (MessageBox, FileDialog, ColorDialog etc.)Most of it is planned to be supported them ASAP
A demo mapping all the theory learnt so far into a practical example
It's generally accepted that writing tests as part of software development is a very good thing indeed. It's also generally accepted that automating the running of tests in an automated or nightly build is good engineering practice. Let's face it, if tests are not run automatically then there's a good chance they won't be run at all, and tests that are not run are next to useless.SWTBot provides an excellent framework to write and run unit tests for your plug-ins that can be run from within the Eclipse environment.Once you have taken the time and effort to write these valuable unit tests, how do you automate the running of these unit tests so that you can integrate them into your automated build?
A demo showing how execution on unit tests can be integrated with the regular build system
List of Not Yet Supported SWT WidgetsButton Arrow,Browser,Canvas,Composite,CTabFolder,Link,ProgressBar,Sash,Scale, ScrolledComposite,Slider,Spinner,TabFolderNot Yet Supported UI ToolkitsGEFEclipse FormsNebulaeSWT & eRCPRAP (work in progress)Native Dialogs (MessageBox, FileDialog, ColorDialog etc.)Most of it is planned to be supported them ASAP