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 use environment variables in our QA Wolf test.
Environments are collections of environment variables in QA Wolf. Learn more about managing environments here.
You can edit the variables in an environment by clicking on the configure button next to the environment name. You can do this from the test editor or from the dashboard.
Clicking on the configure button opens a popup where you can manage environment variables. In this tutorial, we'll add a variable to the Production environment.
To create an environment variable, click on the "Create variable" button at the bottom of the popup.
Provide the name of the variable in the create form. In our example, we name our variable
TODO_TEXT and give it a value of
After pressing the "Save" button, the environment variable will be saved. If you hover over it, you will see options to edit or delete it.
Click "Done" to close the popup.
We can now use our
TODO_TEXT environment variable in our test. Environment variables are accessible under
First, make sure you are viewing a test in the editor to update the code. 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(".new-todo", "todo");
To this line of code:
await page.fill(".new-todo", 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.
Each group of tests in QA Wolf can be assigned an environment. This means that when this group runs, it will use the variables specified in the assigned environment.
Go to the dashboard and make sure the group you want to modify is selected.
Open the environments dropdown at the top of the dashboard. Click on the environment you want to assign to the group. In our example, we'll assign the Production environment to the All Tests group.
You can create, rename, and delete environments in QA Wolf. To manage environments, click the "Edit environments" button in the dropdown.
Create an environment by pressing the "Create environment" button. Hover over an existing environment to reveal options to edit or delete.