Skip to main content

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.

Other Components

What You'll Need

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.tagComposer.jpgYou can also add tags to the test details screen when you create or edit a test.
Tag Component - create new testStatic tags will be displayed in your Tests list.
Tests tag.jpgAll tags, dynamic and static will mark the test execution documents. On your project Dashboard, you can filter events by tags.
project dashboard tag
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.

Set var component
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: StringThis 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. If it is a variable the engine will evaluate the variable value every time the test will be executed. Check out the example to learn more about this mode.Mode: DataUsing 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. To learn more about this mode, check out the example.Mode: LanguageThis 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.

  • 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 to check if all is correct (Body cannot be printed).

You can learn more about this mode by checking out the example.
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

Parse component UI

Examples

Set a variable (which will be a plain string) as a list of colors.Parse component variableNext, use the Comment component to see what happens if you print “colors[1]” before and after parsing it into JSON.Parse component testHere are the results of the above test:Parse component testBefore 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 the system 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:flow_stop.pngIf the statusCode is not 200, the test will be halted; none of the remaining assertions will be checked.flow_wait.pngIn 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., ${...}).

caution

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.


Learn how to improve the email notifications, disable the notifications and set the thresholds by checking the examples.
Code View Examples
- id: fact
identifier: environment
label: environment
value: ${env}

Call Snippet

note

Looking to create or update a snippet? See Snippets.

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.

warning

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.
    KeyValueSet.png
  • Load: recalls a value from the Key/Value store when provided with a key.
    KeyValueLoad.png
  • 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.
    KeyValuePush.png
  • Pop: removes a value from the end of an existent value of the datatype "Array" in the Key/Value store.
    KeyValuePop.png
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:

More Information