Using Unique Credentials For Each Test Iteration

January 21, 2016

Often times when running a load test we need to authenticate as a user before performing actions. This could anything from a website that uses OAuth to a custom streaming service with its own protocol for authentication. Testable scripts support CSV data to solve this problem.

For this blog post we use the sample service /login endpoint to simulate testing with different users. The only valid credentials that this endpoint accepts is admin/admin.

Step 1: Create a Test Case

Make sure you sign up for a Testable account first. After logging in click the New Test Case button, give it a name, and specify the URL ( in our example).

Step 2: Upload CSV Data

Click Next and select Script as the scenario type. On the Data tab upload a CSV file with the following 3 rows of data:


In our script we will use one row from this file each time it executes. Testable gives us an iterator which cycles through the rows in the file across all global test iterations. The global iterator can even fail once all rows have been iterated over if you do not want to repeat credentials, but in our case we are happy to loop through the rows multiple times.

The code for our script will look as follows:

var dt ='credentials.csv'); {
    var credentials = { 
        hostname: '', 
        path: '/login', 
        method: 'POST'
    results(credentials.user).counter('count', 1, 'requests');

This code does the following:

  1. Gets the next row in the CSV file. Remember that the iterator is global across all concurrent clients.
  2. Build a credentials object using the row assigned to the scenario.
  3. Call POST and pass the credentials in the body.
  4. Increment a custom counter that keeps track of the number of requests per username.

You can try out your script by pressing the Run button in the upper right.

Step 3: Configure and Execute Test

After pressing Next we configure the load test using the following parameters that are well within the free account limit:

  • Concurrent Clients Per Region: 10
  • Iterations: 20
  • Regions: AWS N. Virginia, AWS Oregon, AWS Singapore
  • Ramp up: 60 seconds
  • Iteration Sleep: 1 second

Press Start Test and watch the results start to flow in.

That’s it! Read the upload data documentation for the full set of options.