Easy GUI Testing with FEST

29
Easy GUI Testing with FEST Oracle Corporation Alex Ruiz Software Engineer Yvonne W. Price Software Engineer

Transcript of Easy GUI Testing with FEST

Page 1: Easy GUI Testing with FEST

Easy GUI Testing with FEST

Oracle Corporation

Alex RuizSoftware Engineer

Yvonne W. PriceSoftware Engineer

Page 2: Easy GUI Testing with FEST

www.javapolis.com

Overall Presentation Goal

Learn a simple and easy way to test Swing GUI applications

Page 3: Easy GUI Testing with FEST

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

Page 4: Easy GUI Testing with FEST

www.javapolis.com

Do you test your GUIs?

Testing GUIs, although essential, has been difficult to achieve

Page 5: Easy GUI Testing with FEST

www.javapolis.com

Do you test your GUIs?

Testing GUIs, although essential, has been difficult to achieve

…until now!

Page 6: Easy GUI Testing with FEST

www.javapolis.com

Agenda

Introducing FEST Features Roadmap Demo Summary Q & A

Page 7: Easy GUI Testing with FEST

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

Page 8: Easy GUI Testing with FEST

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

Page 9: Easy GUI Testing with FEST

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

Page 10: Easy GUI Testing with FEST

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

Page 11: Easy GUI Testing with FEST

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

Page 12: Easy GUI Testing with FEST

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

Page 13: Easy GUI Testing with FEST

www.javapolis.com

Features

Click a list 2 times:list("employees").doubleClick();list("employees").click(leftButton().times(2));

DSL-Oriented, “Fluent” API

Page 14: Easy GUI Testing with FEST

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

Page 15: Easy GUI Testing with FEST

www.javapolis.com

Features

JUnit: @RunWith(GUITestRunner.class) Ant’s “junit” task

Screenshots of Failing Tests

Page 16: Easy GUI Testing with FEST

www.javapolis.com

Features

TestNG: ScreenshotOnFailureListener

Screenshots of Failing Tests

Page 17: Easy GUI Testing with FEST

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

Page 18: Easy GUI Testing with FEST

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

Page 19: Easy GUI Testing with FEST

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

Page 20: Easy GUI Testing with FEST

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!!

Page 21: Easy GUI Testing with FEST

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)

Page 22: Easy GUI Testing with FEST

DemoTesting a Login Window

Page 23: Easy GUI Testing with FEST

www.javapolis.com

Demo

Testing a Login Window

Page 24: Easy GUI Testing with FEST

www.javapolis.com

Demo

Testing a Login Window

Page 25: Easy GUI Testing with FEST

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

Page 26: Easy GUI Testing with FEST

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

Page 27: Easy GUI Testing with FEST

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!!

Page 28: Easy GUI Testing with FEST

Q&AView JavaPolis talks @ www.parleys.com

Page 29: Easy GUI Testing with FEST

Thank you for your attention