I have some tests that involve switching between different user roles to validate that they can (and can’t) access appropriate things in my web application.
I’ve noticed that when I try to run with concurrency via this command line:
testcafe chrome <filenames> -e -c 2
That they share a profile, and so if one test changes the logged in account using User Roles, the test in the other chrome instance also gets that login. And that sometimes based on timing results in my tests failing due to receiving the wrong thing. A test that is supposed to validate an admin can do something is now operating as a regular user, or vice versa.
For example, I have a toggle that is only available to roles with edit permission to switch between editing and viewing. This portion works in isolation:
await SignIn.as(UserRoles.training_reviewer_ht);
await Navigator.goToItem(t.ctx.courseId);
await t.wait(Waits.medium);
if (!(await Training.Selectors.viewCourseToggle.exists)) {
await t.debug(Training.Selectors.viewCourseToggle);
}
t.click(Training.Selectors.viewCourseToggle);
But sometimes in between signing in as the Reviewer (which has edit permissions) and loading the page, another test logs in with a user that does not have edit permissions, and I then hit the debug statement because the view toggle is not actually on the page.
Is there a way to make each of my concurrent instances isolated or each use a different empty chrome profile so my tests don’t interfere with each other when running concurrently?
Thomas Blight is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.