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.
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.
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.
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/
.
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:
Once we are in the new suite click on Add existing to add some tests from other test suites:
From the dialog, select the tests you want to import from the other test suites and then click Add selected.
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.