Parameters and Results
Messages are identified by a single word — the message name — but they can also include additional information in the form of parameters. Parameters are values that are passed to commands or functions. These commands or functions may be custom handlers, which can either be located within the calling script, or in another script or helper suite. For more information on declaring handlers and receiving parameters, see Handlers
Two Ways to Pass Parameters: Sequential and Named
There are two ways to pass parameters when calling a command or function: sequentially, or by name. Sequential parameters are passed in sequence, as you might expect. Named parameters are passed as a property list of key:value pairs, with each key being used to match the name of a parameter on the receiving end. The two methods of passing parameters can also be combined.
The calling command or function can be in the same or a different script from the handler being called. The call is often in a separate script, which is helpful for the modularization of tests. A test structure might include a primary script with a number of different calls in it out to other scripts containing a wide variety of handlers that execute different tasks.
If you are interested in pre-defining a default value for any parameter the receiving handler might expect, see Default Parameter Values. For information on writing handlers to receive parameters, see Handlers.
Sequential Parameters
Passing Sequential Parameters
To pass parameters sequentially, simply list the parameter values after the command name separated by commas, or enclosed in parentheses after the function name when calling a function (there are some other variations for functions when only a single parameter value is being passed — see Calling Functions).
The command put "Hello, World!" sends the string “Hello, World!” as a single parameter along with the put
message. To send more than one parameter, just list them with commas in between.
Example: Passing Sequential Parameters with a Command
This example passes three parameters to the doSomethingImportant
command as sequential parameters: the number 31
, the text green
, and the variable style
:
doSomethingImportant 31, "green", style
Command parameters should not be enclosed in parentheses (unless the intent is to pass a list as a single parameter).
Example: Passing Sequential Parameters with a Function
To include parameters with a function call message, list them inside the parentheses after the function name:
put roundToNearest(salary/12, 0.01) into monthlyPayTothePenny
Example: Supplying an Empty Parameter
Two commas in a row imply an empty parameter, and a final comma at the end of a list is ignored, so the following passes three parameters ("silverBar"
, ""
, and 16
):
get verifyQuantity("silverBar",,16,)