Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » [ANN] Summary of changes in SWTBot 2.0
[ANN] Summary of changes in SWTBot 2.0 [message #2897] Tue, 14 October 2008 21:18
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member

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.

In the meantime for those of you who'd want to get their hands dirty.
I'll be publishing a nightly here:

The regular nightlies continue to be available at:

-- 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"
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,
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),
Previous Topic:The easiest tool to test RCP apps
Next Topic:[IMP] Switching license from Apache License 2.0 to EPL.
Goto Forum:

Current Time: Mon May 27 07:49:33 GMT 2024

Powered by FUDForum. Page generated in 0.03892 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top