Creating and Using Suite Variables

On the Eggplant Functional Settings tab, you can define suite variables, a special user-defined type of predefined variable. Suite variables are accessible to any script in the suite as well as to API testing by using SenseTalk's merge formatting. You can access the Settings tab by clicking the Settings button at the lower left in the Eggplant Functional Suite window.

New feature: Suite variables are available in Eggplant Functional 17.2 and later.

Variable Scope

The scope of suite variables is considered local. (See Variables in SenseTalk for explanation of different variable scopes.) However, because you define them for the suite, they can have a value at the start of a script run or handler so that you don't have to assign an initial value. You can overwrite the value by using the variable during a script run without changing the default, which returns at the start of the next handler.

Within SenseTalk, suite variables are stored in the suiteVariables global property. Therefore, it is possible to change the default value of a suite variable within a script run by accessing it through the global property. Because suite variables might be accessed from multiple scripts or API tests, you should be careful about updating a value in this way and do so only when you know which contexts you're changing.

Creating Suite Variables

Suite variables are essentially key/value pairs, with a variable name (key) and the value you assign for the variable. You can create suite variables in the Suite Variables section of the Settings tab.

The Suite Variables section of the Settings tab in Eggplant Functional

The Suite Variables section of the Settings tab in Eggplant Functional

To create a new suite variable:

  1. Click Add.
  2. Enter the variable name in the Key field. Be sure to use a name that is unique and clearly identifies the variable you're defining. For instance, if you typically use a name such as myVar in your scripts, you probably don't want to use that as the name for a suite variable.
  3. Enter the value for this variable in the Value field.

Suite variables are saved automatically. You can add as many suite variables here as you need.

The Suite Variables section in Eggplant Functional with defined variables displayed

The Suite Variables section in Eggplant Functional with defined variables displayed

You can edit existing suite variables in the Suite Variables section by clicking in the Key or Value field for the variable you want to edit, then updating the information.

Note: Although you can change the key name of an existing suite variable, it is not recommended. Changing the name here doesn't change it in scripts or other places where you might already reference this suite variable. Therefore, changing the key name could lead to unexpected results.

To delete a suite variable, click the Delete row button on the right side of the variable you want to remove. Deleting the variable does not remove references to the variable that you might have included in scripts or other places, but the variable no longer has a predefined value.

Working with the Global Property

You can also create or update suite variables directly through the suiteVariables global property within a SenseTalk script.

set the suitevariables to (baseURL:"http://examples.com")

In the example above, the value of baseURL is updated to http://examples.com. If the variable baseURL didn't already exist, it would be created and the value assigned. The following example provides the same result:

set the suitevariables.baseURL to "http://examples.com"

You can update or create multiple suite variables at once by using the following syntax:

set the suitevariables to (usr3:"giles",usr4:"dawn",usr5:"xander")

Updating the global property also adds or changes values in the Suite Variables section of the Settings tab. However, if the Settings tab is open in the Suite window when you make the update, you need to close and reopen it to see the change.

For a complete definition of the global property, see the suiteVariables. For more information about working with global properties, see Local and Global Properties in SenseTalk.

Using Suite Variables

You can access suite variables in SenseTalk scripts by calling the key name as a variable:

put usr4 into currentUser // puts the value of suite variable "usr4" (as stored in "the suiteVariables" property) into the new variable "currentUser"

log currentUser // logs "currentUser", which contains the username for usr4

You can also use SenseTalk's merge() function to access suite variables in more complex but useful constructions. For example:

put merge("My base URL is currently [[baseURL]]") // Pulls the value from the suite variable "baseURL"

// Displays: My base URL is currently http://chicago.publicserver.com

Note the double square brackets ([[ and ]]) that surround the suite variable name in the example above. The merge() function uses these delimiters to evaluate what should be substituted. In this case, the suite variable key is replaced with its value.

There are other options you can use with the merge() function in your scripts. For complete information, see merge() Function.

Suite Variables with API Tests

In the API Test Editor view, you can use the double square brackets method to merge or substitute your suite variables as well. For example, if you have multiple tests that make requests to the same basic URL, you could use a suite variable in the address bar for the request:

The address bar in the Eggplant Functional API Test Editor showing suite variable substitution

In the example above, the base URL for the request is supplied by the suite variable, and the port number and additional parameters are entered for the specific test.

Within the API Test Editor, you can use suite variable substitution in the address bar, in the Parameters section, in the Authentication section, and in the Headers section. The API Scripts section lets you create SenseTalk script steps, so you can access suite variables here in the same way you do in other SenseTalk scripts. You can also use the merge format with suite variables in the Request Body section for POST, PUT, and PATCH requests.

 

This topic was last updated on June 21, 2019, at 02:49:49 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2019 Eggplant