Jemmy tutorial. Introduction to Jemmy testing framework. Pawel Prokop. March 14, 2012. pawel.prokop@adfinem.net



Similar documents
UI Performance Monitoring

Unit Testing. and. JUnit

Appium mobile test automation

Generating Automated Test Scripts for AltioLive using QF Test

Java Unit testing with JUnit 4.x in Eclipse

Unit Testing JUnit and Clover

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

TESTING WITH JUNIT. Lab 3 : Testing

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in

JDemo - Lightweight Exploratory Developer Testing

Slides prepared by : Farzana Rahman TESTING WITH JUNIT IN ECLIPSE

Unit Testing & JUnit

International Journal of Advanced Engineering Research and Science (IJAERS) Vol-2, Issue-11, Nov- 2015] ISSN:

Eclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.

Approach of Unit testing with the help of JUnit

AP Computer Science Java Subset

Debugging Java Applications

Table of Contents. LESSON: The JUnit Test Tool...1. Subjects...2. Testing What JUnit Provides...4. JUnit Concepts...5

ID TECH UniMag Android SDK User Manual

Milosz Mazurkiewicz GUI TEST AUTOMATION WITH SWTBOT

A Practical Guide to Test Case Types in Java

Build management & Continuous integration. with Maven & Hudson

Plugin JUnit. Contents. Mikaël Marche. November 18, 2005

The Darwin Game 2.0 Programming Guide

Testing, Debugging, and Verification

Using NetBeans IDE to Build Quick UI s Ray Hylock, GISo Tutorial 3/8/2011

JAVA DEVELOPER S GUIDE TO ASPRISE SCANNING & IMAGE CAPTURE SDK

Computing Concepts with Java Essentials

An Overview of Java. overview-1

Applets, RMI, JDBC Exam Review

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java Interview Questions and Answers

Tutorial: Time Of Day Part 2 GUI Design in NetBeans

Capabilities of a Java Test Execution Framework by Erick Griffin

How to develop your own app

Tutorial: Getting Started

UNIT TESTING. Written by Patrick Kua Oracle Australian Development Centre Oracle Corporation

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

Fair Scheduler. Table of contents

Software Quality Exercise 2

Syllabus for CS 134 Java Programming

Beyond Unit Testing. Steve Loughran Julio Guijarro HP Laboratories, Bristol, UK. steve.loughran at hpl.hp.com julio.guijarro at hpl.hp.

Winning the Battle against Automated Testing. Elena Laskavaia March 2016

Performance Testing from User Perspective through Front End Software Testing Conference, 2013

Effective unit testing with JUnit

Unit Testing webmethods Integrations using JUnit Practicing TDD for EAI projects

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Continuous Integration

Continuous Integration: Aspects in Automation and Configuration Management

Tutorial 5: Developing Java applications

Unit Testing and JUnit

Going Interactive: Combining Ad-Hoc and Regression Testing

Automation using Selenium

Analog Monitoring Tool AMT 0.3b User Manual

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

How To Test In Bluej

Java CPD (I) Frans Coenen Department of Computer Science

Habanero Extreme Scale Software Research Project

