Using variables and secrets
Variables and secrets are a way to manage dynamic values in your tests. This is especially useful to store values that are used across multiple tests, such as API key or user credentials.
In this guide, we'll continue editing the test we created in the previous guide.
Your first variable
In our previous test, we left on the login page.
Now, we would like to fill the email and password fields.
Let's use the Fill Input action to fill the email field.
As a description, we'll write "The email input". This is enough for the AI to find the email input field.
For the value to assign, instead of putting the email directly in the test, we'll use a variable to store it.
By clicking on the x (variable) icon, you can open the variable popover.
Give your variable a name, description and value. In our example we'll name it user_email
and set the value to tutorial@magicinspector.com
.
The description only helps you remember what the variable is for, it's not used for anything else.
Then click on the Save button.
Congratulations, you just created your first variable!
This variables is now reusable in all your tests and will be replaced by its value at runtime automatically.
Your first secret
Now, we would like to do the same thing for the password.
However, passwords are very sensitive information and should not be stored in plain text in your tests.
So instead of using a variable, we'll use a secret.
Secrets are very similar to variables but with some major differences:
- Secrets are encrypted using AES-256 algorithm in our database
- Secrets won't be exposed in plain text or stored in your logs
- Secrets will never leave the Magic Inspector infrastructure
- Secrets will never be sent to any third-party services
To create a secret, let's repeat the same process as for the variable but this time we'll choose the Secret type.
Now we created our secret, let's use it in a Fill Input instruction.
As a description, we'll write "The password input".
For the value to assign, we'll use the secret we just created.
Congratulations, you've just created your first secret!
Let's wrap everything up
Now our authentication flow is almost complete, let's simply add a Click Element instruction to click on the login button and run our test.
The test will now run and pass with your variable and secrets, congratulations!
It's also worth nothing that the password value will be marked as REDACTED in the logs, since it's a secret so it can't be exposed.
What's next?
You now know how to use variables and secrets to store and reuse values in your tests.
In the next sections, we'll see how you can leverage reusable tests to create more complex scenarios.