Note that if the test tries to access a property from the returned widget, there may be an invalid thread-access error. For example, ctabs.get(0).getText()
will result in an Invalid thread access
SWT error.
To perform tests on widgets, the code has to be run in the UI thread. Either the Display.getDefault().syncExec()
or the equivalent Synchronizer
class can be used, but SWTBot has a general interface called StringResult
, which is like a Runnable
method that can return a String
value through syncExec()
on the bot.
In the last
testTimeZone()
method of theUITest
class, create a newStringResult
and pass it toUIThreadRunnable.syncExec()
.In the
run()
method, get the firstcTabItem
and return its text value.After the
Runnable
method has been run, assert that the value isAfrica
.The code looks like this:
String tabText = UIThreadRunnable.syncExec(new StringResult() { @Override public String run() { return ctabs.get(0).getText(); } }); assertEquals...