How To Write A File Station In Android.Com (For Free) On A Microsoft Macbook Or Ipad (For A Limited Time) On An Ubuntu 8.1 (For Ubuntu) On Your Computer Or Ipa (For

+ Introduction to JUnit. IT323 Software Engineering II By: Mashael Al-Duwais

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

JUnit Automated Software Testing Framework. Jeff Offutt. SWE 437 George Mason University Thanks in part to Aynur Abdurazik. What is JUnit?

Tools for Integration Testing

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Project 4 DB A Simple database program

Demo: Embedding Windows Presentation Foundation elements inside a Java GUI application. Version 7.3

Swing. A Quick Tutorial on Programming Swing Applications

MarathonITE. GUI Testing for Java/Swing Applications

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

IDE s for Java, C, C++ David Rey - DREAM

Game Programming with Groovy. James Sr. Software Engineer, BT/Ribbit

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Evaluation of AgitarOne

Java is commonly used for deploying applications across a network. Compiled Java code

Pemrograman Dasar. Basic Elements Of Java

Testing Methodology Assignment 1 Unit testing using JUnit

Robotium Automated Testing for Android

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Announcement. SOFT1902 Software Development Tools. Today s Lecture. Version Control. Multiple iterations. What is Version Control

Japan Communication India Skill Development Center

GUI Test Automation How-To Tips

Automated Integration Testing & Continuous Integration for webmethods

Android Environment SDK

Running a Program on an AVD

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

JUnit - A Whole Lot of Testing Going On

Principles of integrated software development environments. Learning Objectives. Context: Software Process (e.g. USDP or RUP)

Java Software Structures

Software project management. and. Maven

Android Environment SDK

Transcription:

tutorial Introduction to testing framework pawel.prokop@adfinem.net http://prokop.uek.krakow.pl March 14, 2012

Recording tests Testing frameworks Summary Manualy testing error prone slow and not efficient repeating test costs a lot no place for TDD boring for developers (dinner syndrome) flexible look & feel fast feedback

Recording tests Testing frameworks Summary Recording user actions to exercise the application efficient fast preparation fast execution cheap hard to modify during application development common functionalities no place for TDD

Recording tests Testing frameworks Summary Available tools for test recording SWTBot is an open-source Java based functional testing tool for testing SWT and Eclipse based applications. http://www.eclipse.org/swtbot/ Marathon allows to record the script that can be modified later manualy. Supports assertions. www.marathontesting.com/ Jacareto is a tool that allows capture actions on applications and replay them later. http://jacareto.sourceforge.net/wiki

Recording tests Testing frameworks Summary Write code that simulates user actions efficient moderate slow preparation parts of code may be reused fast execution easy to modify during application development can be used with TDD

Recording tests Testing frameworks Summary Testing frameworks UISpec4J is an open source framework to test Swing applications. http://www.uispec4j.org/ JFCUnit is an extension of JUnit that allows to execute unit tests against Swing based interface. http://jfcunit.sourceforge.net/ is an open source framework that allows to simulate user interactions with Swing applications. https://svn.java.net/svn/jemmy~svn

Recording tests Testing frameworks Summary Summary Manual testing Recording Framework Efficiency - + + Preparation time + + +/- Execution time - + + Price - + + Reusability - - + TDD - - + Flexibility + - -

Introduction Installation introduction documentation not so many tutorials not so many presentations and documents good javadoc is enough to start few samples low vitality

Introduction Installation framework How works? the same JVM as tested application simulates user operations on the components by calling events events are stored on the QueueTool class and then provided to AWT EventQueue search components recursively by given criteria (caption, name) criteria defined as implementation of ComponentChooser interface

Introduction Installation framework in TDD approach design UI interface and the components implement jemmy tests to fit the interface run failing tests create implementation and re-run tests until they pass

Introduction Installation Installation Eclipse add jemmy.jar to the Java Build Path

Introduction Installation Installation Netbeans add Jar/Folder to Libraries

Introduction Installation Integration with JUnit 1 @Ignore 2 p u b l i c class CommonTest { 3 protected s t a t i c JMyApplication a p p l i c a t i o n = n u l l ; 4 5 public CommonTest ( ) { } 6 7 @BeforeClass 8 public s t a t i c void setupclass ( ) throws Exception { } 9 10 @AfterClass 11 public s t a t i c void teardownclass ( ) throws Exception { } 12 13 @Before 14 p u b l i c void setup ( ) throws Exception { 15 application = new JMyApplication ( ) ; 16 a p p l i c a t i o n. startjmyforms ( ) ; 17 } 18 19 @After 20 public void teardown ( ) throws Exception { 21 a p p l i c a t i o n. stopjmyforms ( ) ; 22 } 23 }

Introduction Installation Integration with Ant

Introduction Installation Integration with Ant 1 < p r o j e c t name= "Sample"> 2 < t a r g e t name= " j u n i t " > 3 < j u n i t printsummary= " yes " > 4 <classpath path= " l i b s / j u n i t 4.5. j a r " / > 5 <classpath path= " l i b s / jemmy. j a r " / > 6 <classpath path= " b u i l d / t e s t / classes / " / > 7 <classpath path= " b u i l d / classes / " / > 8 <batchtest fork= " yes "> 9 < f i l e s e t d i r = " t e s t " i n cludes=" / Test. java " / > 10 < / b a t c h t e s t > 11 < / j u n i t > 12 < / t a r g e t > 13 < / p r o j e c t > 1 ant f j u n i t. xml j u n i t

Operators Concept depended approach Component choosers Timeouts Find components Operators Communication with UI controls is realized by operators defines own operators for every AWT/Swing UI component JFrameOperator JDialogOperator JButtonOperator JCheckBoxOperator JComboBoxOperator JFileChooserOperator...and many others Operators can be extended by the developer

Operators Concept depended approach Component choosers Timeouts Find components Operators - small example Yes/No dialog operator 1 p u b l i c class YesNoDialogOperator extends JDialogOperator { 2 p u b l i c YesNoDialogOperator ( ) { 3 super ( " Confirmation " ) ; 4 } 5 6 public void pushyes ( ) { 7 new JButtonOperator ( t h i s, " Yes " ). push ( ) ; 8 } 9 10 public void pushno ( ) { 11 new JButtonOperator ( t h i s, "No" ). push ( ) ; 12 } 13 }

Operators Concept depended approach Component choosers Timeouts Find components Operators - small example Usage 1 / /... 2 @Test 3 public void test_some_functionality ( ) { 4 / /... 5 YesNoDialogOperator operator = new YesNoDialogOperator ( ) ; 6 a s s e r t N o t N u l l ( operator ) ; 7 operator. pushyes ( ) ; 8 / /... 9 } 10 / /...

Operators Concept depended approach Component choosers Timeouts Find components Load application with jemmy class reference 1 new ClassReference ( " jemmysample. SampleApplication " ). startapplication ( ) ; direct call 1 SampleApplication. main ( n u l l ) ;

Operators Concept depended approach Component choosers Timeouts Find components Concept depended approach create classes that support some application s functionality: 1 class MyMainDialog extends JDialogOperator { 2 public s t a t i c String dialogcaption = "My Dialog " ; 3 4 public MyMainDialog ( ) { super ( dialogcaption ) ; } 5 6 p u b l i c void pushbuttoncancel ( ) { 7 new JButtonOperator ( " Cancel " ). push ( ) ; 8 } 9 } and then use them from test suites: 1 @Test 2 public void test_dialog_can_cancel ( ) { 3 MyMainDialog dialogoperator = new MyMainDialog ( ) ; 4 dialogoperator. pushbuttoncancel ( ) ; 5 }

Operators Concept depended approach Component choosers Timeouts Find components Application Shadow 1 p u b l i c class JMyApplication { 2 private JFrameOperator mainframe = n u l l ; 3 4 public JFrameOperator getmainframe ( ) { 5 return mainframe ; 6 } 7 8 public i n t startjmyforms ( ) { 9 SampleApplication. main ( n u l l ) ; 10 mainframe = new JFrameOperator ( "JMyForms " ) ; 11 r e t u r n 0; 12 } 13 14 public i n t stopjmyforms ( ) { 15 JMenuBarOperator menubarop = new JMenuBarOperator ( mainframe ) ; 16 JMenuOperator filemenu = new JMenuOperator (menubarop. getmenu ( 0 ) ) ; 17 filemenu. pushmenu ( " F i l e E x i t " ) ; 18 r e t u r n 0; 19 } 20 }

Operators Concept depended approach Component choosers Timeouts Find components The Component Choosers How to find component? using its index inside the container textfield next to label using Component Chooser implementation NameComponentChooser uses a name property PropChooser uses properties and methods to match a component Developer can define custom component choosers - implementing ComponentChooser interface

Operators Concept depended approach Component choosers Timeouts Find components RegexpFrameTitleChooser 1 p u b l i c class RegexpFrameTitleChooser implements ComponentChooser { 2 Pattern p a t t e r n = n u l l ; 3 4 p u b l i c RegexpFrameTitleChooser ( S t r i n g p a t t e r n ) { 5 t h i s. p a t t e r n = Pattern. compile ( p a t t e r n ) ; 6 } 7 8 @Override 9 public boolean checkcomponent ( Component component ) { 10 i f ( component instanceof JFrame ) { 11 S t r i n g f r a m e T i t l e = ( ( JFrame ) component ). g e t T i t l e ( ) ; 12 Matcher matcher = pattern. matcher ( frametitle ) ; 13 return matcher. matches ( ) ; 14 } 15 return false ; 16 } 17 18 @Override 19 public String getdescription ( ) { 20 return pattern. pattern ( ) ; 21 } 22 }

Operators Concept depended approach Component choosers Timeouts Find components ShowingComponentChooser 1 p u b l i c class ShowingNameComponentChooser extends NameComponentChooser { 2 p u b l i c ShowingNameComponentChooser ( S t r i n g name) { 3 super (name ) ; 4 } 5 6 @Override 7 public boolean checkcomponent ( Component component ) { 8 i f ( super. checkcomponent ( component ) && component. isshowing ( ) ) { 9 return true ; 10 } 11 return false ; 12 } 13 14 15 16 }

Operators Concept depended approach Component choosers Timeouts Find components Timeouts time values (milliseconds) to wait for something to be done by the application

Operators Concept depended approach Component choosers Timeouts Find components Timeouts to delay simulated user behaviour kept by org.netbeans.jemmy.timeouts class 1 / / Set delay before key i s pressed during t y p i n g 2 Properties. getcurrenttimeouts ( ). settimeout 3 ( " JTextComponentOperator. PushKeyTimeout ", 50); each instance can have its own timeouts set 1 / / Set delay between button pressing and releasing. 2 JButtonOperator btnoperator = new JButtonOperator ( " Process " ) ; 3 btnoperator. gettimeouts ( ) 4. settimeout ( " AbstractButtonOperator. PushButtonTimeout ", 500);

Operators Concept depended approach Component choosers Timeouts Find components Timeouts cont. to wait until timeout exception is raised 1 / / wait up to 5 seconds f o r JDialog 2 Properties. getcurrenttimeouts ( ). settimeout 3 ( " DialogWaiter. WaitDialogTimeout ", 5000); 4 JDialogOperator albums = new JDialogOperator ( " Dialog Caption " ) ;

Operators Concept depended approach Component choosers Timeouts Find components More timeouts JComboBoxOperator.BeforeSelectingTimeout - time to sleep after list opened and before item selected JComboBoxOperator.WaitListTimeout - time to wait list opened ComponentOperator.WaitStateTimeout - time to wait for item to be selected JTextComponentOperator.PushKeyTimeout - time between key pressing and releasing during text typing JTextComponentOperator.BetweenKeysTimeout - time to sleep between two chars typing

Operators Concept depended approach Component choosers Timeouts Find components find method vs operator constructor static find method returns the operator or null immediately: 1 @Test 2 public void test_some_functionality ( ) { 3 / /... 4 JDialogOperator mydialog = JDialogOperator. f i n d D i a l o g ( " E r r o r ", true, t r u e ) ; 5 i f ( n u l l == mydialog ) { 6 / / no E r r o r d i a l o g i s c u r r e n t l y displayed 7 } 8 / /... 9 } constructor blocks until component appears on the screen or timeout. 1 public void test_some_functionality ( ) { 2 / /... 3 JDialogOperator mydialog = new JDialogOperator ( " E r r o r " ) ; 4 / /... 5 }

Screenshot Dump componenets Screenshot feature Capture screen shot 1 / /... 2 @Test 3 public void testsomefunctionality ( ) { 4 / /... 5 org. netbeans. jemmy. u t i l. PNGEncoder 6. capturescreen ( " testsomefunctionality. png " ) ; 7 / /... 8 } 9 / /... Image modes black and white grayscale colour

Screenshot Dump componenets Dump components in JVM Dump components in JVM Dump all components 1 / /... 2 @Test 3 public void testsomefunctionality ( ) { 4 / /... 5 org. netbeans. jemmy. u t i l. Dumper. dumpall ( " jemmy_example. xml " ) ; 6 / /... 7 } 8 / /... Dump component 1 / /... 2 public void testsomefunctionality ( ) { 3 / /... 4 Component comp = application. getmainframe ( ). getcomponent ( 0 ) ; 5 org. netbeans. jemmy. u t i l. Dumper. dumpcomponent ( comp, 6 " jemmy_example_component. xml " ) ; 7 / /... 8 } 9 / /...

GUIBrowser tool GUIBrowser tool shows all GUI objects in current JVM shows components in hierarchy allows to take snapshot in defined time delay displays component members (name, caption, size...)

GUIBrowser tool Launch GUIBrowser tool 1 new ClassReference ( " org. netbeans. jemmy. e x p l o r e r. GUIBrowser " ). s t a r t A p p l i c a t i o n ( ) ;

GUIBrowser tool Questions? Questions?

GUIBrowser tool Links 1. Operators: http://wiki.netbeans.org/_operators_environment 2. repository: https://svn.java.net/svn/jemmy~svn 3. tutorial: http://wiki.netbeans.org/_tutorial 4. this presentation: http://prokop.ae.krakow.pl/projects/download/ jemmy_introduction.pdf

GUIBrowser tool Credits 1. flickr/ant/binux 2. flickr/clock/kobiz7