SlideShare a Scribd company logo
SWTBot Essentials
                    Chris Aniszczyk
                http://aniszczyk.org
             caniszczyk@gmail.com
Agenda
introduction
exercises
  setting up the environment
  SWTBot API
how does it work?
conclusion and Q&A
UI Testing


 It’s not easy, natural brittleness...
 manual vs. automated testing
 deciding what to test
UI Testing Challenges
Challenges
Identifying Controls
Challenges
Similar looking controls
Similar looking controls
Moving controls
Challenges
Sending “events” to controls
Challenges
Manage SWT Threading
Challenges
Tests to be non-blocking
Challenges
Run in a separate thread
Still manage synchronization between threads
Challenges
Internationalization (i18n) and Localization (L10n)
Challenges
Readability
Hands on exercises!
Learn by doing.
All exercises focus around...
 creating a java project “MyFirstProject”
 create a java class
 type in a program that prints “Hello, World”
 execute the program
 verify that the program printed “Hello, World”
Exercise 0: Setup
Test01.java
Objectives
Setup SWTBot
Run a test with the SWTBot launch configuration
Setting up the Environment
Use Eclipse 3.6
Install SWTBot via update site
  http://www.eclipse.org/swtbot/downloads.php
Create a plugin project
 “org.eclipse.swtbot.examples”
Setup Dependencies
org.eclipse.ui
org.eclipse.core.runtime
org.eclipse.swtbot.eclipse.finder
org.eclipse.swtbot.junit4_x
org.eclipse.swtbot.swt.finder
org.junit4
Create a new plugin project
Create a simple Test
   @RunWith(SWTBotJunit4ClassRunner.class)
   public class Test01 {

   	   @Test
   	   public void thisOneFails() throws Exception {
   	   	 fail("this test fails");
   	   }

   	   @Test
   	   public void thisOnePasses() throws Exception {
   	   	 pass();
   	   }
   }
Run the first test
SWTBot API Introduction
Finding widgets
SWTWorkbenchBot bot = new SWTWorkbenchBot();

SWTBot[Widget] widget = bot.[widget][With][Matcher(s)]();

SWTBotText text = bot.textWithLabel("Username:");



        Think of the bot as something that can
        do tasks for you (e.g., find widgets, click
        on them, etc.)
Finding obscure widgets
  Use matchers and WidgetMatcherFactory!

withLabel("Username:")       Matcher pushButtonToProceedToNextStep = allOf(
withMnemonic("Finish")            widgetOfType(Button.class),
withText("&Finish")               withStyle(SWT.PUSH),
inGroup("Billing Address")        withRegex("Proceed to step (.*) >")
widgetOfType(Button.class)     );
withStyle(SWT.RADIO)
withTooltip("Save All")      SWTBotButton button = new SWTBotButton(
withRegex("Welcome, (.*)")        (Button)
                             bot.widget(pushButtonToProceedToNextStep)
                               );
Performing actions
button.click() // click on a button

// chain methods to make them concise
bot.menu("File").menu("New").menu("Project...").click();

tree.expand("Project").expand("src").expand("Foo.java").contextMenu("Delete").clic
k(); // delete Foo.java

list.select("Orange", "Banana", "Mango"); // make a selection in a list
list.select(2, 5, 6); // make a selection using indexes
Exercise 1: Hello SWTBot
SWTBotTest01.java
Objectives
Get introduced to the SWTBot API
  SWTWorkbenchBot is your friend
Tasks
  beforeClass() - close the welcome view

  canCreateANewProject() - create a java project
  Run the test!
  Ensure SWTBot logging works
beforeClass()


	   @BeforeClass
	   public static void beforeClass() throws Exception {
	   	 bot = new SWTWorkbenchBot();
	   	 bot.viewByTitle("Welcome").close();
	   }
canCreateANewProject()

     @Test
 	   public void canCreateANewJavaProject() throws Exception {
 	   	    bot.menu("File").menu("New").menu("Project...").click();

 	   	   SWTBotShell shell = bot.shell("New Project");
 	   	   shell.activate();
 	   	   bot.tree().select("Java Project");
 	   	   bot.button("Next >").click();

 	   	   bot.textWithLabel("Project name:").setText("MyFirstProject");

 	   	   bot.button("Finish").click();
 	   }
Seeing log messages?
How does it work? Magic?
)"*#(+,,(
-"#$%&'(




 !"#$%&'(
Redundancy and Failure
Proofing
)"*#(+,,(
-"#$%&'(




 !"#$%&'(
Find all widgets

  Depth first traversal of UI elements


1.Find top level widgets
  1.Find children of each widget
2.For each child do (1) and (2)
Finding widgets

public SWTBotTree treeWithLabelInGroup(String l, String g, int i) {

       // create the matcher
       Matcher matcher =
              allOf(
                      widgetOfType(Tree.class), withLabel(l), inGroup(g)
              );
       // find the widget, with redundancy built in
       Tree tree = (Tree) widget(matcher, index);
       // create a wrapper for thread safety
       // and convinience APIs
       return new SWTBotTree(tree, matcher);
}
Thread Safety


