Rayrun
← Back to Discord Forum

How to create and use a pool of users that can be used by tests

Hi all,

In a new automation project, I have a bunch of email address's that I can use to create users against. I can't use randomly made up email addresses as they have to be known to the backend.

Right now, for the purpose of getting something up and running quickly, I have a number of those uses hard-coded into the tests where I need a new user. This if fine for the moment until these tests are run on the CI server as the playwright.config.ts is set to have a maxium of 2 retries.

If a test has already used one of the emails up when creating a user as part of a test and then that test fails at some point after that, the retry will then fail both times because the user has already been created with said email address.

So I need some way to manage a pool of users, whereby each test that needs one, can take it from/off the pool and use it. I am assuming in a CI environment with multiple workers that a race condition is possible, so probably need some kind of locking when removing/adding users in that pool of users.

Has anyone got any tips, tricks, ideas on how to achieve this?

This thread is trying to answer question "How to manage a pool of users for an automation project where each test requires a new user, especially when tests are run on the CI server?"

6 replies

Think this is all on you. Might suggest standing up a simple end point that your tests can call via a rest command "GiveMeNextEmail( requestInfo) " your requestinfo might provide some info. Other than this think you are all on your own.

I solved this type of scenario with the server app that returns unique user data for each request. https://profile.qaplayground.dev/0e65f597-56e9-40a2-822c-f4d6ad5dfd43

So essentially you are saying you have a fixed set of users? (based on email addresses)

Personally I'd lock the users to a specific set of spec files then so there is minimal chance of crosstalk

Why don’t you read csv data which comes as config?

Thanks for the replies all.

@whitemc2 Thanks, I will take a look at that.

@captainjetski That is pretty much what I have done as my first approach, but the only issue with this is if a test fails after the user has been added to the AUT, when CI retries, it will immediately fail when attempting to add the user again. I would personally prefer to run with retries turned off but other people want it on.

I did have a tidy up of the user, so if it was successfully added in the test, I would remove the user in AterEach hook (I am using one test per spec file), but as far as I can see, if the test fails, the AfterEach hook does not execute.....I think I need to go back and double check that is that doesn't sound right to me.....

@jaratlanta I could do that and will certainly give it a try. When multiple workers are in use, could there be a possible race condition when I go to update the CSV saying the user has been used?

Yes it will be problem if you multiple writes. It’s best to generate before you run if possible

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].