GUI test exeutions have to be configured for various purposes. Test engineers might want to configure a test in order to use specific test data as input to the Application Under Test. Or the Application Under Test itself has to be executed with a variation of program arguments.
While many tests are self-contained, there are cases in which the configuration is done externally, for example through a scheduler that drives the test executions, such as a Continuous Integration server. In these cases, the
squishrunner executable can be used to pass arguments to the test scripts. The test script may access those arguments and adopt its behaviour based on the values.
Passing Script Arguments to squishrunner
squishrunner option that supports this is called
--scriptargs. It has to be specified at the very end of the complete
squishrunner command call. All arguments which are specified after
--scriptargs are passed to the executed script.
The following example shows a
squishrunner call that passes two arguments to the test script:
./squishrunner --testsuite /path/to/suite --testcase tst_case1 --reportgen xml3.2,/path/to/result --scriptargs argument1 argument2
Accessing these arguments in the test script depends on the scripting language that is used. Assuming that Python is used, we need to use the
sys module which provides a list of command line arguments through the
import sys def main(): test.log('Number of arguments:' + str(len(sys.argv)) + 'arguments.') test.log('Argument List: ' + str(sys.argv))
When executing the snippet above, you will notice that the first field,
argv, holds the name of the script itself. This is common practice in many scripting languages. The first argument we pass to the
squishrunner --scriptargs option can be accessed through
Configuring an Example Application through Script Arguments
Let’s get back to one of the initial examples: we want to pass a program argument to configure the AUT. Let’s assume this argument is called
--nolauncher --autoconnect. The command for such an application startup could look like this:
./exampleApplication --nolauncher --autoconnect
To pass these arguments to the test script, the
squishrunner call would look like this:
./squishrunner --testsuite /path/to/suite --testcase tst_case1 --reportgen xml3.2,/Users/flo/tmp/result --scriptargs --nolauncher --autoconnect
Finally, we need to access the arguments in the test script itself, and pass it to the
import names import sys def main(): autCommand = "exampleApplication" for i in range(1, len(sys.argv)): autCommand = autCommand + " " + sys.argv[i] startApplication(autCommand) ...