Tests should run in non-ui thread
query state of a widget
change state of a widget
Thread Safety (Query state)

    public class SWTBotCheckBox {
	   public boolean isChecked() {
	   	 // evaluate a result on the UI thread
	   	 return syncExec(new BoolResult() {
	   	 	 public Boolean run() {
	   	 	 	 return widget.getSelection();
	   	 	 }
	   	 });
	   }
}
Thread Safety(change state)

public class SWTBotCheckBox {
	   public void select() {
	   	   asyncExec(new VoidResult() {
	   	   	   public void run() {
	   	   	   	   widget.setSelection(true);
	   	   	   }
	   	   });
	   	   notifyListeners();
	   }
	
	   protected void notifyListeners() {
	   	   notify(SWT.MouseDown);
	   	   notify(SWT.MouseUp);
	   	   notify(SWT.Selection);
	   }
}
Exercise 2: More SWTBot
SWTBotTest02.java
Objectives
Tasks
  canCreateANewJavaClass()
    create a new java class: HelloWorld
    Source folder: MyFirstProject/src
    Package: org.eclipsecon.project
    Click Finish!
  Run the test!
canCreateANewJavaClass()

	   @Test
	   public void canCreateANewJavaClass() throws Exception {
	   	   bot.toolbarDropDownButtonWithTooltip("New Java Class").menuItem("Class").click();

	   	   bot.shell("New Java Class").activate();
	   	   bot.textWithLabel("Source folder:").setText("MyFirstProject/src");

	   	   bot.textWithLabel("Package:").setText("org.eclipsecon.project");
	   	   bot.textWithLabel("Name:").setText("HelloWorld");

	   	   bot.button("Finish").click();

	   }
Exercise 3: SWTBotEditor
SWTBotTest03.java
Objectives
Tasks
  canTypeInTextInAJavaClass()
    open a file: HelloWorld.java
    set some text in the Java file
  canExecuteJavaApplication()

    Run the Java application
  Run the test!
canTypeInTextInAJavaClass()
     @Test
 	   public void canTypeInTextInAJavaClass() throws Exception {
 	   	    Bundle bundle = Activator.getContext().getBundle();
 	   	    String contents =
              FileUtils.read(bundle.getEntry("test-files/HelloWorld.java"));
 	   	    SWTBotEditor editor = bot.editorByTitle("HelloWorld.java");
 	   	    SWTBotEclipseEditor e = editor.toTextEditor();
 	   	    e.setText(contents);
 	   	    editor.save();
 	   }
canExecuteJavaApplication()

    	   @Test
    	   public void canExecuteJavaApplication() throws Exception {
    	   	 bot.menu("Run").menu("Run").click();
    	   	
    	   	 // FIXME: verify that the program printed 'Hello World'
    	   }
SWTBotEditor
Exercise 4: Matchers
SWTBotTest04.java
Objectives
Learn about SWTBot and the Matcher API
Tasks
  canExecuteJavaApplication()
    Run the Java application
    Grab the Console view
    Verify that “Hello World” is printed
  Run the tests!
canExecuteJavaApplication()
	   @Test
	   public void canExecuteJavaApplication() throws Exception {
	   	 bot.menu("Run").menu("Run").click();
	   	 SWTBotView view = bot.viewByTitle("Console");
	   	 Widget consoleViewComposite = view.getWidget();

	 	 StyledText console =
bot.widget(WidgetMatcherFactory.widgetOfType(StyledText.class),
consoleViewComposite);
	 	 SWTBotStyledText styledText = new SWTBotStyledText(console);

	   	   assertTextContains("Hello World", styledText);
	   }
Matchers
Under the covers, SWTBot uses Hamcrest
Hamcrest is a framework for writing ‘match’ rules
SWTBot is essentially all about match rules
bot.widget(WidgetMatcherFactory.widgetO
fType(StyledText.class),
consoleViewComposite);
WidgetMatcherFactory
Creating matchers

WidgetMatcherFactory is your friend!
withText("Finish")
withLabel("Username:")
withRegex("Proceed to step (.*)")
widgetOfType(Button.class)
withStyle(SWT.ARROW, "SWT.ARROW")
Combining matchers

allOf(matchers...)
anyOf(matchers...)
not(matcher)
allOf(anyOf(matchers...), matchers...)
Exercise 5: Waiting
SWTBotTest05.java
Objectives
Learn about waiting and SWTBot Condition API
Tasks
  afterClass()
    Select the Package Explorer view
    Select MyFirstProject
    Right click and delete the project
  Run the test!
afterClass()
	   @AfterClass
	   public static void afterClass() throws Exception {
	   	    SWTBotView packageExplorerView = bot.viewByTitle("Package Explorer");
	   	    packageExplorerView.show();
	   	    Composite packageExplorerComposite = (Composite) packageExplorerView.getWidget();

	   	    Tree swtTree =
             (Tree) bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), packageExplorerComposite);
	   	    SWTBotTree tree = new SWTBotTree(swtTree);

	   	    tree.select("MyFirstProject");

	   	    bot.menu("Edit").menu("Delete").click();

	   	    // the project deletion confirmation dialog
	   	    SWTBotShell shell = bot.shell("Delete Resources");
	   	    shell.activate();
	   	    bot.checkBox("Delete project contents on disk (cannot be undone)").select();
	   	    bot.button("OK").click();
	   	    bot.waitUntil(shellCloses(shell));
	   }
