You can download the dependencies from https://swtbot.svn.sourceforge.net/svnroot/swtbot/branches/java-1.5-api-spike/org.eclipse.swtbot.releng/externals/plugins/ for now (and put them in .releng/externals/plugins)

+

=== Creating A Project ===

−

A patched version of the eclipse test framework is available at https://swtbot.svn.sourceforge.net/svnroot/swtbot/branches/java-1.5-api-spike/org.eclipse.swtbot.releng/test-sandbox/eclipse-test-framework-3.3.zip (you'll need to put this into .releng/externals)

+

Create a new project by clicking on '''File>New>Project'''. On the '''New Project Dialog''', search for "plug-in", select '''New Plug-in Project''' and click '''Next'''. Create a new plugin project named '''org.eclipsecon.swtbot.example'''.

+

[[Image:Swtbot-create-project.gif]]

+

===Configuration===

* Add the following to your classpath:

* Add the following to your classpath:

−

org.eclipse.swtbot.finder

+

org.eclipse.swtbot.eclipse.core

+

org.eclipse.swtbot.eclipse.finder

+

org.eclipse.swtbot.junit4_x

+

org.hamcrest

org.apache.commons.collections

org.apache.commons.collections

+

org.junit4

org.apache.log4j

org.apache.log4j

−

* These are useful if you are using SWTBot to test Eclipse plugins

+

org.eclipse.ui

−

org.eclipse.swtbot.eclipse.finder

+

+

[[Image:Swtbot-setup-dependencies.gif]]

===Getting started with SWTBot===

===Getting started with SWTBot===

−

SWTBot requires that tests run on a non-UI thread. If you run tests on the UI thread, they will eventually block the UI at some point in time. More info on this behavior available in the [[SWTBot/FAQ|FAQ]].

+

SWTBot requires that tests run on a non-UI thread, so that '''PlatformUI.getWorkbench()''' will return you null and that traditional unit-test code won't work. If you run tests on the UI thread, they will eventually block the UI at some point in time. Take a look into the FAQ for [[SWTBot/FAQ#Why do tests run on a non-UI thread?|explanations]] and [[SWTBot/FAQ#How do I execute parts of tests that need UI thread?|workaround]].

−

===Getting started with SWTBot for SWT applications===

+

===Getting started with SWTBot for Eclipse Plugins===

−

