Other Test Components
Here are some other components that you can add to a test using the Composer. This guide describes each component and shows you how to add them to tests. To learn how to access the components and create a test using the Composer see Writing API Tests with the Composer.

What You'll Need
- A Sauce Labs account (Log in or sign up for a free trial license).
- Familiarity with the API Testing Composer.
Tag
The Tag component within the Composer enables you to dynamically tag the resulting document of a test execution. You can add different tags based on dynamic events happening during the test execution, such as a certain value retrieved in the payload. You can assign multiple tags to each test by adding more 'tag' components to it.
This is different from the tags applied when you first create the test. That feature enables you to search for that tag(s) filter in your Project Tests tab or Dashboard tab.
Parameters
Fields | |
Tag | | REQUIRED | STRING | |
Examples
Here's an example of how you could use a tag in the Composer tab.

You can also add tags to the test details screen when you create or edit a test.
Static tags will be displayed in your Tests list.
All tags, dynamic and static will mark the test execution documents. On your project Dashboard, you can filter events by tags.
Code View Example
- id: tag
value: Production
Set (Variable)
In Sauce Labs API Testing you can create variables in several different ways by using SET (variable)
. This component has different modes that allow you to create variables in different ways, such as String
, Data
, and Language
.

Parameters
Fields | |
Variable | | REQUIRED | STRING | |
Mode | | REQUIRED | STRING, DATA, or LANGUAGE | |
Value (depends on ‘Mode = String’) | | REQUIRED | DATA | |
Data (depends on ‘Mode = Data’) | | REQUIRED | DATA | |
Lang (depends on ‘Mode = Language’) | | REQUIRED | JAVASCRIPT or TEMPLATE | |
Body (depends on ‘Mode = Language’) | | REQUIRED | DATA | |
Mode: String
This mode generates a String variable, which can be a static value or a variable taken from the response payload. If it is a static value you just have to write it and the engine will take it as is.
Consider the following example:

- id: set
var: product
mode: string
value: t-shirt
In the above example the variable product
will always have the value t-shirt
.
If you want to make it dynamic and let the engine evaluate the value every time the test will be executed, you have to write it in ${...} brackets.
Consider the following response payload and let’s say it has been stored in the payload
variable:
{
"id": 1,
"name": "Baseball Cap",
"price": 29.99,
"category": "1",
"description": "This is product 1!",
"quantity": 5,
"imageURL": "http://image.com",
"color": [
"blue",
"yellow"
],
"createdAt": "2021-11-28T21:58:43.461Z",
"updatedAt": "2021-11-28T21:58:43.461Z"
}
If you write the following:

- id: set
var: product
mode: string
value: ${payload.name}
The engine will evaluate the variable value every time the test will be executed. In the above scenario the variable product
will contain the value Baseball Cap
but if the response is the following:
{
"id": 2,
"name": "Long Sleeve Shirt",
"price": 39.99,
"category": "1",
"description": "This is product 2!",
"quantity": 7,
"imageURL": "http://image.com",
"color": [
"blue",
"yellow",
"red"
],
"createdAt": "2021-11-28T21:58:43.461Z",
"updatedAt": "2021-11-28T21:58:43.461Z"
}
The value will be Long Sleeve Shirt
, without changing your test.
Mode: Data
Using this mode, the variable will be evaluated (like the Expression field), therefore the variable type can be everything. The variable type will depend on the object being evaluated. In the Data field, you need to enter a single line expression that returns a value.
For example, you can create a new array in this way:

- id: set
var: product
mode: object
object: '["Bluetooth Headphones","Long Sleeve Shirt","Baseball Cap"]'
Then, you can iterate over it using the each
component or you can invoke a specific item using ${product[1]}
where the number inside the square brackets identifies the position of the item you want to reach out, starting from 0.
Now, let's consider the example below and imagine we have the JSON payload stored in the payload
variable:
[
{
"id": 1,
"name": "Baseball Cap",
"price": 29.99,
"category": "1",
"description": "This is product 1!",
"quantity": 5,
"imageURL": "http://image.com",
"color": [
"blue",
"yellow"
],
"createdAt": "2021-11-28T21:58:43.461Z",
"updatedAt": "2021-11-28T21:58:43.461Z"
},
{
"id": 2,
"name": "Long Sleeve Shirt",
"price": 39.99,
"category": "1",
"description": "This is product 2!",
"quantity": 7,
"imageURL": "http://image.com",
"color": [
"blue",
"yellow",
"red"
],
"createdAt": "2021-11-28T21:58:43.461Z",
"updatedAt": "2021-11-28T21:58:43.461Z"
},
{
"id": 3,
"name": "Bluetooth Headphones",
"price": 49.99,
"category": "1",
"description": "This is product 3!",
"quantity": 50,
"imageURL": "http://image.com",
"color": [
"green",
"yellow"
],
"createdAt": "2021-11-28T21:58:43.462Z",
"updatedAt": "2021-11-28T21:58:43.462Z"
}
]
If you write the following:

