I've been experimenting with testcafé in an effort to simultaneously log into multiple services using the role mechanism. My goal is to have my tests logged into multiple services concurrently without switching between roles.
While a guide on this topic () suggests that it's possible to achieve this with testcafé, I've only been able to switch between roles, rather than being logged into multiple services simultaneously.
The guide states:
For instance, assume that you switch to a role that logs you in on website A. After you switch to this role, you log in to website B in test code. TestCafe adds a new cookie to the role branch. If you switch to a different role and then back to the initial role in the same test run, you will be logged to both website A and B. If you switch to this role in a different test, you will be logged in to website A only.
I've made several attempts to achieve the desired outcome as described above, but unfortunately, none of them have been successful.
import { Role } from "testcafe";
const role1 = Role("https://some-website.org", async t => {
await t
.typeText("input[type=text]", "")
.typeText("input[type=password]", "")
.click(".button");
});
const role2 = Role("https:/another-website.org", async t => {
await t
.typeText("input[type=text]", "")
.typeText("input[type=password]", "")
.click(".button");
});
fixture `Getting Started`;
test("test 1", async t => {
await t.useRole(role1);
// now logged in as "role1"
await t.useRole(role2);
// now logged in as "role2"
// ... but not logged in as "role1" and "role2"
});
test("test 2", async t => {
await t
.useRole(role1) // now logged in as "role1"
.useRole(role2); // now logged in as "role2"
// ... but not logged in as "role1" and "role2"
});
test("test 3", async t => {
await t
.useRole(role1) // now logged in as "role1"
.useRole(role2) // now logged in as "role2"
.useRole(role1); // now logged in as "role1"
// ... but not logged in as "role1" and "role2"
});
What steps should I take to ensure that I am logged into multiple services simultaneously?
testcafé version: 1.8.8
browser: Chrome 84.0.4147.89 / macOS 10.15.5