Handling long operations

describe a condition
poll for the condition at intervals
wait for it to evaluate to true or false
of course there’s a timeout
SWTBot has an ICondition
ICondition
Handling Waits

private void waitUntil(ICondition condition, long timeout, long interval) {

	   long limit = System.currentTimeMillis() + timeout;
	   condition.init((SWTBot) this);
	   while (true) {
	   	   try {
	   	   	   if (condition.test())
	   	   	   	   return;
	   	   } catch (Throwable e) {
	   	   	   // do nothing
	   	   }
	   	   sleep(interval);
	   	   if (System.currentTimeMillis() > limit)
	   	   	   throw new TimeoutException("Timeout after: " + timeout);
	   }
}
Conditions is your friend
Building Abstractions
Abstractions are good!
 They simplify writing tests for QA folks
 Build page objects for common “services”
   Project Explorer
   The Editor
   The Console View
   The main menu bar, tool bar
Model Capabilities

 Create a project
 Delete a project
 Create a class
 Execute a class
 more...
Domain Objects
Domain Objects?



Represent the operations that can be performed on
concepts
Sample Domain Object

public class JavaProject {
	 public JavaProject create(String projectName){
	 	 // create a project and return it
	 }
	 public JavaProject delete(){
	 	 // delete the project and return it
	 }
	 public JavaClass createClass(String className){
	 	 // create a class and return it
	 }
}
Page Objects
http://code.google.com/p/webdriver/wiki/PageObjects
Page Objects?
Represent the services offered by the page to the test
developer
Internally knows the details about how these services
are offered and the details of UI elements that offer
them
Return other page objects to model the user’s journey
through the application
Different results of the same operation modeled
Page Objects... should not


 Expose details about user interface elements
 Make assertions about the state of the UI
A Sample Page Object

    public class LoginPage {

	   public HomePage loginAs(String user, String pass) {
	   	   // ... clever magic happens here
	   }

	   public LoginPage loginAsExpectingError(String user, String pass) {
	   	   // ... failed login here, maybe because one or both of
	   	   // username and password are wrong
	   }

	   public String getErrorMessage() {
	   	   // So we can verify that the correct error is shown
	   }
}
Using Page Objects

// the bad test
public void testMessagesAreReadOrUnread() {
    Inbox inbox = new Inbox(driver);
    inbox.assertMessageWithSubjectIsUnread("I like cheese");
    inbox.assertMessageWithSubjectIsNotUndread("I'm not fond of tofu");
}

// the good test
public void testMessagesAreReadOrUnread() {
    Inbox inbox = new Inbox(driver);
    assertTrue(inbox.isMessageWithSubjectIsUnread("I like cheese"));
    assertFalse(inbox.isMessageWithSubjectIsUnread("I'm not fond of tofu"));
}
LoginPage login = new LoginPage();
HomePage home = login.loginAs("username", "secret");
SearchPage search = home.searchFor("swtbot");
assertTrue(search.containsResult("http://eclipse.org/swtbot"));
Exercise 6: Abstractions
SWTBotTest06.java
Objectives
Learn about page and domain objects
Tasks
  Create a NewProjectBot
    Opens the new project wizard
    Allows you to set the project name and click finish
  Modify canCreateANewJavaProject()

  Run the test!
NewProjectBot
public class NewProjectBot {

    private static SWTWorkbenchBot      bot;

    public NewProjectBot() {
        bot.menu("File").menu("New").menu("Project...").click();
        bot.shell("New Project").activate();
        bot.tree().select("Java Project");
        bot.button("Next >").click();
    }

    public void setProjectName(String projectName) {
        bot.textWithLabel("Project name:").setText(projectName);
    }

    public void finish() {
        bot.button("Finish").click();
    }
}
Modify Project Wizard Code
 @Test
 public void canCreateANewJavaProject() throws Exception {
    // use the NewProjectBot abstraction
      NewProjectBot newProjectBot = new NewProjectBot();
      newProjectBot.setProjectName("MyFirstProject");
      newProjectBot.finish();

     assertProjectCreated();
 }
Best Practices & Tips
Logging
Turn logging on always, it helps :)
http://wiki.eclipse.org/SWTBot/
FAQ#How_do_I_configure_log4j_to_turn_on
_logging_for_SWTBot.3F
Slow down executions
  Useful for debugging at times...
  SWTBotPreferences.PLAYBACK_DELAY
  -Dorg.eclipse.swtbot.playback.delay=20
  or via code...

long oldDelay = SWTBotPreferences.PLAYBACK_DELAY;
// increase the delay
SWTBotPreferences.PLAYBACK_DELAY = 10;

// do whatever