- id: set
var: product
mode: object
object: payload.filter(it=>it.name=='Bluetooth Headphones')
It will return the following object:
{
"id": 3,
"name": "Bluetooth Headphones",
"price": 49.99,
"category": "1",
"description": "This is product 3!",
"quantity": 50,
"imageURL": "http://image.com",
"color": [
"green",
"yellow"
],
"createdAt": "2021-11-28T21:58:43.462Z",
"updatedAt": "2021-11-28T21:58:43.462Z"
}
Mode: Language
This is the most advanced way to create your variables. There are two different options available: Javascript
and Template
.
Lang: Javascript
In this mode you can create your variable by writing a Javascript script in the Body
field. It can be a complete script with variable declarations or loops.
For example, you have a JWT token stored in the token
variable and we need to decode it and return the JSON payload it was generated from:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NTgyMzY1NjgsImV4cCI6MTY4OTc3MjU2OCwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJOYW1lIjoiSm9obiIsIlN1cm5hbWUiOiJEb2UiLCJFbWFpbCI6ImpvaG4uZG9lQGV4YW1wbGUuY29tIiwiUm9sZSI6WyJNYW5hZ2VyIiwiUHJvamVjdCBBZG1pbmlzdHJhdG9yIl19.DN7vKPlHkAy1hwYOYpUKDwkV0yD-KS2pdoc76aKPhm8
To achieve this, you need to write the following script inside the Body
field:
var pieces = token.split('.')
var b64payload = pieces[1]
var decoded = Buffer.from(b64payload, 'base64').toString()
var json = JSON.parse(decoded)
return json

That’s producing the following JSON:
{
"iat": 1658236568,
"exp": 1689772568,
"aud": "www.example.com",
"sub": "john.doe@example.com",
"Name": "John",
"Surname": "Doe",
"Email": "john.doe@example.com",
"Role": [
"Manager",
"Project Administrator"
]
}
Then, you can retrieve all the keys as jsonData.iat
where jsonData
is the variable name you entered in the Variable
field.
Lang: Template
In this mode you can create your own template in the same way as it is done for Request Body, the advantage here is that you can print the variable in order to check if all is correct (Body cannot be printed).
For example, if you need to add a new product in your database, you can create the body for the (PUT) request and paste the Body in the Body
field and print it in a Comment
.
{
"id": 4,
"name": "T-Shirt",
"price": ${price},
"category": "1",
"description": "This is product ${id}!",
"quantity": 5,
"imageURL": "http://image.com",
"color": ["red", "green"],
"createdAt": "${D.format (D.nowMillis(), 'yyyy-MM-DD')}",
"updatedAt": "${D.format (D.nowMillis(), 'yyyy-MM-DD')}T${D.format(D.nowMillis(), 'HH:mm:ssz')}"
}

Code View Examples
- id: set
var: product
mode: string
value: t-shirt
- id: set
var: product
mode: string
value: ${payload.name}
- id: set
var: product
mode: object
object: '["Bluetooth Headphones","Long Sleeve Shirt","Baseball Cap"]'
- id: set
var: product
mode: object
object: payload.filter(it=>it.name=='Bluetooth Headphones')
- id: set
var: jsonData
mode: lang
lang: javascript
body: |-
var pieces = token.split('.')
var b64payload = pieces[1]
var decoded = Buffer.from(b64payload,'base64').toString()
var json = JSON.parse(decoded)
return json
- id: set
var: new_product
mode: lang
lang: template
body: >-
{
"id": 4,
"name": "T-Shirt",
"price": ${price},
"category": "1",
"description": "This is product ${id}!",
"quantity": 5,
"imageURL": "http://image.com",
"color": ["red", "green"],
"createdAt": "${D.format (D.nowMillis(), 'yyyy-MM-DD')}",
"updatedAt": "${D.format (D.nowMillis(), 'yyyy-MM-DD')}T${D.format(D.nowMillis(), 'HH:mm:ssz')}"
}
Parse
This component allows you to parse a string into structured data, using one of the available parsers.
Parameters
Fields | |
Variable | | REQUIRED | STRING | The name of the variable you want to parse. |
Adapter | | REQUIRED | json, xml, etc. | The parser to use |

