Test Script Runner scripts are simple text based files with the extension TSR. The language uses variables to store Integers, Doubles, Booleans, Results and Tester objects. Tester objects provide actions which result in Pass/Fail/Error verdicts. Each tester object has its own set of actions. A number of Tester objects have been built-in to Test Script Runner and you can add your own to interface with whatever you need to perform your testing.
To write a script please use the text editor of your choice as Test Script Runner does not provide any editing features. There are a vast array of text editors out there and you probably have a preferred one in any case. After editing the script simply press the Reload button to load the changes.
You can debug scripts by setting breakpoints, using the step option or selecting pause on error. All of these options will pause the execution to allow you to view the variables etc. to check what is going on.
Tester objects are created via the new keyword and removed via the delete keyword as with C++. Once a Tester Object has been created and assigned to a variable, any of its actions can be called via the dot operator. The actions associated with a tester are displayed in the GUI via the Help->Tester Documentation dialog.
Other language keywords are result, sprint, sscanf, include, if, then, else, endif, while, do, endwhile, function...endfunction and ignoreresult...endignoreresult. Most of these commands will be recognisable by programmers.
The ignoreresult...endignoreresult allows you to include test code that may fail but the result is of no significance to the overall script result. Simply place these two keywords around any script statements to ensure their failure is not recorded in the result of the script.
The function...endfunction commands allow you to add functions to the script. The syntax is function <function name> {statements} endfunction. To call the function from the script simply add <function name>(<parameters>). Within the function you can access the parameters via the variable matching the function name using the array syntax <function name>[0].
Comments are denoted by the # character. All characters till the end of the line are ignored but are included in the loaded script to aid the reading of the script by the user.
You can find example scripts showing how to use each of these at www.TestScriptRunner.com/examples.htm
#Set port number and baud rate
default AtPortSettings = "rs232",[6,115200]
#Create a Serial RS-232
#Tester Object
Var = new Serial (AtPortSettings [0])
#Open RS-232 port
Var.Open (AtPortSettings[1])
LoopCounter = 0
while LoopCounter < 10 do
#send at<CR> via serial line
Var.Send (“at\n”)
#Wait For up to 10 sec
# For OK response
Result “Phone responded” Var.WaitFor(10,”OK”)
#Decrement loop counter
LoopCounter--
Endwhile
#Close the serial port
Var.Close()
#Delete the Tester Object
delete Var
The script to the left shows how easy it is to create a script that will open RS-232 COM port 6 with a baud rate of 115200, then repeat the actions send at<CR> and waiting for the response OK ten times.
In the script the variable AtPortSettings is assigned the value "rs232",[6,115200] and this is then used in the new command and Open action for the RS-232 COM port. This demonstrates the ability to use variables as the parameters of action. In order to take into account the fact that the COM port assigned to a peripheral such as a mobile phone varies from PC to PC a system variable can be created instead via Admin->Set/Clear Variables menu.
The AtPortSettings variable also shows that a variable can be a multi-dimensional array. In this case it has two values and these could be accessed via the array operator []. In this case the port number would be AtPortSettings[1][0] and the baud rate AtPortSettings[1][1].
The Result keyword allows you to state that the result of a given script action etc. is of significance and to provide a string to describe what the result is. Result lines are included in the email result message should you turn on this feature.
You can use the include keyword to include a sub-script into your script. This allows you to avoid lots of duplication within your test scripts. An include statement has the form include“<filename>”.
At the end of the script all variables are deleted therefore should you forget to call delete the object will be freed by default. This would also occur if you managed to assign something else to a variable already assigned to a tester.
To view the format language definition go to Script Language Definition