Scripting in QF-Test (basics)
Here you will learn about the basics of scripting in QF-Test and get a demonstration for using the SUT script and Server script nodes.
Further information: Scripting in QF-Test (Manual)
Transcript
Welcome to this video about the scripting capabilities of QF-Test.
Today I will give you an overview of how to use scripts in QF-Test.
In addition to event nodes such as mouse clicks or checks and control structures such as loops or if nodes, QF-Test also offers the possibility to integrate arbitrary code snippets implemented in various scripting languages into the test run. Such scripts can greatly extend the functionality of QF-Test.
Script Types
To insert such a script, I select insert control structures from the menu and then Server or SUT script.
- Unlike a Server script, an SUT script can interact directly with the system under test and therefore also determine the properties of graphical objects at runtime.
- A Server script on the other hand should be used for actions that are independent of the graphical user interface such as database or file operations.
I am now adding an SUT script to my test suite. There are several scripting languages available for implementation. In the current version of QF-Test, there are Jython, Groovy, and JavaScript.
SUT script example
A simple example of an SUT script is the count of rows in a table and then to write this row count to the QF-Test run log. We will now implement the script in the Groovy scripting language:
def table = rc.getComponent("#VehicleTable")
def rows = table.getElementsByClassName("TableRow")
def rowCount = rows.size()
rc.logMessage("Table has " + rowCount + " rows.")
- In line one of the script, the table is retrieved from the test application and stored in the variable
table. - In line two, the table rows are retrieved into a list
- and stored in line three in the variable
rowCountwith the length of this list. - Line four finally writes this row count to the QF-Test run log.
Pseudo DOM API and accessing native Java component methods
To read the properties of web components, QF-Test offers its own DOM API which is documented in the manual and provides simple methods for accessing DOM properties and HTML elements.
This approach works for every supported technology but the method names may be different because they are technology-dependent. You will find information on this in the respective documentation. For applications with Java Swing, methods can be assessed directly.
When I now run the script, the number of table rows is written to the QF-Test run log, which we can see accordingly.
The QF-Test run context
Let’s go back to the script. You can see in line one and in line four that a variable rc is used there. This stands for the QF-Test run context and offers you options for interacting with QF-Test methods and scripts. In our case, the aim is to identify a graphical component, our table, and write a message to the QF-Test run log.
The run context also allows you to write your custom error messages to the run log or execute entire checks.
The script editor also offers auto-completion for rc. So you type rc., press Control+Space, and now you will see all supported methods and the corresponding documentation.
An example server script
A typical use case for a server script is to write a message or variable content into a file. You can see such a server script here now in the Jython scripting language:
value = rc.getStr("nameOfVehicle")
fh = open ("testfile.txt", 'w')
fh.write("Vehicle is : " + value)
fh.close()
- In line one, the QF-Test run context is assessed again and the content of a variable is determined which was previously set somewhere in the test run.
Outlook
Scripts and QF-Test allow you to extend your tests with any logic and simplify some complex tasks. However, scripts and QF-Test can do much more. Scripts allow you to develop so-called Resolvers that optimize QF-Tests component recognition for your application. Alternatively, you can use a TestRunListener to add additional logic to the test execution. In addition, QF-Test offers many other interfaces which you can learn more about in our detailed manual.
You have now learned the most important basics about scripting support in QF-Test. In the QF-Test Help menu, you will find further links to three available scripting languages and their documentation and tutorials. The QF-Test manual contains several chapters explaining scripts and their possible uses with many examples. Take advantage of this powerful feature to further advance your test automation.