// set to the original timeout of 5 seconds
SWTBotPreferences.PLAYBACK_DELAY = oldDelay;
Changing Timeout
  SWTBotPreferences.TIMEOUT
  -Dorg.eclipse.swtbot.search.timeout=10000
  or via code...
long oldTimeout = SWTBotPreferences.TIMEOUT;
// increase the timeout
SWTBotPreferences.TIMEOUT = 10000;

// do whatever

// set to the original timeout of 5 seconds
SWTBotPreferences.TIMEOUT = oldTimeout;
Identifiers
 In our examples, we used labels as matchers mostly
 SWTBot allows you to use IDs as matchers
 IDs are less brittle than labels!
 text.setData(SWTBotPreferences.DEFAULT_
 KEY,”id”)
 bot.textWithId(“id”)
Page Objects
Use Page Objects to simplify writing tests
Allows more people than just normal devs to write tests
More SWTBot?


Eclipse Forms support in HEAD
GEF support is available for graphical editor testing
Questions ?
newsgroup: news://news.eclipse.org/eclipse.swtbot
web: eclipse.org/swtbot

More Related Content

What's hot

Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
José Paumard
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Designveloper
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Thomas Zimmermann
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
ICS
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Nascenia IT
 
spring-boot-fr.pdf
spring-boot-fr.pdfspring-boot-fr.pdf
spring-boot-fr.pdf
seydou4devops
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
Fabien Vauchelles
 
C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기Heo Seungwook
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
Roman Elizarov
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Pei-Tang Huang
 
Exception handling
Exception handlingException handling
Exception handling
Anna Pietras
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
Vincent Kok
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
Theo Jungeblut
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
NexThoughts Technologies
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentationJohn Slick
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
Hiranya Jayathilaka
 

What's hot (20)

Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
spring-boot-fr.pdf
spring-boot-fr.pdfspring-boot-fr.pdf
spring-boot-fr.pdf
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Exception handling
Exception handlingException handling
Exception handling
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Mockito
MockitoMockito
Mockito
 
Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 

Viewers also liked

Functional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersFunctional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and Testers
Aurélien Pupier
 
Java UI Unit Testing with jemmy
Java UI Unit Testing with jemmyJava UI Unit Testing with jemmy
Java UI Unit Testing with jemmyWarin Laocharoen
 
The Open Container Initiative (OCI) at 12 months
The Open Container Initiative (OCI) at 12 monthsThe Open Container Initiative (OCI) at 12 months
The Open Container Initiative (OCI) at 12 months
Chris Aniszczyk
 
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
Mickael Istria
 
Jemmy Introduction
Jemmy IntroductionJemmy Introduction
Jemmy Introduction
Pawel Prokop
 

Viewers also liked (6)

Functional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersFunctional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and Testers
 
Java UI Unit Testing with jemmy
Java UI Unit Testing with jemmyJava UI Unit Testing with jemmy
Java UI Unit Testing with jemmy
 
The Open Container Initiative (OCI) at 12 months
The Open Container Initiative (OCI) at 12 monthsThe Open Container Initiative (OCI) at 12 months
The Open Container Initiative (OCI) at 12 months
 
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
 
WindowTester PRO
WindowTester PROWindowTester PRO
WindowTester PRO
 
Jemmy Introduction
Jemmy IntroductionJemmy Introduction
Jemmy Introduction
 

Similar to SWTBot Tutorial

Android testing
Android testingAndroid testing
Android testing
Sean Tsai
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
IT Event
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
OXUS 20
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
Thierry Wasylczenko
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
Alexis Hassler
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
Tuto jtatoo
Tuto jtatooTuto jtatoo
6 swt programming
6 swt programming6 swt programming
6 swt programming
Prakash Sweet
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
kavinilavuG
 
Teste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityTeste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrity
Washington Botelho
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
IMC Institute
 
Vaadin 8 によるオール java web アプリ開発の仕組みと実践
Vaadin 8 によるオール java web アプリ開発の仕組みと実践Vaadin 8 によるオール java web アプリ開発の仕組みと実践
Vaadin 8 によるオール java web アプリ開発の仕組みと実践
Yutaka Kato
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
Eric Wendelin
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With Griffon
Matthew McCullough
 
Geb qa fest2017
Geb qa fest2017Geb qa fest2017
Geb qa fest2017
Sviatkin Yaroslav
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
Dave Artz
 

Similar to SWTBot Tutorial (20)

Swtbot
SwtbotSwtbot
Swtbot
 
Android testing
Android testingAndroid testing
Android testing
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Tuto jtatoo
Tuto jtatooTuto jtatoo
Tuto jtatoo
 
6 swt programming
6 swt programming6 swt programming
6 swt programming
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
Teste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityTeste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrity
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Vaadin 8 によるオール java web アプリ開発の仕組みと実践
Vaadin 8 によるオール java web アプリ開発の仕組みと実践Vaadin 8 によるオール java web アプリ開発の仕組みと実践
Vaadin 8 によるオール java web アプリ開発の仕組みと実践
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With Griffon
 
Geb qa fest2017
Geb qa fest2017Geb qa fest2017
Geb qa fest2017
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 

More from Chris Aniszczyk

