Variables
Variables enable you to run and maintain tests efficiently in any of the following situations:
- you work with multiple development environments
- you have multiple tests that use the same value in multiple form fields or assertions
- you want to test forms that require users to enter random and unique data, ex. registration with an email address
- you want to run the same tests with different form input, ex. testing product searching against various search queries or testing different zip-codes
Variables are dynamic pieces of text that you can use in your tests. Use variables in tests by entering their name in curly brackets to place a variable in any text field in the test steps ex.
{{myCustomVariable}}
Variables are good for storing:
- Fragments of URL addresses like domains, subdomains, hostnames, etc.
- Email addresses
- Input values like product names, brands, phone numbers, ZIP codes, etc.

Example: variable "hostname" used in an URL

Example: definition of variable "hostname" in the variables tab
Variables do not have to be simple text assignments. Some built-in variables are different each time you run the test for example
{{timestamp}}
or generate random values like {{testRunId}}
. You can also write your own javascript variables - functions that return a value that is calculated every time you use the variable.
This is the most basic type of variable. Go to the "Variables" tab and click "New variable". Add a name and value for your variable.
Use a variable name in curly brackets to place a variable in any text field in the test steps. You can combine variables with normal text, for example
{{hostname}}/v1/index.html

Example: a variable used in "Go to url" action
You can use variables in other types of actions, such as typing text in a form, assertions, and even in CSS selectors.

Use variables in selectors, assertions, etc.
Use BugBug's pre-defined set of variables to handle your complex testing scenarios. Here are some examples of what you can do with built-in variables
Built-in variable name | Type | Description | Usage example |
---|---|---|---|
Text | The current id of the running test (UUID format). | You want to have a new random unique value for one specific test run, for example you want to test user sign-up and then log in. | |
Text | The current id of the test (UUID format). | You want to test add/edit/remove operations in one test, for example, add a product and then remove the same product with a name Test Product {{testId}} | |
Text | The current id of the suite (if the test is running from a suite, UUID format). | You want to have a new, random unique value that is the same across all the test runs in one suite. | |
Text | The current run mode for the test ("local" or "server"). | You want to have different input or assertion value when the test is run on server. | |
randomNameFixed | Text | Random name that remains unchanged during the test run (8 letters). | You want to have a new, random uniqe name that is the same across all the test and used multiple time |
Text | The current id of the schedule (if the test has been started via a schedule, UUID format). | You want to have a new, random unique value that is the same across all schedule run. | |
Text | The current Unix Time in milliseconds (int format, e.g.: 1645710937798). | You want to know when your test runs or use it similar to randomNumber | |
Text | Random number that remains unchanged during the test run (10 digits). | If you want to edit an element, find it later in test steps and use it or remove it. | |
Text | The current profile name for the test. Default: "Default". | If you want to enter a production/test URL depending on the profile, test runs | |
Text | The current suite name for the test (if the test is running from a suite). | If you want to create an email that inform you about suit name that was run | |
Text | The current test name. | You can mix it with timestamp to create a new subscription notification test. |
Built-in variables also give you access to generators of random numbers and names that you can use right away in your tests.

Currently, there is no way to use variables during the recording. You can't type variables when recording tests.
First, record the steps and then edit them manually. Edit the step and replace the text with the variable name in curly brackets.
Upcoming improvement! We are working hard to enable this feature in the future and allow you to store and enter variables directly during the recording.
Test case: as a user, I go to the homepage and click "sign up" button. I enter my email and password. I receive a verification email. I click the link. I use previous email and password to log in.
We're going to use variables to solve a number of problems
- How to get a unique random email address
- How to receive the email with the authorization link
- How to use previously generated unique email and password in the login form
Register a new account in an email provider that supports plus aliasing or sub-addressing ex. Outlook or iCloud mail.
Important! Don't use Gmail as BugBug extension will fail in the Gmail app because of a bug caused by Chromium
Let's assume you registered such an email
[email protected]
Your emails may be at first classified as "junk mail", but later Outlook may just put them in your inbox and organize them into a conversation. To prevent this unpredictable behavior you need to change a few switches in the Outlook settings
Add BugBug email to safe addresses to prevent junk email classification

Disable the conversation view in Outlook settings

Disable the Focused inbox
.png?alt=media&token=5a7eeb14-2ff6-4efb-8a90-a2d49a667c70)
Create a new test and start recording. When you're about to enter the registered email address, remember to use the plus aliasing and add a random text after the "+" symbol for example
[email protected]
We're going to replace this suffix later with a variable!
During the recording, open a new tab and access your email inbox. Use your standard email address without the
+12345
part in the email log-in form.Find the email with the authorization link.
Don't forget to check the junk email folder! To prevent that we recommend that you add BugBug email to "safe emails" in Outlook settings.
Important! Make sure you click the subject line of the email! BugBug needs to always open the most recent email, so your selector here needs to click the first email with a specific subject line, for example
//SPAN[normalize-space(text())="
Finish your sign-up"]
.png?alt=media&token=b0d3ff18-e4fd-42a1-be0d-e700382f761f)
Now just click the Button with the authorization link and continue recording.
If your verification link is shown directly as a string, this string will be different every time. BugBug will record a selector that matches exactly this string, for example //A[normalize-space(text())="
https://
acmecorp.com/#/activate
?key=60f0ae29-542a-4418-8529-41a01bf22fcc"]In such case, you may need to manually update your selector after the recording so that it only checks if the text contains the beginning of the verification URL, for example
//*[contains(text(), "https://
acmecorp.com/#/activate")
In the login form to your app, remember to again use the email address with the plus alias
[email protected]
Now finish the recording. We now need to replace the recorded texts with variables manually.
If you run the test without using variables, it will fail because you will get a validation "This email already exists".
We need to have a unique email address every time we run this test.
In the test find all the steps that use
[email protected]
and replace it with acmeautomation+{{testRunId}}@outlook.com

