qftest JUI M Pasquato European Southern Observatory Garching
qftest. JUI M. Pasquato European Southern Observatory Garching, 12 - Jan - 2006 1
What’s this about? • QFSTest. JUI 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 2
System Under Test • A System Under Test (SUT) is an user application that runs from qftest. JUI. • JDK or JRE instrumentation is used to provide a way for qftest. JUI to interact with SUT (Chapter 17 manual) 3
Record Buttons Run Buttons Debug Buttons qftest. JUI GUI Node Children Test Node Attributes Insertion Marker Sequence Node Terminal Output Area 4
Test-Suite 5
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). 6
Test-Suite and Execution Order 7
Various methods to start the SUT • There are basically two ways to start a Java application as an SUT from qftest. JUI. • 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 Web. Start and applets run in the Java plugin of a web browser. 8
Starting the SUT 9
Building a Test-Suite 10
Recording Components: F 11+Click 11
Recording Components (2) • All graphical items in a GUI are translated by qftest. JUI in Windows and Components Nodes with an unique ID. • Users can use the method set. Name to assign his/her own unique name(ID). • Component recognition is done via an good, but not perfect, algorithm. The usage of set. Name makes it reliable over time (changes). 12
Waiting for Component 13
Check State 14
Check Text 15
Check Image 16
Deterministic Try/Catch Attribute to be Set Base class for all exceptions: Test. Exception 17
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. 18
Implicitly Catch Exception (2) Attribute to be Set 19
Implicitly Catch Exception (3) 20
Components: List - Table - Tree 21
Tree – Numeric Access 22
Variables • $(var) • ${group: name} • $[expression] # Expands to the value of some previously defined variable #Accesses external data from a resource bundle or property file #Evaluates some mathematical expression 23
Variables: Priority (2) Low Priority Procedures Variables High Priority 24
Control Structures Nodes: Loop Fixed Value Parameter 25
Procedures Parameter passed color=red Local Variable color=green is overridden with value “red” 26
Package = (Procedure)+(Package)* 27
Includes others Suites qftest. JUI -batch -report. copyicons -report. depth 10 -report. html %b. html -systemcfg $HOME/qftest. JUI. cfg -variable IP=$IP -variable HOST=$HOST -variable HOME=$HOME -libpath $HOME -runlog %b. qrz acscommandcenter. qft 28
Modularization General Variable 29
Run - Log 30
Html – Xml reports 31
Debugger Step-in Step-out Step-over Breakpoint 32
Scripting • qftest. JUI 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 qftest. JUI • SUT Scripts are run in a Jython interpreter embedded in the SUT 33
Scripting: Example 34
RC Variable RC represent the run-context which encapsulates the current state of the execution of the test. It provides an interface for accessing qftest. JUI’s variables, for calling qftest. JUI 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. 35
RC: Examples rc. log. Message("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. log. Message("x=" + `x`) 36
RC and SUT’s GUI Components For SUT scripts RC provides the method get. Component(“component. ID”) that retrieves the information of the NODE with ID component. ID. # get the text field global field = rc. get. Component("value") # fetch its value rc. log. Message("The current value is " + field. get. Text()) 37
RC and Procedures RC Variable can also be used to call back into qftest. JUI and execute Procedure Node rc. call. Procedure(“Package. Procedure”, {“Parameter”: ”Value”, …}) 38
Jython’s Modules are like Python’s Modules. import my. Module # load the data = my. Module. load. Table(rc. lookup("filename")) # Modules my. Module import string def load. Table(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 39
- Slides: 39