Run before hook for every browser

Viewed 164

In TestCafé, I want to run a test in different browsers in parallel. Each session should sign up and log in with a different user account.

I tried to achieve this with the before hook:

let user = null;

fixture("My fixture")
  .page("http://localhost:8080")
  .before(() => {
    user = faker.internet.email();
  });

test("login", async t => {
  // using user in here
});

However, this hook is just executed once for all browsers, I need to run it for each browser so that I can have different credentials each time.

Is this feasible?

This is the NPM script:

testcafe firefox,chrome,edge tests.js

2 Answers

I reconsidered this solution and think that you could use the TestCafe User Roles feature in your scenario. You can create separate roles for different browsers and then choose one of them in the beforeEach hook based on the userAgent string. Here is an example how to obtain the userAgent using a client function.

Related