Create a Test
Run Tests on a Schedule
Run Tests on Vercel Deployment
Run Tests on Netlify Deployment
Run Tests on Heroku Deployment
Run Tests on Render Deployment
Run Tests with API
Run Tests with CLI
Invite Team Members
Use Environment Variables
Reuse Helper Code
Receive an Email
Call an API
Get a Value
How QA Wolf Picks Selectors
Environment variables are secret values that you can use in your test code. Because they are encrypted, they are useful for storing sensitive values like passwords.
Environment variables can also be used to change the behavior of your test by group. For example, you may want to write a test that goes to one URL for staging and a different URL for production.
In this tutorial, we'll learn how use environment variables in our tests.
Environments are groups of environment variables. You can create, rename, and delete environments from the test editor and from the dashboard.
Let's create an environment if you don't have one already. In our example, we'll create an environment called "Staging".
Open the environments popup by clicking the "Environments" button in the sidebar of the dashboard, or the configure button in the bottom left corner of the test editor.
Create an environment by clicking the "Create environment" button on the left side of the popup.
Type the environment name in the input and press enter to save your environment.
You can rename and delete environments by hovering over them and clicking the options button.
Now that we have an environment, let's add some variables to it.
Click the "Create variable" button in the right side of the environments popup to create a variable.
Enter the variable name and value into the form. We'll name our varaiable
TODO_TEXT and give it a value of
secret todo. Click "Save" to save your variable.
Your variable will be encrypted and saved. You can edit and delete environment variables by hovering over them and clicking the relevant button.
Click "Done" to close the popup.
We can now use our
TODO_TEXT environment variable in our test. Environment variables are accessible under
First, open your test in the editor. Make sure your desired environment is selected in the bottom left corner of the test editor.
In our example, we'll replace a hard-coded todo value with the value saved as
secret todo). We'll change this line of code:
await page.fill('[placeholder="What needs to be done?"]', "todo");
To this line of code:
await page.fill('[placeholder="What needs to be done?"]',process.env.TODO_TEXT);
In the code editor, we can delete the existing todo value (
"todo") and replace it with
process.env.TODO_TEXT. You'll notice as you type
process.env. that your environment variables will be shown as suggestions.
If we run our test, it will now create a todo with the value
secret todo, which comes from our environment variable.
Environments can be assigned to triggers in QA Wolf. This means that when tests runs are created by the trigger, they will have access to the variables in the assigned environment.
To add an environment to a trigger, open the triggers popup.
Edit the trigger so that your desired environment is selected.