Ask a Flooder 17: How do I use UNIQUE test data on Element? [Video]

Scripting user logins using real browsers with Flood Element

In this video, I talk about how to ensure that Flood Element uses unique test data, using the example of a customer wanting to script unique logins for his application.


Hi everyone, Nicole van der Hoeven here again back with another Ask a Flooder, and this week's question is a follow-up question from last week. That user had previously asked about test data in Flood Element. This week he's asking: "How do I ensure that Flood Element uses unique test data?"

So this user is actually trying to script a login for an application. He has a list of usernames and corresponding passwords that he wants to use. He's already set both of these up in a CSV file, and he's also set up the Element script in the same way that I outline in my previous video. However, this user is seeing errors in the test due to the application not allowing a given user account to be used simultaneously in two or more devices. The problem is that the way that he's set it up is that he has Element running on multiple nodes, and each node has the chance to pick the same user account.

So how do you make sure that it's a unique 1:1 ratio for an instance of Element and a user account in the CSV file? If you haven't already watched the previous week's video, you should pause this, watch that, and then come back here, so it makes a little more sense because the script that I'm using is building on what we already did in the previous week.

Let's talk about the differences between this script and the previous week's.

First, I'm declaring a global variable here called `globalBrowserID`. The idea is to create a unique and globally identifiable string that I can attach to every account in the CSV file.

const globalBrowserID = ENV.FLOOD_GRID_INDEX + '_' + ENV.FLOOD_GRID_NODE_SEQUENCE_ID + '_' + ENV.BROWSER_ID.toString()

The global browser ID consists of three parts:
- The first is a grid index, which is a number assigned to every grid, and it's also globally unique. So if there are three grids being used in the test, then the grid indexes would be 0, 1, and 2.
- The second one is a grid node sequence ID, and this is unique within the grid. The node sequence ID is a number that is assigned to every node in a single grid.
- The last one is a browser ID. The browser ID is a number assigned to an instance of Element running on a single node.

These are all zero-based, so the very first instance of Element running on the very first node and on the very first grid in the entire test would be `0_0_0`.

We're going to have to modify our CSV file to make use of this browser ID. So whereas the user previously had username and password, I've added an ID column. From then, these will have to be sequential. So `0_0_0`, `0_0_1...` And `0_0_1` would be the second instance of Element running still on the first node, on the first grid. And you can make as many of these as you need.


I've also modified the interface `UserData` to describe the fields in the CSV file. So there's `id`, `username`, and `password`, and I've defined them all as strings.

TestData.fromCSV<UserData>('users_multiplegrids.csv').filter((line, index, browserID) => === globalBrowserID)

This line is telling Element to take this data file with this filename and filter it based on the line, the index, and the browserID such that `id` is equal to the browser ID. So what happens here is that Element will take the global browser ID, which let's say is `0_0_0` for the very first one. It'll then take that `0_0_0` and look at the CSV file for anything in the ID field that has the value `0_0_0`. And then it will continue to use the rest of that line.

I've also made the CSV file circular just because that's always a good practice to get into.

And as always, I think it's a great idea to debug this, especially when you're dealing with multiple grids and multiple nodes on that grid.

   step('Print to console', async (browser: Browser, data: UserData) => {
       console.log('global browser ID: ', globalBrowserID, '| user: ', `${data.username}`, ' | password: ', `${data.password}`)

I've also added the username and password here, just in case we need to verify the state that that user is in.

So let's run the test. Since we're just running this locally, we'll see that the first value indeed is `0_0_0`, and the user we're selecting is `user1` and `password1`, which lines up with the username and password values corresponding to `0_0_0` in the CSV file.

I hope that helped, and until next time, happy flooding!

Download the full script and the data file to follow along.

Start load testing now

It only takes 30 seconds to create an account, and get access to our free-tier to begin load testing without any risk.