Every time you run the test, you will see that a new unique email address is typed in the registration and login fields.
You will see a computed value in the step details.

Computed value will appear below the field after a test run
Profiles are your own presets for different variable values. You can run tests or suites with profiles to override your default variables to a specific value. This is especially useful if you work with multiple development environments.
Important To see the profile section in the test, you need to have at least 2 profiles.

You can quickly swap the profile in the menu near the "Run" button. This menu will not appear if you only have one default profile.

To add, remove and edit profiles go to the "Variables" tab

Override variables in the profile settings. Leave an empty field to keep the default value.
- 1.Create a profile in the "Variables" tab
- 2.Go to test editing
- 3.Swap profiles before running the test in the menu near the "Run" button
Important! Profiles selection is not saved in the test. If you run the test from the tests list, we will ask you to select a profile.
Tip! Your tests should pass on all profiles. Don't create tests that only work in one profile.
You can have multiple suites and each suite can run your tests with a specific profile. For example, you create suites for "Production smoke tests" and "Staging all tests". Each suite will have different sets of tests that are going to run on different profiles with different variables.
- 1.Go to "Suites" and select a suite to edit
- 2.Choose with which profile this suite will run
Important! This suite will always run with this profile. Profiles selection is saved in the suite settings.

Let's assume you work with 3 environments: production, stage, and local. Both are exactly the same, but they have different URL addresses. You want to sometimes run the test on production and sometimes on staging.
Environment | URL |
---|---|
Production | acme.com |
Staging | stage.acme.com |
Local | localhost:3000 |
Prepare the variables and profiles
- 1.Create a variable named
hostname
with default valuehttps://acme.com
- 2.Create 2 profiles named
Staging
andLocal
- 3.Override the hostname variable in the profile Staging for
https://stage.acme.com
- 4.Override the hostname variable in the profile
Local
forhttps://localhost:3000
- 1.In the tests, find your steps with
Go to url
action - 2.Replace the
acme.com
with{{hostname}}
.
Tip: you can also combine the curly brackets with the rest of the URL for example
{{hostname}}/registration
or app.{{hostname}}

Use BugBug CLI to integrate with your build pipelines and run tests with variables that you can adjust to multiple environments.
If you run tests or suites from the command line, you can override each variable or profile with parameters, for example,
--variable val1=value
and --profile=profileName
. Read more in the CLI documentation.
Javascript variables allow you to compute dynamic values every time the variable is used in a test.
- getting data from API, for example, SMS codes, authorization magic links
- mathematical calculations such as adding, subtracting, multiplying, etc.
- generating unique strings that need to meet specific validation criteria such as social security numbers, postal codes
- values that are different depending on conditions, for example, if your app shows a different text during night and daytime
- 1.Go to the "Variables" tab and click "New variable"
- 2.Change the variable type to "Custom JavaScript"
- 3.Enter a JavaScript function that will be executed every time this variable is used in the test
Important! Remember that your function needs to have a
return
statement - it needs to return a specific value.
Return a simple string value
async function(variables) {
let firstName = "John";
let lastName = "Smith";
return firstName + lastName;
}
Return a different value when the day of the week is Sunday
async function(variables) {
const d = new Date();
let day = d.getDay();
if (day === '7') {
return "Delivery in 48 hours"
} else {
return "Delivery in 24 hours"
}
}
Your custom JS variable can also read your other variables. The
variables
argument stores all the built-in variables and your custom variables. If you run a custom javascript step with a function console.log(variables)
you will get such an output in the console: {
hostname: "https://marmelab.com/react-admin-demo/"
profileName: "Default"
runMode: "local"
scheduleId: null //only for scheduled runs
scheduleName: null //only for scheduled runs
startDemoURL: "https://marmelab.com/react-admin-demo/"
suiteId: "54bd4384-ad9c-4e83-946f-111392ed0a82"
suiteName: "All tests"
suiteRunId: "18e1e3c3-ec2a-45c9-b817-8f48a56a0807"
testId: "37e64599-31a9-4707-9fed-a64cdec24294"
testName: "Test"
testRunId: "6498c9bd-81a5-412f-a275-2c7f1cfc4d45"
timestamp: 1665667075470
username: "demo"
}
You can use this to operate on the variables, combine them, calculate, etc.
async function(variables) {
return variables.firstName + variables.lastName
}
async function(variables) {
return variables.userEmail + variables.testRunId
}
async function(variables) {
return variables.userHeightInCentimeters + 20;
}
Important! Variables are calculated immediately before a step is executed. If you want to calculate variable only once per test, use
localStorage
to cache the result and then access it with custom javascript steps.Important! Other Custom JavaScript variables are not available in the
variables
object. This is impossible because you can't specify the order in which the JS variables are calculated or control the dependencies. See the localStorage
workaround below.If you want to access a variable that was already calculated in a previous step, use
localStorage
. - 1.At the end of the function in the first variable, store the result in
localStorage
.
async function(variables) {
let name = variables.firstName + variables.lastName;
localStorage.setItem('bugbugUserName', name);
return name;
}
2. At the beginning of the next variable get the value from
localStorage
.async function(variables) {
let name = localStorage.getItem('bugbugUserName', name);
if (name === 'Carl') {
...
}
}