Easy GUI Testing with FEST
-
Upload
softwarecentral -
Category
Documents
-
view
4.261 -
download
9
Transcript of Easy GUI Testing with FEST
Easy GUI Testing with FEST
Oracle Corporation
Alex RuizSoftware Engineer
Yvonne W. PriceSoftware Engineer
www.javapolis.com
Overall Presentation Goal
Learn a simple and easy way to test Swing GUI applications
www.javapolis.com
Speaker’s Qualifications
Alex Ruiz writes articles about testing and DSLs for several publications
Alex speaks frequently about testing at conferences
Alex works on the core IDE platform at Oracle using Swing
Yvonne Wang Price has written about Test-Driven GUI Development for IEEE Software
Yvonne speaks frequently about GUI testing at conferences
www.javapolis.com
Do you test your GUIs?
Testing GUIs, although essential, has been difficult to achieve
www.javapolis.com
Do you test your GUIs?
Testing GUIs, although essential, has been difficult to achieve
…until now!
www.javapolis.com
Agenda
Introducing FEST Features Roadmap Demo Summary Q & A
www.javapolis.com
Introducing FEST
Library for functional GUI testing Open Source (Apache 2.0 license) Supports both JUnit and TestNG DSL-oriented API that is both easy to read
and write Supports all Swing components included in
the JDK
www.javapolis.com
Features
Robust GUI testing Easy test setup DSL-oriented, “fluent” API Screenshots of failing tests Drag ‘n Drop Testing long-duration tasks Testing legacy/existing applications
www.javapolis.com
Features
Simulates user events Provides a reliable mechanism for finding GUI
components By name By type By Custom Search Criteria
Tolerates changes in a component's position and/or layout.
Robust GUI Testing
www.javapolis.com
Features
Example:
private FrameFixture frame;
@BeforeMethod public void setUp() { frame = new FrameFixture(new MyFrame()); frame.show(); }
@AfterMethod public void tearDown() { frame.cleanUp();}
Easy Test Setup
www.javapolis.com
Features
Example: Test that the text of label changes to “bye!”
when clicking the “Bye” button:
@Test public void shouldChangeTextWhenClickingButton() { frame.button("byeButton").click(); frame.label("messageLabel").requireText("Bye!"); }
DSL-Oriented, “Fluent” API
www.javapolis.com
Features
Right-click a specific item in a JList:list("employees").item("Gandalf") .rightClick();
Show a JPopupMenu in a JTextField and select “Copy”:textBox("name").showPopupMenu() .selectItem("Copy");
Double-click a specific cell in a JTable:table("name").cell(row(0).column(3)) .doubleClick();
DSL-Oriented, “Fluent” API
www.javapolis.com
Features
Click a list 2 times:list("employees").doubleClick();list("employees").click(leftButton().times(2));
DSL-Oriented, “Fluent” API
www.javapolis.com
Features
Takes a picture of the desktop if a GUI test fails
Supports both JUnit and TestNG
Plugs into existing reporting infrastructure with minimal changes
Screenshots of Failing Tests
www.javapolis.com
Features
JUnit: @RunWith(GUITestRunner.class) Ant’s “junit” task
Screenshots of Failing Tests
www.javapolis.com
Features
TestNG: ScreenshotOnFailureListener
Screenshots of Failing Tests
www.javapolis.com
Features
Example: drag from list and drop in table
frame.list("projects").drag("FEST");frame.table("active").drop(row(2).column(0));
Drag ‘n Drop
www.javapolis.com
Features
Example: Successful login
// simulate a user login inlogin.textBox("username").enterText("frodo");login.textBox("password").enterText("ring");login.button("ok").click();
// wait for authentication/authorization to// finish, and get a reference to the main // windowFrameFixture mainFrame = findFrame("main").withTimeout(10, SECONDS) .using(robot);
Testing Long-Duration Tasks
www.javapolis.com
Features
Legacy applications may not have unique GUI component names
Example: find button with text “OK”
GenericTypeMatcher<JButton> textMatcher = new GenericTypeMatcher<JButton>() { protected boolean isMatching(JButton button) { return "OK".equals(button.getText()); } };dialog.button(textMatcher).click();
Testing Legacy Applications
www.javapolis.com
Roadmap
Finish Groovy support Add support for testing GUIs in other JVMs Finish pending features January/February 2008: FEST 1.0! Add support for SwingX, JIDE and
Flamingo Component Suite Add JRuby-based API A really nice surprise coming up!!
www.javapolis.com
Roadmap
fixture.frame(new MyFrame()) { show(width: 400, height: 200)
textBox("name") { enterText("Leia") select("ia") } button("ok") { click() } }
Groovy Support (quick peek)
DemoTesting a Login Window
www.javapolis.com
Demo
Testing a Login Window
www.javapolis.com
Demo
Testing a Login Window
www.javapolis.com
Links
FEST website: http://fest.easytesting.org/swing/ Getting started guide, Javadocs, feature
references, examples, articles, etc.
Books: “Java Power Tools” by John Ferguson Smart
(February 2008) “Next Generation Java Testing” by Cédric Beust
and Hani Suleiman
www.javapolis.com
Summary
FEST is an open source library that makes functional GUI testing really simple and easy
Its DSL-oriented API is easy to write and read, reducing time spent writing and maintaining tests
FEST provides useful debugging features that can help us diagnose testing failures
www.javapolis.com
Concluding Statement
FEST makes GUI testing easy and simple.
There are no more excuses for not testing our GUIs!
What are you waiting for? Start testing!!
Q&AView JavaPolis talks @ www.parleys.com
Thank you for your attention