Dynamic Variables

A dynamic variable is a variable which value is determined when the scenario is run. Apart from other tasks, you can effectively use them for storing authorization tokens or newly created entities. The mechanism consists of two parts - variable assignment and dynamic variables themselves.

Variable assignment

You can assign a part of your request to a dynamic variable. For now you can do it in RequestStep nodes only. To illustrate this, let's create a request, that adds a new post and save its id into a dynamic variable.

So let's create the request and send it. Send a POST request to https://testmace-stage.herokuapp.com/posts with {"title":"Our cool post!"} in its body. The RequestStep node will look like this:

The RequestStep node after sending a POST request

Open the parsed response and click on the id parameter to see the dynamic variables assignment dialog:

The id parameter context menu

Choose Assign to variable. You'll see the variable assignment dialog:

The dynamic variable assignment dialog

You can see the following interface parts.

  1. The path to the $requestwhere the value is stored.

  2. The drop-down list with parents, that you can assign the dynamic variable to.

  3. The current value at the given path.

  4. The dynamic variable name.

Let's create a variable named id at this node.

After assignment you can find the dynamic variable in the list of the chosen node (RequestStep) dynamic variables. See the list in the variables dialog on the Dynamic variables tab:

The RequestStep node dynamic variables list

Using Dynamic Variables

All dynamic variables available for the chosen node are stored in the $dynamicVar variable. For example, to access the id variable you should write $dynamicVar.id. Just like with other variables, dynamic variables can be inherited from parents or overridden in child elements.