Bringing an open source project to the Linux Foundation
Bringing an open source project to the Linux FoundationBringing an open source project to the Linux Foundation
Bringing an open source project to the Linux Foundation
Chris Aniszczyk
 
Starting an Open Source Program Office (OSPO)
Starting an Open Source Program Office (OSPO)Starting an Open Source Program Office (OSPO)
Starting an Open Source Program Office (OSPO)
Chris Aniszczyk
 
Open Container Initiative Update
Open Container Initiative UpdateOpen Container Initiative Update
Open Container Initiative Update
Chris Aniszczyk
 
Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)
Chris Aniszczyk
 
Rise of Open Source Programs
Rise of Open Source ProgramsRise of Open Source Programs
Rise of Open Source Programs
Chris Aniszczyk
 
Open Source Lessons from the TODO Group
Open Source Lessons from the TODO GroupOpen Source Lessons from the TODO Group
Open Source Lessons from the TODO Group
Chris Aniszczyk
 
Getting Students Involved in Open Source
Getting Students Involved in Open SourceGetting Students Involved in Open Source
Getting Students Involved in Open Source
Chris Aniszczyk
 
Life at Twitter + Career Advice for Students
Life at Twitter + Career Advice for StudentsLife at Twitter + Career Advice for Students
Life at Twitter + Career Advice for Students
Chris Aniszczyk
 
Creating an Open Source Office: Lessons from Twitter
Creating an Open Source Office: Lessons from TwitterCreating an Open Source Office: Lessons from Twitter
Creating an Open Source Office: Lessons from Twitter
Chris Aniszczyk
 
The Open Source... Behind the Tweets
The Open Source... Behind the TweetsThe Open Source... Behind the Tweets
The Open Source... Behind the TweetsChris Aniszczyk
 
Apache Mesos at Twitter (Texas LinuxFest 2014)
Apache Mesos at Twitter (Texas LinuxFest 2014)Apache Mesos at Twitter (Texas LinuxFest 2014)
Apache Mesos at Twitter (Texas LinuxFest 2014)
Chris Aniszczyk
 
Evolution of The Twitter Stack
Evolution of The Twitter StackEvolution of The Twitter Stack
Evolution of The Twitter Stack
Chris Aniszczyk
 
Open Source Craft at Twitter
Open Source Craft at TwitterOpen Source Craft at Twitter
Open Source Craft at Twitter
Chris Aniszczyk
 
Open Source Compliance at Twitter
Open Source Compliance at TwitterOpen Source Compliance at Twitter
Open Source Compliance at TwitterChris Aniszczyk
 
Effective Development With Eclipse Mylyn, Git, Gerrit and Hudson
Effective Development With Eclipse Mylyn, Git, Gerrit and HudsonEffective Development With Eclipse Mylyn, Git, Gerrit and Hudson
Effective Development With Eclipse Mylyn, Git, Gerrit and Hudson
Chris Aniszczyk
 
Effective Git with Eclipse
Effective Git with EclipseEffective Git with Eclipse
Effective Git with Eclipse
Chris Aniszczyk
 
Evolution of Version Control In Open Source
Evolution of Version Control In Open SourceEvolution of Version Control In Open Source
Evolution of Version Control In Open Source
Chris Aniszczyk
 
ESE 2010: Using Git in Eclipse
ESE 2010: Using Git in EclipseESE 2010: Using Git in Eclipse
ESE 2010: Using Git in Eclipse
Chris Aniszczyk
 
Helios in Action: Git at Eclipse
Helios in Action: Git at EclipseHelios in Action: Git at Eclipse
Helios in Action: Git at Eclipse
Chris Aniszczyk
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
Chris Aniszczyk
 

More from Chris Aniszczyk (20)

Bringing an open source project to the Linux Foundation
Bringing an open source project to the Linux FoundationBringing an open source project to the Linux Foundation
Bringing an open source project to the Linux Foundation
 
Starting an Open Source Program Office (OSPO)
Starting an Open Source Program Office (OSPO)Starting an Open Source Program Office (OSPO)
Starting an Open Source Program Office (OSPO)
 
Open Container Initiative Update
Open Container Initiative UpdateOpen Container Initiative Update
Open Container Initiative Update
 
Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)
 
Rise of Open Source Programs
Rise of Open Source ProgramsRise of Open Source Programs
Rise of Open Source Programs
 
Open Source Lessons from the TODO Group
Open Source Lessons from the TODO GroupOpen Source Lessons from the TODO Group
Open Source Lessons from the TODO Group
 
Getting Students Involved in Open Source
Getting Students Involved in Open SourceGetting Students Involved in Open Source
Getting Students Involved in Open Source
 
Life at Twitter + Career Advice for Students
Life at Twitter + Career Advice for StudentsLife at Twitter + Career Advice for Students
Life at Twitter + Career Advice for Students
 
Creating an Open Source Office: Lessons from Twitter
Creating an Open Source Office: Lessons from TwitterCreating an Open Source Office: Lessons from Twitter
Creating an Open Source Office: Lessons from Twitter
 
