SWTBot is an open-source Java framework for testing SWT and Eclipse-based applications. It provides an easy API to automate UI testing similar to a click-robot by handling SWT complexity. SWTBot's API can be integrated into JUnit tests to develop and run test cases. It allows finding widgets using text, labels, groups, tooltips, or IDs, and performing common actions like clicking, typing, and selecting. SWTBot also takes screenshots on errors and supports different test execution modes like via launch configurations or from the command line.
2. Introduction SWTBot is an open-source Java based UI/functional testing tool for testing SWT and Eclipse based applications. SWTBot project is in Incubation Phase in Eclipse Latest version is 2.0.0.568 Similar to a click-robot, it solves SWT handling complexity by providing easy UI API SWTBot’s API can integrate in JUnit framework in order to develop and run test cases
3. Starting with example SWTWorkbenchBot bot = new SWTWorkbenchBot(); // click on a button with the given text SWTBotButton button = bot. button ( "Hello, World!" ); button. click (); // click on the File>New menu item SWTBotMenu file = bot. menu ( "File" ); SWTBotMenu new = file. menu ( "New" ); new. click ();
4. Finding widgets // find the textbox that has a label 'Username:‘ SWTBotText username = bot.textWithLabel("Username:"); // Easily identify buttons using the tooltip SWTBotToolbarButton save = bot.toolbarButtonWithTooltip("Save"); // find windows using the window title SWTBotShell shell = bot.shell("New Project Wizard"); You can find controls using: text label group tooltip ids combination of all or any of the above
5. Custom matchers import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory .*; // 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));
7. Querying widgets for state SWTBot provides a few operations to query the state of widgets. Some generic queries like: getText(), isEnabled(), isVisible() are available on all widgets Ex. boolean checked = checkbox. isChecked (); boolean selected = radio. isSelected ();
8. Screenshots SWTBot generates a screenshot when an error occurs. The screenshot will be saved and available within the test plugin’s directory
9. Test Execution SWTBot framework allows for tests to be executed in 2 ways: Manually, by launching them from launch configuration (similar with junit tests); 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)
10. What’s new in Eclipse Helios Updated to support Junit 4.8 instead 4.7 (included Categories). Bug Fixes: 300103 - SWTBotGefEditor.directEditType does not work 301260 - SWTBotGefEditor.mouseDrag(String,int,int) doesn't drag node, it reduces them 305430 - Create the parent screenshot dir when capturing the screenshot.