Hi,
This is a summary of changes for 2.0. This list is by no means
complete, but covers most of the important changes that have happened
since 1.x. This is meant as a guide for people who want to move to 2.0
from the existing 1.x branch. Expect a few minor changes in 2.0 in the
next couple of weeks.
Feel free to shoot any questions and concerns that come to mind.
-- Ketan
==============================
## Summary of changes for 2.0:
==============================
SWTBot 2.0 is a major release of SWTBot. It features a completely re-
hauled core. Sub-components within SWTBot have now been decoupled.
==============
## Matcher API
==============
======================
### IMatcher interface
======================
The interface IMatcher, and all its subclasses no longer exist. It is
instead replaced by org.hamcrest.Matcher. Both the interfaces have
similar behavior, and the hamcrest matchers provide a much nicer API.
========================
### WidgetMatcherFactory
========================
The WidgetMatcherFactory provided factory methods to create matchers
that matched final widgets. Finding widgets using a new mechanism
involved subclassing and composition. The matchers have now been
reduced to a very few matchers that make composition easier. All these
matchers implement the org.hamcrest.Matcher interface.
The following matchers are available:
widgetOfType(class), withLabel(label), withMnemonic(mnemonicText),
withRegex(regex), withText(text), withStyle(styleBits),
withTooltip(toolTip), withId(key, value), inGroup(groupText)
This makes for very powerful combination:
Matcher buttonMatcher = allOf(instanceOf(Button.class),
withLabel(label))
Also this now helps to get away from the index based api. For e.g. if
you have two groups "personal details" and "address" with one edit
button each, you can do:
Matcher m = allOf(instanceOf(Button.class), withLabel("Edit"),
inGroup("Personal Details"))
This makes for easier wiring of matchers if you're inclined to write
one.
=======================================================
## Java 1.5, and the use of generics and static imports
=======================================================
This is one of the major improvements in SWTBot 2.0. You can now
statically import *all* matchers in Eclipse and make life easier. Also
the use of generics provides for added type safety which was not
available before. It is recommended that users add the following
classes as under "Preferences>Java>Editor>Content Assist>Favorites"
junit.framework.Assert,
net.sf.swtbot.eclipse.finder.matcher.WidgetMatcherFactory,
org.hamcrest.MatcherAssert, org.hamcrest.Matchers
====================
### UIThreadRunnable
====================
The new UIThreadRunnable now uses generics, so you can now pass in a
runnable bound to a specific type. This makes for better type safety,
and avoids having to type-cast. Also these interfaces have moved into
a new package (net.sf.swtbot.finder.results) instead of being inner
classes.
UIThreadRunnable.syncExec(new Result<MyClass>{
public MyClass run(){
// return an instance of MyClass
}
});
Of course there's always some convenience Runnables for the most
common types: BoolResult, IntResult, ObjectResult, ListResult, and a
few more.
=================
## Custom finders
=================
Using custom finders to find widgets is now much easier. This is the
code that you'd write earlier:
ControlFinder controlFinder = new ControlFinder();
ClassMatcher matcher = new ClassMatcher(Table.class);
List findControls = controlFinder.findControls(parentWidget,
matcher, true);
if (findControls.isEmpty())
throw new WidgetNotFoundException("Could not find any table
control in the active editor");
return new SWTBotTable((Table) findControls.get(0));
The new version is simply a one liner:
return new SWTBotTable((Table)
bot.widget(widgetOfType(Table.class), parentWidget));
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
SWTBot-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swtbot-users
http://swtbot.org/ - a functional testing tool for SWT/Eclipse