The Open Source... Behind the Tweets
The Open Source... Behind the TweetsThe Open Source... Behind the Tweets
The Open Source... Behind the Tweets
 
Apache Mesos at Twitter (Texas LinuxFest 2014)
Apache Mesos at Twitter (Texas LinuxFest 2014)Apache Mesos at Twitter (Texas LinuxFest 2014)
Apache Mesos at Twitter (Texas LinuxFest 2014)
 
Evolution of The Twitter Stack
Evolution of The Twitter StackEvolution of The Twitter Stack
Evolution of The Twitter Stack
 
Open Source Craft at Twitter
Open Source Craft at TwitterOpen Source Craft at Twitter
Open Source Craft at Twitter
 
Open Source Compliance at Twitter
Open Source Compliance at TwitterOpen Source Compliance at Twitter
Open Source Compliance at Twitter
 
Effective Development With Eclipse Mylyn, Git, Gerrit and Hudson
Effective Development With Eclipse Mylyn, Git, Gerrit and HudsonEffective Development With Eclipse Mylyn, Git, Gerrit and Hudson
Effective Development With Eclipse Mylyn, Git, Gerrit and Hudson
 
Effective Git with Eclipse
Effective Git with EclipseEffective Git with Eclipse
Effective Git with Eclipse
 
Evolution of Version Control In Open Source
Evolution of Version Control In Open SourceEvolution of Version Control In Open Source
Evolution of Version Control In Open Source
 
ESE 2010: Using Git in Eclipse
ESE 2010: Using Git in EclipseESE 2010: Using Git in Eclipse
ESE 2010: Using Git in Eclipse
 
Helios in Action: Git at Eclipse
Helios in Action: Git at EclipseHelios in Action: Git at Eclipse
Helios in Action: Git at Eclipse
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
 

Recently uploaded

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 

