Shipped: Step Variables

Picture of Fred Stevens-Smith
Fred Stevens-Smith, Monday January 27, 2014

This week we shipped something that I like to think of as a Swiss army knife for writing good tests. We call them Step Variables.

With front-end testing, you often want to use dynamic content. Perhaps you want to use real login credentials, or you want to test a number of different strings for your search functionality. Step variables are simple placeholders that display dynamic content in your steps, and persist throughout your test.

How do Step Variables work?

Like this:

Using step variables gif

When a tester does this test, {{ }} and {{ random.password }} are replaced with a random email address and a random password.

Let's look at a couple of examples.

1. Random Strings

Sometimes we want a tester to input a string and then check for the existence of that same string later. A good example is a sign up flow. We typically want the tester to sign up with a certain email address, and then check if that email address is displayed correctly later on.

This is an expanded version of the example above. Before step variables we would have had to either specify a static string to signup with and then test for, which would not work because each user email has to be unique, or we would have had to tell the tester to make up a string and remember it, which is error-prone. Step variables make it easy!

2. Users

When testing we often see customers using a single test login email and password. This is problematic because of how Rainforest works - we send several hundred testers to your site in parallel to get your tests done super quickly.

To avoid race conditions and other weirdness we recommend you add a custom step variable. This could be as simple as an array of email and password combinations, or you could create multiple step variables based on user permissions, eg. AdminUser, RegularUser, SuperUser.

This example will give each tester a unique set of credentials from the array of admin users.

Adding new step variables

Go to the Step Variables settings page to see your existing variables and add new ones.

Step variables adding interface

We've already found several weird and wonderful uses for Step Variables, and we're excited to see what you come up with!