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. All functions and test cases in the script have access to the arguments.
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"
You can pass arguments to a script using the following methods:
You use the GetArgs function to process arguments passed into a script. GetArgs returns a list of strings with each string being one of the passed arguments. Any test case or function in a script can call GetArgs to access the arguments.
The following test case prints a list of all the 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