Examples
I have set a variable (which will be a plain string), in this case I have a list of colors.

Next, we can use the comment component to see what happens if I print “colors[1]” before and after parsing it into JSON.

Here are the results of the above test:

As you can see before parsing the string, the test will consider the variable colors
as one big string so colors[1]
will print “ as that is the second character in the string. After parsing the string into JSON we can traverse through the variable as a JSON, so colors[1]
will print the second element in the JSON array blue.
Code View Examples
- id: parse
var: varName
adapter: json
- id: parse
var: fileName
adapter: csv
Comment
This assertion allows you to print out (in test reports) information. It can have two sorts of values, as described below.
Parameters
There are no parameters -- text only.
Examples
The first is a normal string value. An example of that would be to explain what a specific WHEN loop is being used for. Similar to when you write comments in code.
This is a comment
The second is useful for test debugging and analysis. You can pass variables into the comments. An example use of this would be to print out the product ID being used in the current loop of a test.
The value of the ID is ${payload.id}
Code View Example
- id: comment
text: This is a comment
- id: comment
text: The value of the ID is ${payload.id}
Flow
This component allows you to pause or stop a test entirely.
Parameters
Fields | |
Command | | REQUIRED | 'stop', 'wait' | This parameter defines the action you want to take. 'Stop' will stop the test. 'Wait' will pause the test for a number of milliseconds defined in the 'Value' parameter. |
Value | | REQUIRED | INTEGER | Depends on 'Command = wait'. The number of milliseconds you want to pause the test for. |
Examples
This component is especially useful when combined with the If
component. See the examples below:

If the statusCode is not 200
, the test will be halted; none of the remaining assertions will be checked.

