You are here: Chapter 4: Writing and Configuring Test Scripts > Creating Structure: Steps and Scripts

Creating Structure: Steps and Scripts

This topic deals with T-Plan Robot Enterprise features and it is not applicable to the legacy VNCRobot Version 1.3 or 2.0 projects.

Tests in the software engineering industry usually consist of test cases. A test case is either a single logical step or a sequence of steps aimed at testing of a feature, functionality or correct behaviour of an application. An expected result is usually defined. Test cases are often referred to as test scripts and they are usually collected to test suites.

T-Plan Robot Enterprise supports test cases (called "scripts" in T-Plan terminology) and steps. It is expected that test suites are managed on a higher level outside of T-Plan Robot, such as through the test management tools like T-Plan Professional. The scripting language contains two commands, Script and Step:

Script and step structures are reflected both in HTML and XML reports created through the Report command. The XML serves as test report viewable through a web browser as well as a source of test result data suitable for export to 3rd party applications. Reporting functionality will be discussed in details later on in this tutorial.

As an example let's add the script and step structure to the calculator example from previous topic. We suppose that it automates two test cases: verify calculation of "5+5" (script 1) and "10*5" (script 2). For simplicity the steps always returns "pass" because we do not verify the result in any way. Verification of application behaviour is covered extensively in the next chapter of this tutorial.

Script specification
calculator.tpr (Windows version)
Script  1:
  1. Start calculator
  2. Calculate "5+5"
  3. Close calculator
Expected Result:
  1. App starts/stops as expected.
  2. Produces the result of 10.

Script 2:
  1. Start calculator
  2. Calculate "10*5"
  3. Close calculator
Expected Result:
  1. App starts/stops as expected.
  2. Produces the result of 50.

# Define the OS variable because the library expects it.
Var OS="Windows"

# Include the library.
Include calculator-lib. tpr

# Define XML report.
Report calculator-{OS}.xml desc="Calculator testing on {OS}."

# Calculate "5+5" and"10*5".
Script 1 name="Calculate 5+5"
calculate "5+5"

name="Calculate 10*5"
calculate "10*5"

# Variable initialization based on target OS.
# If the "OS" variable is not initialized, default to Windows.
Var RUN_BOX_KEY="Windows+r"

# Both systems close applications through Alt+F4
Var CLOSE_KEY="Alt+F4"

if ("{OS}" == "Linux") {
  Var RUN_BOX_KEY="Alt+F2"
  Var CALCULATOR_CMD="gnome-calculator"

# Start an application through the Run box.
# Params: {1} ... application start command
procedure startApp {
  Press "{RUN_BOX_KEY}" wait=5s
  Typeline "{1}" wait=4s

# Start the calculator, type the expression, save
# a screenshot to a uniquely named file and close it.
# Params: {1} ... numeric expression to type, for ex. "5+5"
procedure calculate {

  startApp "{CALCULATOR_CMD}"
  Step "Start" instruct="Start calculator" result="pass"
  Typeline "{1}" wait=2s
  Screenshot calculator_{_CURTIME}.jpg desc="Result of {1}"
  Step "Calculate" instruct="Calculate {1}" result="pass"
  Press "{CLOSE_KEY}" wait=2s
  Step "End" instruct="Close calculator" result="pass"

To see the resulting XML report look at calculator-Windows.xml (Windows XP only) in our examples. To get the raw XML data simply select "View Page Source" in your web browser or save the report to a file and open it in a text editor.


12 December 2014

Copyright © T-Plan Ltd.

Version 1.0