You can pass arguments to a script. For example, you might want to pass in the number of iterations to perform or the name of a data file.
testcase MyTest1(STRING arg1, STRING arg2)
Print("{arg1} {arg2}")
testcase MyTest2() LIST OF STRING args = GetArgs() ListPrint(args)
All arguments are passed in as strings, separated by spaces, such as: Bob Emily Craig
If an argument is more than one word, enclose it with quotation marks. For example, the following passes in three arguments: "Bob H" "Emily M" "Craig J"
The following test case prints a list of all the implicitly passed arguments:
testcase ProcessArgs ( ) LIST OF STRING lsArgs lsArgs = GetArgs ( ) ListPrint (lsArgs) //You can also process the arguments individually. The following test case prints the second argument passed: testcase ProcessSecondArg ( ) LIST OF STRING lsArgs lsArgs = GetArgs ( ) Print (lsArgs[2]) //The following testcase adds the first two arguments: testcase AddArgs () LIST OF STRING lsArgs lsArgs = GetArgs ( ) NUMBER nArgSum nArgSum = Val (lsArgs[1]) + Val (lsArgs[2]) Print (nArgSum)
You can use the Val function to convert the arguments, which are always passed as strings, into numbers.
When the arguments script 10 20 30 are passed to the scr_args.t script, the test result is:
Script scr_args.t (10, 20, 30) - Passed Passed: 1 test (100%) Failed: 0 tests (0%) Totals: 1 test, 0 errors, 0 warnings Testcase AddArgs - Passed 30