Top Banner
EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot UI Test Automation with SWTBot Ketan Padegaonkar, Code Monkey ThoughtWorks Studios.
90

EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

Jun 05, 2018

Download

Documents

vonhi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

UI Test Automation with SWTBotKetan Padegaonkar, Code Monkey

ThoughtWorks Studios.

Page 2: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 3: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

+

Page 4: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 5: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

=

Page 6: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 7: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 8: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 9: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 10: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Challenges

Page 11: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesIdentifying Controls

Page 12: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesSimilar looking controls

Page 13: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Similar looking controls

Page 14: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Moving controls

Page 15: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesSending “events” to controls

Page 16: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesManage SWT Threading

Page 17: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesTests to be non-blocking

Page 18: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesRun in a separate thread

Page 19: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesRun in a separate thread

Still manage synchronization between threads

Page 20: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesMulti threaded applications, background jobs

Page 21: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesMulti threaded applications, background jobs

“Non-deterministic” in amount of time required

Page 22: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesInternationalization (i18n) and Localization (L10n)

Page 23: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesReadability

Page 24: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

ChallengesIdentifying controls

Similar looking controls

Moving controls

Sending “events to controls”

Manage SWT Threading

Tests to be non-blocking

Run in a separate thread, and manage synchronization

Multi threaded applications, background jobs

Internationalization (i18n) and Localization (L10n)

Readability

Page 25: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Testing ?

Page 26: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 27: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 28: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Unit Testing

Page 29: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 30: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 31: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 32: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

"red green refactor"

Page 33: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Functional Tests

Page 34: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 35: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 36: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 37: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 38: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Writing SWT Tests

Page 39: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 40: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Understand SWT

Page 41: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Understand Threading

Page 42: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 43: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Quality Analysts/Testers

Page 44: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Quality Analysts/Testers

Page 45: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 46: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 47: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

SWTBot

Page 48: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Agenda

Page 49: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

setting up the environment

basic SWTBot API

custom assertions

analyze failures

how does it work?

handling background jobs and long running operations

thread safety

improve performance

FluentAPI for common eclipse operations (DSL-ish)

Page 50: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Setting up the Environment

Page 51: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Eclipse 3.4

SWTBot update site

http://www.eclipse.org/swtbot/downloads.php

Setting up the Environment

Page 52: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

“org.eclipsecon.swtbot.example”

Create a plugin project

Page 53: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 54: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

org.eclipse.ui

org.eclipse.core.runtime

org.eclipse.swtbot.eclipse.finder

org.eclipse.swtbot.junit4_x

org.eclipse.swtbot.swt.finder

org.junit4

org.hamcrest

Setup Dependencies

Page 55: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 56: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Basic SWTBot API

Page 57: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

The first red and green barA “hello world” test!

Page 58: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

close the “Welcome Page”

Setup for the test

Page 59: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

creating a java project “MyFirstProject”

creating a java class “org.eclipsecon.project.HelloWorld”

type in a program that prints “Hello, World”

execute the program

verify that the program printed “Hello, World”

Create tests for

Page 60: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Teardown for the testdelete the project

Page 61: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

How does it work?

Page 62: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

!"#$%&'(

)"*#(+,,(

-"#$%&'(

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page 63: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Redundancy and Failure Proofing

Page 64: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

!"#$%&'(

)"*#(+,,(

-"#$%&'(

Page 65: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Find all widgetsDepth first traversal of UI elements

1. Find top level widgets

1. Find children of each widget

2. For each child do (1) and (2)

Page 66: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Creating matchers(simple)withText("Finish")

withLabel("Username:")

withRegex("Proceed to step (.*)")

widgetOfType(Button.class)

withStyle(SWT.ARROW, "SWT.ARROW")

Page 67: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

...Creating matchers(combination)allOf(matchers...)

anyOf(matchers...)

not(matcher)

allOf(anyOf(matchers...), matchers...)

Page 68: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Handling long running operationsdescribe a condition

poll for the condition at intervals

wait for it to evaluate to true or false

of course there’s a timeout

Page 69: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Handling Waits(SWTBot.java)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); }}

Page 70: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

The whole thing put togetherThe End User API

Page 71: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Finding widgets (SWTBot.java)public SWTBotTree treeWithLabelInGroup(String l, String g, int i) {

// create the matcherMatcher matcher =

allOf(widgetOfType(Tree.class), withLabel(l), inGroup(g)

);// find the widget, with redundancy built inTree tree = (Tree) widget(matcher, index);// create a wrapper for thread safety// and convinience APIsreturn new SWTBotTree(tree, matcher);

}

Page 72: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Thread SafetyTests should run in non-ui thread

query state of a widget

change state of a widget

Page 73: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

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(); } }); }}

Page 74: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

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); }}

Page 75: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Building Abstractions

Page 76: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Features and capabilities of tests(Page Objects)

Project Explorer

The Editor

The Console View

The main menu bar, tool bar

Page 77: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Features and capabilities of tests(Domain Objects)

Create a project

Delete a project

Create a class

Execute a class

more...

Page 78: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page Objects

http://code.google.com/p/webdriver/wiki/PageObjects

Page 79: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page Objects... shouldRepresent 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

Page 80: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page Objects... should notExpose details about user interface elements

Make assertions about the state of the UI

Page 81: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page Objects (implementation)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 }}

Page 82: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Page Objects (usage)

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

// the good testpublic void testMessagesAreReadOrUnread() { Inbox inbox = new Inbox(driver); assertTrue(inbox.isMessageWithSubjectIsUnread("I like cheese")); assertFalse(inbox.isMessageWithSubjectIsUnread("I'm not fond of tofu"));}

Page 83: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

LoginPage login = new LoginPage();HomePage home = login.loginAs("username", "secret");SearchPage search = home.searchFor("swtbot");assertTrue(search.containsResult("http://eclipse.org/swtbot"));

Page 84: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Exercise: Page ObjectsRefactor the tests in the form of a PageObject

Page 85: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Domain Objects

Page 86: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Domain Objects... shouldRepresent the operations that can be performed on concepts

Page 87: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Domain Objectspublic 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 88: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Going aheadCommonly used functionality bundled as convenience API

Eclipse Forms

GEF!

Use “real” events instead of “mocks”

Page 89: EclipseCon 2009 - Eclipse Downloadsdownload.eclipse.org/.../swtbot/docs/eclipsecon2009/SWTBotTutorial… · EclipseCon 2009 © 2009 - ThoughtWorks, Inc. Made available under the EPL

EclipseCon 2009

© 2009 - ThoughtWorks, Inc. Made available under the EPL v1.0. eclipse.org/swtbot

Questions ?newsgroup: news://news.eclipse.org/eclipse.swtbot

web: eclipse.org/swtbot

gmail: KetanPadegaonkar