In this example, the test will wait 1000 milliseconds before performing the GET
request.
Code View Examples
- id: flow
command: stop
- id: flow
command: wait
value: 1000
Fact
The Fact component enables you to add information (facts) about the nature of the test execution, along with static or dynamic data. It's used to control the behavior of Email notifications, which (if enabled) alert you to test failures.
Test activity is tracked using test ID number. This may not work if you're testing in multiple environments (i.e., production, staging, QA), as an incident could be environment-specific. When a Fact component is added to a test, it will inform our system which environment the execution relates to so that the incident signature will carry the environment as well.
Parameters
Fields | |
Identifier | | REQUIRED | STRING | Should be unique within the test. |
Label | | REQUIRED | To provide an understanding of the Fact. |
Value | | REQUIRED | STRING | String value that supports the template language (i.e., |
The Fact component should be set as high up in the test as possible. If the test fails before it reaches the Fact, then it will not be set.
Examples/Uses Cases
Setting Alert Environments
Assume that in the variable scope of your test, you have a variable called env that contains your environment string (production, staging, qa etc.).
By configuring a Fact in the following way, you can add the environment value to the incident signature:
- id: fact
identifier: environment
label: environment
value: ${env}

From this moment on, the signature of the incident will be id_of_the_test
+ value_of_environment
.
For example, you will receive start/end incidents for test123
in the production environment, and start/end incidents for test123
in the staging environment, as separate flow of events.
You can use anything as a value of the environment, such as domain names and IDs.
Disabling Email Notifications
A second use case is disabling email notifications for the test from within the test:
Fact id: disable_alerts
label: whatever you want here
value: true

You can use logic within the test to set the Fact component and use that to alter the email notification.
As an example, you could say "IF the env is development, then disable emails for this test":

Setting Email Notification Thresholds
Another use-case of the fact component is set an email alert threshold. If you want a test to fail more than once before an email is sent, a Fact called mail_threshold
can be set in the test:

This means the test will need to fail twice in a row before an email alert is sent.
Given that this can be configured within the test, it offers all the flexibility provided by conditional statements, such as an IF condition on the environment the test is running upon:

Code View Examples
- id: fact
identifier: environment
label: environment
value: ${env}
- id: fact
identifier: disable_alerts
label: alerts disabled
value: 'true'
- id: fact
identifier: mail_threshold
label: multi failure
value: '2'
Snippets
When you save a snippet from the Composer, it will be saved in the project Vault. While you cannot save a snippet from the Composer to the Company Vault, you can export there using the import/export feature (see screenshot below).
Create a Snippet
- Open a project.
- Open a test.
- Click the first component you want to include.
- Hold down the
Ctrl + Shift
keys and click the last component you want to include. This will highlight your snippet selection. - Click Save Snippet.
- Give the snippet a name.
- Click Save Snippet.


Updating Snippet
- Open a project.
- In the left panel, click Vault, then click Code Snippets.
- Click any of the fields and begin typing to edit the details.
- Click Save.
Call Snippet
Creates a Call component that will invoke the snippet. If the snippet changes, all the tests containing the Call component to that snippet will inherit the changes.
Paste Snippet
This allows you to paste the entire snippet inside the test, which you can then edit as needed. The pasted components will lose any reference to the original snippet.
K/V Store
The Key/Value store allows you to create temporary key/value pairs that can be accessed across different tests. The Key/Value store is accessed via the Key/Value Store Component.
These Key/Value pairs are temporary. They expire after 24 hours has elapsed since the last update to the value itself.
Methods
The Key/Value Store component has four methods available for use:
- Set: creates a new key/value pair in the Key/Value store. The value is entered in the Data field.
- Load: recalls a value from the Key/Value store when provided with a key.
- Push: adds a value to the end of an existent value of the datatype "Array" in the Key/Value store. If no such key exists, it will create a new array containing the passed in value. The passed in value is entered in the Data field.
- Pop: removes a value from the end of an existent value of the datatype "Array" in the Key/Value store.
Code View Examples
- id: kv
key:
action: load
var:
- id: kv
key: prods
action: load
var: kvprods
- id: kv
key:
action: pop
var:
- id: kv
key:
action: set
object:
- id: kv
key: adasd
action: set
object: products[0].name
- id: kv
key: prods
action: set
object: '[products[0].color]'
- id: kv
key:
action: push
object:
Basic Workflow
Let's take a look at how this workflow works in a practical setting. The first example will be a simple set and retrieve of a value in the Key/Value Store.
- First, we'll make a
GET
request to an endpoint. - Next, we'll add a K/V Store component.
- This first K/V Store component (we're going to incorporate several) is going to set the Key/Value pair in the Store, so we're going to use Set
- In this case, we're setting the Key prods equal to
products[0].name
, which in this case evaluates to Baseball Cap. - Next, we're going to retrieve this Key/Value pair from the store with the Load method. In the K/V Store Load component, we're going to assign the retrieved value to the variable
kvprods.
- Finally, we'll add in a Comment component to ensure that the data was recovered successfully.
- When we run the test, we're presented with the following result:
Success!
Push/Pop Workflow
Next, we're going to take a look at how Push and Pop work. Push and Pop are both array methods and behave as they normally do outside of this context. Push will append a value to the end of an array. Pop will remove the last value in an array.
First, we're going to use Push. It should be noted that Pop works similarly but with the opposite result. Pop also assigns the removed value to a variable which can be used in the context of the test, but can no longer be accessed from the Key/Value Store. We'll discuss this further when we take a look at Pop.
- First, we're going to send a
GET
request and assign a key in the Key/Value Store to a value from the response body. In this case, we're going to use Color, which is an array. - Next, we're going to Load and Comment this key. We're doing that so we can actually see the change on the test report at the end of this workflow.
- The next step is to Push the new data on to the end of the existing array. In this case, we're pushing the integer 999 onto the prods array.
- Finally, we're going to Load the modified data into the test from the K/V Store.
- When we run the test, we're presented with the following test report.
The comments show us clearly that we have pushed the number 999 onto the array stored in the key prods.
Now, we've added something to the array. Let's remove it with Pop!
- The first step is to introduce a Pop K/V Store component.
We provide the Pop component with the name of the key from the Key/Value Store, and the name of the variable we'd like to assign the popped value to. Remember, Pop removes the last value in an array and returns the value itself. In this case, we're going to assign it to a variable called Popped. 2. Next, we're going to recall the modified key from the Key/Value Store. Then, we're going to Comment both the recalled Key/Value Store value AND the previously popped value. 3. Review the Test Report, where you can see the full workflow, showing that we first assigned an array to the Key/Value Store with **Set**, then added to that array with **Push**, and then removed the added value with **Pop**. Each time we made a change, we used **Load** to retrieve an updated value from the Key/Value Store.
The last two comments show the final state of the array in the Key/Value Store and the popped value itself. The popped value will only be available within the scope of this test run. The array in the Key/Value Store will remain retrievable and until 24 hours after it's most recent modification.
Use Set, Push, and Pop to reset the timer. Load does not reset the timer.