Use the following SenseTalk commands in Eggplant Functional to call other scripts or API tests.
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.
Run "Logout Procedure" //Calls a script named "Logout Procedure"
Run "Login", "SusanG76", "password123!@#" // Calls a script named "Login" with parameter values "SusanG76" and "password123!@#"
Read more about the run command in the SenseTalk Reference documentation.
If the other script is located in the same suite as the current script (or an associated helper suite), and its name begins with a letter and contains only letters, digits, and underscores, you can call it as a command in the current script. (You do not have to use the
Run command, just the name of the script you are calling, followed by any parameters.)
Login "SusanG76", "password123!@#"
If the script you are calling has a return, you can capture the return using
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
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
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.
If running Gherkin Features from the command line, any parameters passed in the command line call (including tests executed via Eggplant Manager) will take precedence over tags passed as parameters in a SenseTalk script.
RunFeature featureName, "@tag1,@orTag2 @andTag3", "@andTag4"
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.
RunFeature "FeatureTest1", "@important,@regression" // Runs FeatureTest1 but only elements within it that include either the @important tag or the @regression tag
RunFeature "FeatureTest1", "@important ~@regression" // Runs FeatureTest1 but only elements within it that include the @important tag and don't include the @regression tag
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
RunWithNewResults Command or Function
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.
As a function:
RunWithNewResults( scriptName )
Returns: A results property list. For more information, see
RunWithNewResults "Logout" // Calls a script named "Logout" and creates a separate set of results for it
RunWithNewResults "Login", "SusanG76", "password123!@#" // Calls a script named "Login" with parameter values "SusanG76" and "password123!@#" and creates a separate set of results for it
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
You can use
RunWithNewResults and its result property list to write sophisticated primary control scripts or custom reporting, with actions based on the properties of the result. For example, you can call one script if the previous script succeeds, and call a different script if it fails.
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
set ResultFile to ResourcePath("myTestResults.csv") // Stores the file path of the myTestResults resource file in a variable
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
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.
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.
log api() // Logs the full list of returned values from the most recent API test
put api().statusCode into RetStatus // Puts the server status code from the last API test into the RetStatus variable
put api() into res
put res.responseHeaders into headers
assert that "content-length" of headers is 339
assert that res.responseBody contains "Bad Request"
assert that res.statusCode is 200