Skip to main content
Jump to: navigation, search

Difference between revisions of "Linux Tools Project/SWTBot Workarounds"

(Creating first version of this page)
Line 115: Line 115:
Button b = (Button) bot.widget(matcher, currSelection);
Button b = (Button) bot.widget(matcher, currSelection);

Revision as of 11:18, 13 March 2014


Linux Tools
Mailing ListForumsIRCmattermost
OpenHelp WantedBug Day
Browse Source

When creating SWTBot Tests for Linux Tools projects, developers may experience unusual or unexpected test failures. Listed on this page are some common SWTBot issues known to affect Linux Tools SWTBot tests, and workarounds for them until they are directly fixed by SWTBot.

Support for SWTBot itself is available here.

Tree Item Expansion Failure


Sometimes expanding a SWTBotTree (or SWTBotTreeItem) with the expandNode method will have no effect, causing tests that rely on (initially hidden) tree nodes to fail or throw errors. Note that this problem can happen in tests even if previous runs have succeeded and no changes to the code have been made since.

This problem is not due to concurrency or race conditions, so sleeping or using a wait condition to wait for a node to appear will not work. It is also unlikely to happen during local test runs, making it difficult to debug.


  • Tests that haven't been modified & were successful in previous builds are failing or throwing errors in later builds, with messages like "assertation failed:" or "could not find node with text: <name>"
  • The failed tests succeed when run locally, or when the offending build is retriggered or rebased, but fail again sometime later


If the Shell containing the desired parent tree supports a text search, you should use that to search for the nodes you want to reveal & select rather than expanding nodes directly.

For instance, if you want to create use SWTBot to create a C Project with the "New Project" wizard, you should get SWTBot to type "C Project" in the wizard's search bar (, which will reliably expand the "C/C++" node and reveal its child "C Project" node.

As expanding nodes with this method happens asynchronously relative to SWTBot, you will need a wait condition to halt execution until the node is ready. Below is a DefaultCondition extension that performs this task.

private static class NodeAvailableAndSelect extends DefaultCondition {

	private SWTBotTree tree;
	private String parent;
	private String node;

	 * Wait for a tree node (with a known parent) to become visible, and select it
	 * when it does. Note that this wait condition should only be used after having
	 * made an attempt to reveal the node.
	 * @param tree The SWTBotTree that contains the node to select.
	 * @param parent The text of the parent node that contains the node to select.
	 * @param node The text of the node to select.
	NodeAvailableAndSelect(SWTBotTree tree, String parent, String node){
		this.tree = tree;
		this.node = node;
		this.parent = parent;

	public boolean test() {
		try {
			SWTBotTreeItem parentNode = tree.getTreeItem(parent);
			return true;
		} catch (WidgetNotFoundException e) {
			return false;

	public String getFailureMessage() {
		return "Timed out waiting for " + node; //$NON-NLS-1$

Below is a demonstration of how to use these methods to create a new general project with SWTBot.

public void testCreateProject() {
	// Open the "New Project" wizard, which features a tree & a text search bar"File").menu("New").menu("Project...").click();"New Project").setFocus();

	// Want to create a general project, so search for the "Project" node

	// Wait for the node to be revealed, knowing that its parent is the "General" node
	bot.waitUntil(new NodeAvailableAndSelect(bot.tree(), "General", "Project"));

	// Performing the wait condition selected the node, so we can now navigate through the wizard
	bot.button("Next >").click();
	bot.textWithLabel("Project name:").setText("My New Project");

Radio Button Selection Problems


SWTBot is unable to properly select a radio button if another button in its group is already selected. See for details.


  • Tests that click on a non-selected radio button behave as if it were never clicked
  • Tests that step through clicking each radio button in a group only succeed with tests on the button that was clicked first


In order to select a radio button, no other button in the group can be selected. If the index of a pre-selected button is known, you must first de-select it by calling this helper method:

 * Deselects a radio button.
 * Workaround for
 * @param currSelection The index of the radiobutton to deselect
private void deselectDefaultSelection(final int currSelection) {
	UIThreadRunnable.syncExec(new VoidResult() {
			public void run() {
				Matcher<Widget> matcher = allOf(widgetOfType(Button.class), withStyle(SWT.RADIO, "SWT.RADIO"));
				Button b = (Button) bot.widget(matcher, currSelection);

After calling this method, clicking on a radio button will work as expected. Make sure to call this method whenever you want to change the selected radio button.

Back to the top