September 23, 2018, 04:56:38 AM

Author Topic: How to setup SWTBot test for Eclipse plugin testing?  (Read 8973 times)


  • Guest
How to setup SWTBot test for Eclipse plugin testing?
« on: November 23, 2013, 02:15:37 AM »
I am actually a beginner in this and quite not sure about the steps which I need to follow up for setting up the SWTBot test framework to start the Eclipse UI plugin testing. Have someone worked on it before?

Can you please provide me the instructions which I need to follow to setup the SWTBot in my Eclipse? I tried with several things but still not getting it to work as it just throws some random errors.

Offline infomaniac

  • Administrator
  • Full Member
  • *****
  • Thank You
  • -Given:
  • -Receive:
  • Posts: 173
  • Karma: +0/-0
    • View Profile
    • Poke This Member
Re: How to setup SWTBot test for Eclipse plugin testing?
« Reply #1 on: November 23, 2013, 02:52:18 AM »
SWTBot is an open-source java based UI Testing tool used for testing the SWT and Eclipse based applications. The main advantage of SWTBot is that it automates the entire test case scenario which we need to test and reduces the time in writing the test cases and the major disadvantage is that poor documentation which ends up being confused even to setup the SWTBot environment in our systems. The below mentioned steps should enable you to get the SWTBot testing framework up in no time..

There are basically two key points to follow to start with the SWTBot test cases,

-> Setting up SWTBot Environment
-> Generate test case code and run

Setting up SWTBot Environment:

First we need to make sure that our eclipse is installed with the SWTBot plugin, follow the below mentioned steps for the same,

STEP 1: Open the eclipse application -> Go to Help -> Install new software -> Add…

STEP 2: -> Paste this link in the Location and name it as something like SWTBotTestSetup

STEP 3: Select All the shown plugins from the list -> Select Next -> Next -> Accept the terms and select Finish.

STEP 4: Wait for the installation of the plugins to complete -> Do eclipse restart once it is done.

Now the eclipse is installed with the SWTBot plugin, you need to create a sample project to check if you are able to run the SWTBot Tests. Follow the steps mentioned below,

STEP 1: Create a new Eclipse plugin project from your Eclipse application.

STEP 2: Make sure that MANIFEST.MF file of the imported project contains the below dependencies if not add them in the Required-Bundle,

o   org.eclipse.swtbot.go
o   org.eclipse.swtbot.junit4_x
o   org.eclipse.swtbot.swt.finder

STEP 3: Create a new class called as TestBot and copy/paste the below code.

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 TestBot {
   private static SWTWorkbenchBot bot;
   public static void beforeClass() throws Exception {
      bot = new SWTWorkbenchBot();
   public void canCreateANewJavaProject() throws Exception {"File").menu("New").menu("Project...").click();
      SWTBotShell shell ="New Project");
      bot.tree().expandNode("Java").select("Java Project");
      bot.button("Next >").click();
      bot.textWithLabel("Project name:").setText("MyFirstProject");
      // FIXME: assert that the project is actually created, for later
   public static void sleep() {

STEP 4: Now right click on the code and select Run As -> SWTBot Test which will be the new option showing up after you have done the SWTBot plugin setup which was mentioned before. If you are not able to see the new SWTBot Test run as option then close the eclipse and try to reinstall the SWTBot plugin once again and try.


To generate the test code automatically from SWTBot you need to follow the steps mentioned below,

STEP 1: From Menu open Run -> Run Configurations -> Select the Eclipse Application from the left -> Move to Arguments tab.

STEP 2: -Dorg.eclipse.swtbot.generator.enable=true -> Paste this in the VM Arguments -> Apply -> Run

STEP 3: You should get the normal eclipse launch plus a new popup window SWTBot Test Recorder as the one shown below,

STEP 4: Select the Start Recording option from the window and do the operation which you want to proceed as the test case for example – Creating a new project. While you are doing the operation you can observe that the code gets automatically generated on SWTBot Test Recorder Window.

STEP 5: Once you are done with the operation which needs to be tested. Select Copy button from the SWT Test Recorder and paste the same code to the test class file and run it as SWTBot Test.

There you go now you are an expert in SWTBot Test framework :D

You can go through the below links to get more information on SWTBot Test Framework,
« Last Edit: November 23, 2013, 02:54:58 AM by infomaniac »

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 
Copyrights © InfoManiac

Related Posts Plugin for WordPress, Blogger...