Defining variables at suite level

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 a test

A common use case for suite-level variables is to replace the starting URL of a test. You can, for example, use the variable ${environmentUrl} 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 ${environmentUrl} 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:

Go to a suite's settings
Go to a suite's settings

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 ${environmentUrl} variable will be replaced with the value https://frontendrobot.com/playground/todos/.

The variable is replaced at runtime
The variable is replaced at runtime

Running the same test within different suites

Let’s now suppose we want to run the same test on another environment. We want to replace the starting URL with that of the other environment. To do that we can create a new test suite called for example Env B, and add the tests we want to run on our new environment. Of course, for this to work all those tests should have a starting url set to the ${environmentUrl} 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 popup, 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 environmentUrl and assigning a value representing 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 based on the suite they will run from.

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.