Test suite variables

In Frontend Robot you can define a variable during a test with the Assign Variable instruction or pre-define a set of variables to apply to all the tests in a suite. Let’s see how we can accomplish the latter.

Note: A variable assigned within a test will always override the same suite-level variable.

Common use case: changing the starting URL of all tests

A common use case for suite-level variables is to replace the starting URL of a test. You can, for example, use the variable ${env_url} in the initial Go To URL instruction. This way you can run the same test on your staging environment or your production environment by simply creating two test suites; one assigning the staging URL to the ${env_url} variable the other assigning the production URL to the same variable.

Using a variable in a `Go to URL` field
Using a variable in a `Go to URL` field

Defining suite-level variables

To define suite-level variables we first need to navigate to a suite’s settings, then scroll to the Variables section. To create a new variable, set the name of the variable, then its value and click Add.

Adding a new variable
Adding a new variable

Now, when the test is run from within the suite, the ${env_url} variable will be replaced with the value https://frontendrobot.com/playground/todos/.

The variable is replaced at runtime and the test succeeded
The variable is replaced at runtime and the test succeeded

Running the same test within different suites

Let’s now suppose we want to run the same test on another environment, for example on a staging or a testing environment. We want to replace the starting URL with that of the other environment. To do that we create a new test suite, which we will call Env B, and import the tests we want to run on the new environment. Of course, for this to work all those tests should have a starting url set to the ${env_url} variable.

Let’s start by creating a new test suite:

Creating a new suite
Creating a new suite

Once we are in the new suite click on Add existing to add some tests from other test suites:

Adding existing tests
Adding existing tests

From the dialog, select the tests you want to import from the other test suites and then click Add selected.

Selecting the tests to import
Selecting the tests to import

OK, now that the tests are imported you can create a new suite variable named env_url and assign it a value for the new environment. For our example we can just set it to a TodoMVC implemented with another framework, let’s say http://todomvc.com/examples/vanillajs/. To create the variable you can follow the instructions at the beginning of this article.

Done. Now we have two test suites sharing one or more tests that will run on different environments.

Questions?

We're always happy to help with test creation or other questions you might have! Search our documentation, contact support by email or on chat, or connect with our sales team.