Because SWTBot tests need to [[SWTBot/FAQ#Why_do_tests_run_on_a_non-UI_thread.3F|run in a non-UI thread]], it is essential that the application starts off in another thread. The example below uses a simple mechanism to start the tests in another thread. You could use any other mechanism to do this instead.

+

To use SWTBot along with your eclipse plugin application you have to add the below plugins to your dependencies. You can download the example from the swtbot download site http://download.eclipse.org/technology/swtbot/docs/eclipsecon2009/examples.zip.

+

+

Now you can start using SWTBot. Below you can find a sample SWTBot testcase:

<source lang="java">

<source lang="java">

−

import net.sf.swtbot.SWTBotTestCase;

+

package org.eclipsecon.swtbot.example;

−

import net.sf.swtbot.utils.SWTUtils;

+

−

import net.sf.swtbot.widgets.TimeoutException;

+

−

import org.eclipse.swt.widgets.Display;

+

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;

+

import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;

+

import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;

+

import org.junit.AfterClass;

+

import org.junit.BeforeClass;

+

import org.junit.Test;

+

import org.junit.runner.RunWith;

−

public class FooBarTest extends SWTBotTestCase {

+

@RunWith(SWTBotJunit4ClassRunner.class)

+

public class MyFirstTest {

−

// pull this up into your own superclass that extends SWTBotTestCase and extend from your superclass instead

+

private static SWTWorkbenchBot bot;

−

static {

+

−

startApplicationInAnotherThread();

+

−

}

+

−

protected void setUp() throws Exception {

+

@BeforeClass

−

super.setUp();

+

public static void beforeClass() throws Exception {

−

waitForDisplayToAppear(5000); // wait for the display to appear before you do anything

SWT has a plugin that allows to manipulate GEF/GMF diagrams, editors and editParts as easily as you can manipulate SWT widgets with SWTBot. Then you can easily create some repeatable user-level UI interations and check their effects on the diagram

The configuration is similar to the one describe before for SWTBot, except that you also have to add '''org.eclipse.swtbot.eclipse.gef.finder''' plugin and some other dependencies, such as '''org.eclipse.ui'''. In most case, you'll also like to use GEF and/or GMF plugins to make some checks on diagram.

−

//The view is identified using the title of the view.

+

−

bot.view("Problems").setFocus();

+

−

//The sleep command can be used to slow down the testcase

+

== Getting started with examples ==

−

//execution so that you can see it or you can wait for a

+

−

//background process to complete.

+

−

bot.sleep(2000);

+

−

}

+

−

}

+

−

</source>

+

−

You can find one more SWTBot Testcase snippet below,

+

If you like to get started with working examples, you can take a look at the following URL, or [[SWTBot/Contributing#Getting the source | check them out]] in your workspace.

Everything is almost the same as using SWTBot, except that some classes change in order to give you the ability to manipulate DiagramEditors. The SWTBotTestCase superclass must be replaced by '''SWTBotGefTestCase'''. From the inside of your SWTBotTestCase, you can access your '''SWTGefBot''' ''bot'' field to play with your GEF editor. Then you retrieve a '''SWTBotGefEditor''' by using ''bot.getEditor("label of my editor tab")''.

+

+

Once you have your SWTBotGefEditor, you can perform high level user operations programatically:

+

+

=== Creation of elements ===

<source lang="java">

<source lang="java">

−

// subclassing SWTBotTestCase gives you an instance of

+

// retrieve editor

−

// SWTBot that offers a lot of convinience api

+

SWTBotGefEditor editor = bot.gefEditor("test.logic"); // editor must be already open

−

// this class also has a lot of assertions that are suited for ui operations

+

// Simulate creation of element from palette

−

public class FooTest extends SWTBotEclipseTestCase {

+

editor.activateTool("Circuit"); // "Circuit" is the label of the tool in palette

SWTBot Users Guide

Introduction

SWTBot is an open-source Java based functional testing tool for testing SWT and Eclipse based applications.

SWTBot provides APIs that are simple to read and write. The APIs also hide the complexities involved with SWT and Eclipse. This makes it suitable for functional testing by everyone. SWTBot also provides its own set of assertions that are useful for SWT. You can also use your own assertion framework with SWTBot.

SWTBot can record and playback tests and integrates with Eclipse, and also provides for ant tasks so that you can run your builds from within CruiseControl or any other CI tool that you use.

SWTBot can run on all platforms that SWT runs on. Very few other testing tools provide such a wide variety of platforms.

Quick Start

A Screencast

Creating A Project

Create a new project by clicking on File>New>Project. On the New Project Dialog, search for "plug-in", select New Plug-in Project and click Next. Create a new plugin project named org.eclipsecon.swtbot.example.

Getting started with SWTBot

SWTBot requires that tests run on a non-UI thread, so that PlatformUI.getWorkbench() will return you null and that traditional unit-test code won't work. If you run tests on the UI thread, they will eventually block the UI at some point in time. Take a look into the FAQ for explanations and workaround.

Executing SWTBot Tests for Eclipse Plugins

Now that you've written the great test that you'd always wanted to, lets now see it run. In order to run the test, right click on the test and select Run As > SWTBot Test

Select the application that you want to test

Test a GEF application

Intro

SWT has a plugin that allows to manipulate GEF/GMF diagrams, editors and editParts as easily as you can manipulate SWT widgets with SWTBot. Then you can easily create some repeatable user-level UI interations and check their effects on the diagram

Configuration

The configuration is similar to the one describe before for SWTBot, except that you also have to add org.eclipse.swtbot.eclipse.gef.finder plugin and some other dependencies, such as org.eclipse.ui. In most case, you'll also like to use GEF and/or GMF plugins to make some checks on diagram.

Getting started with examples

If you like to get started with working examples, you can take a look at the following URL, or check them out in your workspace.

General principles

Everything is almost the same as using SWTBot, except that some classes change in order to give you the ability to manipulate DiagramEditors. The SWTBotTestCase superclass must be replaced by SWTBotGefTestCase. From the inside of your SWTBotTestCase, you can access your SWTGefBotbot field to play with your GEF editor. Then you retrieve a SWTBotGefEditor by using bot.getEditor("label of my editor tab").

Once you have your SWTBotGefEditor, you can perform high level user operations programatically: