Skip to main content

Other Test Components

Here are some other components that you can add to a test using the Composer. To access them, go to a Project > Test > Compose (aka Composer) > Click Add component (+ icon) in the Composer toolbar.

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
Value

| REQUIRED | STRING |

Examples#

Here's an example of how you could use a tag in the Compose tab.

tagComposer.jpg

You can also add tags to the test details screen when you create or edit a test.
Tag Component - create new test

Static tags will be displayed in your Tests list.
Tests tag.jpg

All tags, dynamic and static will mark the test execution documents. On your project Dashboard, you can filter events by tags.
projDashTag.png

Set (Variable)#

Allows you to set a variable for future uses in the test. For example, you can save a value retrieved from the response and use it in a subsequent call.

Parameters
Fields
Var

| REQUIRED | STRING |

Variable mode

| REQUIRED | STRING, DATA, or LANGUAGE |

Value (depends on ā€˜Variable mode = stringā€™)

| REQUIRED | DATA |

Data (depends on ā€˜Variable mode = dataā€™)

| REQUIRED | STRING |

Lang (depends on ā€˜Variable mode = languageā€™)

| REQUIRED | STRING |

Content (depends on ā€˜Variable mode = languageā€™)

| REQUIRED | STRING |

Examples#

Set var
Var: artistIdVariable mode: StringValue: _1.id
Set var
Var: sobjectsVariable mode: DataData: payload.findAll {it.name == ā€˜bananasā€™}
Set var
Var: queriesVariable mode: LanguageLang: JavaScriptContent: if (payload.id>100) return ā€˜furnitureā€™

Parse#

This component allows you to parse a string into structured data, using one of the available parsers.

Parameters
Fields
parseVar

| REQUIRED | STRING |

The name of the variable you want to parse.

Adapter

| REQUIRED | json, xml, etc. |

The parser to use

Parse component UI

Examples#

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

Parse component variable

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

Parse component test

Here are the results of the above test:

Parse component 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.

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}

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.jpg

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

flow_wait.jpg

In this example, the test will wait 1000 milliseconds before performing the GET request.

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
ID

| 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.


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:

Fact id: environment  label: The current environment  value: ${env}
screenshot.png

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
screenshot.png

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":

screenshot.png

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:

screenshot.png

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:

screenshot.png

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

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.

  1. First, we'll make a GET request to an endpoint.
    screenshot
  2. Next, we'll add a K/V Store component.
    component.png
  3. 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.
    screenshot.png
  4. In this case, we're setting the Key "prods" equal to products\[0\].name, which in this case evaluates to "Baseball Cap."
  5. 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.
    screenshot.png
  6. Finally, we'll add in a Comment component to ensure that the data was recovered successfully.
    screenshot.png
  7. When we run the test, we're presented with the following result:
    screenshot.png

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.

  1. 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.
    screenshot.png
  2. 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.
  3. 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.
    screenshot.png
  4. Finally, we're going to Load the modified data into the test from the K/V Store.
    screenshot.png
  5. When we run the test, we're presented with the following test report.
    screenshot.png

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!

  1. The first step is to introduce a Pop K/V Store component.
    screenshot.png

    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.
    screenshot.png

  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.
    screenshot.png

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.

note

Use "Set," "Push," and "Pop" to reset the timer. "Load" does not reset the timer.