QA Wolf logo

QA Wolf



Use Environment Variables

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.

Create an Environment Variable

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.

Manage environment variables from editor
Manage environment variables from 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.

Create variable button

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 secret todo.

Create an environment variable

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.

Saved environment variable

Click "Done" to close the popup.

Use an Environment Variable

We can now use our TODO_TEXT environment variable in our test. Environment variables are accessible under process.env.

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 TODO_TEXT (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.

Use environment variable in editor

If we run our test, it will now create a todo with the value secret todo, which comes from our environment variable.

Run a test with an environment variable

Assign Environment to Group

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.

Assign an environment to a group

Manage Environments

You can create, rename, and delete environments in QA Wolf. To manage environments, click the "Edit environments" button in the dropdown.

Edit environments

Create an environment by pressing the "Create environment" button. Hover over an existing environment to reveal options to edit or delete.

Edit environments popup