Recently uploaded (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

SWTBot Tutorial

  • 1. SWTBot Essentials Chris Aniszczyk http://aniszczyk.org caniszczyk@gmail.com
  • 2. Agenda introduction exercises setting up the environment SWTBot API how does it work? conclusion and Q&A
  • 3. UI Testing It’s not easy, natural brittleness... manual vs. automated testing deciding what to test
  • 11. Challenges Tests to be non-blocking
  • 12. Challenges Run in a separate thread Still manage synchronization between threads
  • 16. All exercises focus around... creating a java project “MyFirstProject” create a java class type in a program that prints “Hello, World” execute the program verify that the program printed “Hello, World”
  • 18. Objectives Setup SWTBot Run a test with the SWTBot launch configuration
  • 19. Setting up the Environment Use Eclipse 3.6 Install SWTBot via update site http://www.eclipse.org/swtbot/downloads.php
  • 20.
  • 21. Create a plugin project “org.eclipse.swtbot.examples”
  • 23. Create a new plugin project
  • 24. Create a simple Test @RunWith(SWTBotJunit4ClassRunner.class) public class Test01 { @Test public void thisOneFails() throws Exception { fail("this test fails"); } @Test public void thisOnePasses() throws Exception { pass(); } }
  • 27. Finding widgets SWTWorkbenchBot bot = new SWTWorkbenchBot(); SWTBot[Widget] widget = bot.[widget][With][Matcher(s)](); SWTBotText text = bot.textWithLabel("Username:"); Think of the bot as something that can do tasks for you (e.g., find widgets, click on them, etc.)
  • 28. Finding obscure widgets Use matchers and WidgetMatcherFactory! withLabel("Username:") Matcher pushButtonToProceedToNextStep = allOf( withMnemonic("Finish") widgetOfType(Button.class), withText("&Finish") withStyle(SWT.PUSH), inGroup("Billing Address") withRegex("Proceed to step (.*) >") widgetOfType(Button.class) ); withStyle(SWT.RADIO) withTooltip("Save All") SWTBotButton button = new SWTBotButton( withRegex("Welcome, (.*)") (Button) bot.widget(pushButtonToProceedToNextStep) );
  • 29. Performing actions button.click() // click on a button // chain methods to make them concise bot.menu("File").menu("New").menu("Project...").click(); tree.expand("Project").expand("src").expand("Foo.java").contextMenu("Delete").clic k(); // delete Foo.java list.select("Orange", "Banana", "Mango"); // make a selection in a list list.select(2, 5, 6); // make a selection using indexes
  • 30. Exercise 1: Hello SWTBot SWTBotTest01.java
  • 31. Objectives Get introduced to the SWTBot API SWTWorkbenchBot is your friend Tasks beforeClass() - close the welcome view canCreateANewProject() - create a java project Run the test! Ensure SWTBot logging works
  • 32. beforeClass() @BeforeClass public static void beforeClass() throws Exception { bot = new SWTWorkbenchBot(); bot.viewByTitle("Welcome").close(); }
  • 33. canCreateANewProject() @Test public void canCreateANewJavaProject() throws Exception { bot.menu("File").menu("New").menu("Project...").click(); SWTBotShell shell = bot.shell("New Project"); shell.activate(); bot.tree().select("Java Project"); bot.button("Next >").click(); bot.textWithLabel("Project name:").setText("MyFirstProject"); bot.button("Finish").click(); }
  • 35. How does it work? Magic?
  • 39. Find all widgets Depth first traversal of UI elements 1.Find top level widgets 1.Find children of each widget 2.For each child do (1) and (2)
  • 40. Finding widgets public SWTBotTree treeWithLabelInGroup(String l, String g, int i) { // create the matcher Matcher matcher = allOf( widgetOfType(Tree.class), withLabel(l), inGroup(g) ); // find the widget, with redundancy built in Tree tree = (Tree) widget(matcher, index); // create a wrapper for thread safety // and convinience APIs return new SWTBotTree(tree, matcher); }
  • 41. Thread Safety Tests should run in non-ui thread query state of a widget change state of a widget
  • 42. Thread Safety (Query state) public class SWTBotCheckBox { public boolean isChecked() { // evaluate a result on the UI thread return syncExec(new BoolResult() { public Boolean run() { return widget.getSelection(); } }); } }
  • 43. Thread Safety(change state) public class SWTBotCheckBox { public void select() { asyncExec(new VoidResult() { public void run() { widget.setSelection(true); } }); notifyListeners(); } protected void notifyListeners() { notify(SWT.MouseDown); notify(SWT.MouseUp); notify(SWT.Selection); } }
  • 44. Exercise 2: More SWTBot SWTBotTest02.java
  • 45. Objectives Tasks canCreateANewJavaClass() create a new java class: HelloWorld Source folder: MyFirstProject/src Package: org.eclipsecon.project Click Finish! Run the test!
  • 46. canCreateANewJavaClass() @Test public void canCreateANewJavaClass() throws Exception { bot.toolbarDropDownButtonWithTooltip("New Java Class").menuItem("Class").click(); bot.shell("New Java Class").activate(); bot.textWithLabel("Source folder:").setText("MyFirstProject/src"); bot.textWithLabel("Package:").setText("org.eclipsecon.project"); bot.textWithLabel("Name:").setText("HelloWorld"); bot.button("Finish").click(); }
  • 48. Objectives Tasks canTypeInTextInAJavaClass() open a file: HelloWorld.java set some text in the Java file canExecuteJavaApplication() Run the Java application Run the test!
  • 49. canTypeInTextInAJavaClass() @Test public void canTypeInTextInAJavaClass() throws Exception { Bundle bundle = Activator.getContext().getBundle(); String contents = FileUtils.read(bundle.getEntry("test-files/HelloWorld.java")); SWTBotEditor editor = bot.editorByTitle("HelloWorld.java"); SWTBotEclipseEditor e = editor.toTextEditor(); e.setText(contents); editor.save(); }
  • 50. canExecuteJavaApplication() @Test public void canExecuteJavaApplication() throws Exception { bot.menu("Run").menu("Run").click(); // FIXME: verify that the program printed 'Hello World' }
  • 53. Objectives Learn about SWTBot and the Matcher API Tasks canExecuteJavaApplication() Run the Java application Grab the Console view Verify that “Hello World” is printed Run the tests!
  • 54. canExecuteJavaApplication() @Test public void canExecuteJavaApplication() throws Exception { bot.menu("Run").menu("Run").click(); SWTBotView view = bot.viewByTitle("Console"); Widget consoleViewComposite = view.getWidget(); StyledText console = bot.widget(WidgetMatcherFactory.widgetOfType(StyledText.class), consoleViewComposite); SWTBotStyledText styledText = new SWTBotStyledText(console); assertTextContains("Hello World", styledText); }
  • 55. Matchers Under the covers, SWTBot uses Hamcrest Hamcrest is a framework for writing ‘match’ rules SWTBot is essentially all about match rules bot.widget(WidgetMatcherFactory.widgetO fType(StyledText.class), consoleViewComposite);
  • 57. Creating matchers WidgetMatcherFactory is your friend! withText("Finish") withLabel("Username:") withRegex("Proceed to step (.*)") widgetOfType(Button.class) withStyle(SWT.ARROW, "SWT.ARROW")
  • 60. Objectives Learn about waiting and SWTBot Condition API Tasks afterClass() Select the Package Explorer view Select MyFirstProject Right click and delete the project Run the test!
  • 61. afterClass() @AfterClass public static void afterClass() throws Exception { SWTBotView packageExplorerView = bot.viewByTitle("Package Explorer"); packageExplorerView.show(); Composite packageExplorerComposite = (Composite) packageExplorerView.getWidget(); Tree swtTree = (Tree) bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), packageExplorerComposite); SWTBotTree tree = new SWTBotTree(swtTree); tree.select("MyFirstProject"); bot.menu("Edit").menu("Delete").click(); // the project deletion confirmation dialog SWTBotShell shell = bot.shell("Delete Resources"); shell.activate(); bot.checkBox("Delete project contents on disk (cannot be undone)").select(); bot.button("OK").click(); bot.waitUntil(shellCloses(shell)); }
  • 62. Handling long operations describe a condition poll for the condition at intervals wait for it to evaluate to true or false of course there’s a timeout SWTBot has an ICondition
  • 64. Handling Waits private void waitUntil(ICondition condition, long timeout, long interval) { long limit = System.currentTimeMillis() + timeout; condition.init((SWTBot) this); while (true) { try { if (condition.test()) return; } catch (Throwable e) { // do nothing } sleep(interval); if (System.currentTimeMillis() > limit) throw new TimeoutException("Timeout after: " + timeout); } }
  • 67. Abstractions are good! They simplify writing tests for QA folks Build page objects for common “services” Project Explorer The Editor The Console View The main menu bar, tool bar
  • 68. Model Capabilities Create a project Delete a project Create a class Execute a class more...
  • 70. Domain Objects? Represent the operations that can be performed on concepts
  • 71. Sample Domain Object public class JavaProject { public JavaProject create(String projectName){ // create a project and return it } public JavaProject delete(){ // delete the project and return it } public JavaClass createClass(String className){ // create a class and return it } }
  • 73. Page Objects? Represent the services offered by the page to the test developer Internally knows the details about how these services are offered and the details of UI elements that offer them Return other page objects to model the user’s journey through the application Different results of the same operation modeled
  • 74. Page Objects... should not Expose details about user interface elements Make assertions about the state of the UI
  • 75. A Sample Page Object public class LoginPage { public HomePage loginAs(String user, String pass) { // ... clever magic happens here } public LoginPage loginAsExpectingError(String user, String pass) { // ... failed login here, maybe because one or both of // username and password are wrong } public String getErrorMessage() { // So we can verify that the correct error is shown } }
  • 76. Using Page Objects // the bad test public void testMessagesAreReadOrUnread() { Inbox inbox = new Inbox(driver); inbox.assertMessageWithSubjectIsUnread("I like cheese"); inbox.assertMessageWithSubjectIsNotUndread("I'm not fond of tofu"); } // the good test public void testMessagesAreReadOrUnread() { Inbox inbox = new Inbox(driver); assertTrue(inbox.isMessageWithSubjectIsUnread("I like cheese")); assertFalse(inbox.isMessageWithSubjectIsUnread("I'm not fond of tofu")); }
  • 77. LoginPage login = new LoginPage(); HomePage home = login.loginAs("username", "secret"); SearchPage search = home.searchFor("swtbot"); assertTrue(search.containsResult("http://eclipse.org/swtbot"));
  • 79. Objectives Learn about page and domain objects Tasks Create a NewProjectBot Opens the new project wizard Allows you to set the project name and click finish Modify canCreateANewJavaProject() Run the test!
  • 80. NewProjectBot public class NewProjectBot { private static SWTWorkbenchBot bot; public NewProjectBot() { bot.menu("File").menu("New").menu("Project...").click(); bot.shell("New Project").activate(); bot.tree().select("Java Project"); bot.button("Next >").click(); } public void setProjectName(String projectName) { bot.textWithLabel("Project name:").setText(projectName); } public void finish() { bot.button("Finish").click(); } }
  • 81. Modify Project Wizard Code @Test public void canCreateANewJavaProject() throws Exception { // use the NewProjectBot abstraction NewProjectBot newProjectBot = new NewProjectBot(); newProjectBot.setProjectName("MyFirstProject"); newProjectBot.finish(); assertProjectCreated(); }
  • 83. Logging Turn logging on always, it helps :) http://wiki.eclipse.org/SWTBot/ FAQ#How_do_I_configure_log4j_to_turn_on _logging_for_SWTBot.3F
  • 84. Slow down executions Useful for debugging at times... SWTBotPreferences.PLAYBACK_DELAY -Dorg.eclipse.swtbot.playback.delay=20 or via code... long oldDelay = SWTBotPreferences.PLAYBACK_DELAY; // increase the delay SWTBotPreferences.PLAYBACK_DELAY = 10; // do whatever // set to the original timeout of 5 seconds SWTBotPreferences.PLAYBACK_DELAY = oldDelay;
  • 85. Changing Timeout SWTBotPreferences.TIMEOUT -Dorg.eclipse.swtbot.search.timeout=10000 or via code... long oldTimeout = SWTBotPreferences.TIMEOUT; // increase the timeout SWTBotPreferences.TIMEOUT = 10000; // do whatever // set to the original timeout of 5 seconds SWTBotPreferences.TIMEOUT = oldTimeout;
  • 86. Identifiers In our examples, we used labels as matchers mostly SWTBot allows you to use IDs as matchers IDs are less brittle than labels! text.setData(SWTBotPreferences.DEFAULT_ KEY,”id”) bot.textWithId(“id”)
  • 87. Page Objects Use Page Objects to simplify writing tests Allows more people than just normal devs to write tests
  • 88. More SWTBot? Eclipse Forms support in HEAD GEF support is available for graphical editor testing

Editor's Notes

  1. Should: * Represent the services offered by the page to the test developer * Internally knows the details about how these services are offered and the details of UI elements that offer them * Return other page objects to model the user’s journey through the application * Different results of the same operation modeled differently
  2. Should not: * Expose details about user interface elements * Make assertions about the state of the UI