Script and API Calling
Use the following SenseTalk commands in
On this page:
Run Command
Behavior: Calls another script as if the script were a command. If an error or exception occurs within the called script, the calling script will fail as well. If there is an uncaught exception in the called script, execution will stop.
Parameters: One script name and any parameters values that the called script can receive.
Syntax:
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Example:
Run "Logout Procedure" //Calls a script named "Logout Procedure"
Example:
Run "Login", "SusanG76", "password123!@#" // Calls a script named "Login" with parameter values "SusanG76" and "password123!@#"
Example:
Login "SusanG76", "password123!@#"
Example:
Run "ValidateOutput" // Calls a script named "ValidateOutput" with contents 'return "Test passed!"'
put the result into FormOutput // Stores the string "Test passed!" in a variable
RunFeature Command
Behavior: This command calls a Gherkin Feature (.feature file) as if the Feature were a command. This command lets you trigger Features from SenseTalk scripts. When the Feature executes, it generates its own results file, similarly to running a script with RunWithNewResults.
Parameters: One Feature name (required); optionally, you can include any number of tags. Use a tilde (~) in front of a tag to exclude it rather than include it.
Syntax:
RunFeature "featureName", "@tag1,@orTag2 @andTag3", "@andTag4"
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
You can include multiple tags within one set of quotes. Tags separated by a comma follow OR logic. Tags separated by a space follow AND logic. If both OR and AND conditions exist, the OR always takes precedence and is evaluated first. Joining a parameter within a separate set of quotes forces an AND condition.
Example:
RunFeature FeatureTest1
Example:
RunFeature "FeatureTest1", "@important,@regression" // Runs FeatureTest1 but only elements within it that include either the @important tag or the @regression tag
Example:
RunFeature "FeatureTest1", "@important ~@regression" // Runs FeatureTest1 but only elements within it that include the @important tag and don't include the @regression tag
Example:
RunFeature "AccountingApp" "@over,@rcvd" "@billing" // The elements from AccountingApp that run need to have the @billing tag and either the @over tag or the @rcvd tag
Related:
RunWithNewResults Command
Behavior: Runs another script that generates its own results log, as opposed to scripts called with the Run command, which are logged as part of the calling script. The RunWithNewResults command returns a results property list similar to the ScriptResults function. For more information, see ScriptResults Function and the Results Properties. If the called script fails, the calling script does not automatically fail or raise an exception. You can script this behavior based on the returned Status property from the results property list.
Parameters: One script name, and any parameters it requires to run.
Syntax:
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Returns: A results property list. For more information, see ScriptResults() Function.
Example:
RunWithNewResults "Logout" // Calls a script named "Logout" and creates a separate set of results for it
Example:
RunWithNewResults "Login", "SusanG76", "password123!@#" // Calls a script named "Login" with parameter values "SusanG76" and "password123!@#" and creates a separate set of results for it
Example:
put ["Member.txt", "Administrator.txt"] into UserEnvironmentsList // Stores a list of strings representing file names in a variable called UserEnvironmentsList
// Stores a list of strings representing file names in a variable called UserEnvironmentsList
repeat with each item of UserEnvironmentsList // Iterates with each item of the list of strings in UserEnvironmentsList
RunWithNewResults "ConfigureEnvironment", it // Calls a script named "ConfigureEnvironment" and passes the string to the script using the "it" variable
end repeat
Example:
RunWithNewResults "Login"
if the result's status is "failure" then // Checks the value of the status property to see if it is failure
LogError "Login failed. Performing cleanup."
CleanupScript // Runs a script named CleanupScript in the event that the status is failure
end if
Example:
set ResultFile to ResourcePath("myTestResults.csv") // Stores the file path of the myTestResults resource file in a variable
RunWithNewResults "Login"
set myResult to the result // Stores the result of the RunWithNewResults into a variable named myResult
put "Login" &comma & myResult.runDate & comma & myResult.status & CRLF after file ResultFile // Writes a new line out to the end of the resource file, based on the contents of myResult
API Function
Behavior: Lets you access all the properties of an API test, including both the request and response. This function returns information about the last API test that was run.
Parameters: None
Syntax:
api()
the api
Syntax definitions for language elements follow these formatting guidelines:
- boldface: Indicates words and characters that must be typed exactly
- italic: Indicates expressions or other variable elements
- {} (curly braces): Indicate optional elements.
- [] (square brackets) separated by | (vertical pipes): Indicate alternative options where one or the other can be used, but not both.
Example syntax:
In this example, "open file" is required and must be typed exactly. "fileName" is a variable element; it is the path to and name of the file being opened. The following expression is optional and indicates why the file is being opened. If this expression is added, "for" is required and must be typed exactly. One of the following must be included, but only one, and they also must be typed exactly: "reading", "writing", "readwrite", "appending", or "updating".
Returns: A property list including the following values:
- authenticationType: Returns the authentication type used for the request.
- httpMethod: Returns the request type (e.g., GET, POST).
- mimeType: Returns the MIME type used in the response.
- oauth1Token: Returns the token if OAuth 1.0 is the authentication method; otherwise, empty.
- password: Returns a redacted string if a password is used for authentication; otherwise, empty.
- requestBody: Returns the body content of the request for POST, PUT, and PATCH requests; otherwise, empty.
- requestBodyFormat: Returns the Body Format type selected in the Request Body section. For requests that don't have body content, the returned value is the most recently chosen Body Format type.
- requestHeaders: Returns any headers entered in the Request Headers section as key/value pairs; otherwise, empty.
- responseBody: Returns the response data from the server.
- responseCookies: Returns details about cookies in the response, if any.
- responseHeaders: Returns the response headers as key/value pairs.
- responseTime: Returns the response time from the request from the server, in seconds.
- statusCode: Returns the status code received from the server (e.g., 200, 404).
- url: Returns the request URL.
- userName: Returns the username for authentication (if used); otherwise, empty.
Example:
log api() // Logs the full list of returned values from the most recent API test
Example:
put api().statusCode into RetStatus // Puts the server status code from the last API test into the RetStatus variable
Example:
put api() into res
put res.keys
put res.responseHeaders.archive
put res.responseHeaders into headers
assert that "content-length" of headers is 339
assert that res.responseBody contains "
assert that res.statusCode is 200
Related: