1 qftestJUI M. Pasquato European Southern Observatory Garching, 12 - Jan - 2006.

39
1 qftestJUI M. Pasquato European Southern Observatory Garching, 12 - Jan - 2006

Transcript of 1 qftestJUI M. Pasquato European Southern Observatory Garching, 12 - Jan - 2006.

1

qftestJUIqftestJUI

M. PasquatoEuropean Southern Observatory

Garching, 12 - Jan - 2006

2

What’s this about?

• QFSTestJUI is a capture/replay test driver for Java applications

• A capture/replay tool works exactly like a cassette-recorder: you first record, then you can play back as many times as you want

• This is useful for testing Java GUIs and for exercising systems whose only access is via a GUI

3

System Under Test

• A System Under Test (SUT) is an user application that runs from qftestJUI.

• JDK or JRE instrumentation is used to provide a way for qftestJUI to interact with SUT (Chapter 17 manual)

4

Node

Insertion Marker

Run Buttons Debug ButtonsRecord Buttons

Terminal Output Area

No

de

Att

ribu

tes

Children

qftestJUI GUI

Sequence Node

Test Node

5

Test-Suite

6

Sequence and Test Nodes

• A Sequence node executes its child nodes one by one in the order they appear.

The concept behind a Sequence node is that its child nodes must be run in exactly that order and that each node depends on the outcome of the previous node to work correctly. A sequence of recorded events is a very good example for what constitutes a Sequence node.

• A Test node also executes its independent children one by one after having guaranteed for each of them similar conditions (Setup and Cleanup).

7

Test-Suite and Execution Order

8

Various methods to start the SUT

• There are basically two ways to start a Java application as an SUT from qftestJUI.

• The first one is based on the standard java ... command line with its two variants for either starting a class or a jar file.

• The alternative is running a script or executable file which will then start the Java program.

• Indirect methods like launching the SUT through ant also fall into this category, as do Java WebStart and applets run in the Java plugin of a web browser.

9

Starting the SUT

10

Building a Test-Suite

11

Recording Components: F11+Click

12

Recording Components (2)

• All graphical items in a GUI are translated by qftestJUI in Windows and Components Nodes with an unique ID.

• Users can use the method setName to assign his/her own unique name(ID).

• Component recognition is done via an good, but not perfect, algorithm. The usage of setName makes it reliable over time (changes).

13

Waiting for Component

14

Check State

15

Check Text

16

Check Image

17

Deterministic Try/Catch

Attribute to be Set

Base class for all exceptions: TestException

18

Implicitly Catch Exception• When an exception is thrown during the execution of one of the

Test’s normal child nodes, the Test is usually terminated prematurely.

• This may not be what you want, since no information is gained from the execution of the rest of the child nodes.

• If the Setup and Cleanup of the test are set up so you can guarantee the same initial conditions for each child node even in the case of an exception, you can set this attribute to make the Test catch the exception implicitly.

• That way, if an exception is caught from a normal child node, the exception is logged and the execution of that child node is stopped. Then the Test continues with the Cleanup as if nothing had happened.

• Exceptions thrown during the execution of either the Setup or the Cleanup cannot be caught that way and will always terminate the Test.

19

Implicitly Catch Exception (2)

Attribute to be SetAttribute to be Set

20

Implicitly Catch Exception (3)

21

Components: List - Table - Tree

22

Tree – Numeric Access

23

Variables• $(var) # Expands to the value

of some previously defined variable

• ${group:name} #Accesses external data from a resource bundle or property file

• $[expression] #Evaluates some mathematical expression

24

Variables: Priority (2)

Procedures Variables

Low Priority

High Priority

25

Control Structures Nodes: Loop

Fixed Value

Parameter

26

Procedures

Parameter passed color=red

Local Variable color=green is overridden with value “red”

Local Variable color=green

27

Package = (Procedure)+(Package)*

28

Includes others Suites

qftestJUI -batch -report.copyicons -report.depth 10 -report.html %b.html -systemcfg $HOME/qftestJUI.cfg -variable IP=$IP -variable HOST=$HOST -variable HOME=$HOME -libpath $HOME -runlog %b.qrz acscommandcenter.qft

29

Modularization

General Variable

30

Run - Log

31

Html – Xml reports

32

Debugger

Breakpoint

Step-in

Step-over

Step-out

33

Scripting

• qftestJUI can embed Jython scripts into its own test-suite. There are two Nodes for this: Server Script and SUT Script

• Server Scripts are run in a Jython interpreter embedded in qftestJUI

• SUT Scripts are run in a Jython interpreter embedded in the SUT

34

Scripting: Example

35

RC Variable

RC represent the run-context which encapsulates the current state of the execution of the test. It provides an interface for accessing qftestJUI’s variables, for calling qftestJUI Procedures and can be used to add messages to the run-log. To SUT scripts it also provides access to the actual Java components of the SUT’s GUI.

36

RC: Examples

rc.logMessage("This is a plain message")

rc.check(var == 0, "!Value of var is 0")# global variable set in the Sequence Node (x=25)

# lookup is used to access values as strings

global x

x = 2 * int(rc.lookup("x"))# log some values

rc.logMessage("x=" + `x`)

37

RC and SUT’s GUI Components

For SUT scripts RC provides the method getComponent(“componentID”) that retrieves the information of the NODE with ID componentID.

# get the text field

global field

field = rc.getComponent("value")

# fetch its value

rc.logMessage("The current value is " + field.getText())

38

RC and Procedures

RC Variable can also be used to call back into qftestJUI and execute Procedure Noderc.callProcedure(“Package.Procedure”,

{“Parameter”:”Value”, “Parameter”:”Value”,…})

39

Jython’s Modules

Jython’s Modules are like Python’s Modules.

# Modules myModuleimport stringdef loadTable(file, separator=’|’): data = [] fd = open(file, "r") line = fd.readline() while line: line = string.strip(line) if len(line) > 0: data.append(string.split(line,separator)) line = fd.readline() return data

import myModule# load the datadata = myModule.loadTable(rc.lookup("filename"))