Sunday, June 12, 2011

Using SWTBot as script while developing RCP app

SWTBot is a great tool for writing UI tests. However, you can also use it as script to automate your clicks while developing UI.

Use Case
Suppose we are developing a wizard and we are designing the UI on third page. Now each time we will have to launch our application and then invoke the wizard. Provide template info for first two pages to reach the page where we are actually working currently. While designing UI we do these steps a number of times.

You can use SWTBot to automate these clicks. The idea is simple. Write an SWTBot script for the clicks to be automated, invoke it using Startup extension.

How to do it?

1. Add SWTBot to Target Platform
i) Edit the target platform and add a new 'Software Site' location.
ii) Provide the URL  (see for relevant url for your Eclipse version).
iii) Select 'SWTBot Eclipse features'.

2) Add the SWTBot script using Startup extension
i) Create a dummy plug-in.
ii) Add the 'org.eclipse.ui.startup' extension and create the class that will get invoked by it
iii) Add your SWTBot script to this class created above.
iv) You will have to add the dependency to 'org.eclipse.swtbot.eclipse.finder' for the SWTBot to compile.
v) Include this plug-in and the SWTBot plug-ins from the target to your launch configuration.

How this works?

The 'startup' extension makes the SWTBot script run when your application is launched. Adding the SWTBot to launch configuration will ensure it will be able to run when launched.