使用testcafé,如何同时登录多个服务?
using testcafé, how to be logged into multiple services the same time?
我正在尝试使用 testcafé 通过 testcafé 的 role
-mechanism/concept 登录多个服务。我的测试需要同时登录多个服务(即他们不想在角色之间切换)。
根据本指南 (https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html),应该可以使用具有多个角色的 testcafé。但是,我的测试只能在角色之间切换(即它们 不是 同时登录多个服务)
引用上面的指南:
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.
以下是我完成上述目标的主要尝试,但 none 成功了。
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"
});
同时登录多个服务需要做什么?
testcafé 版本:1.8.8
浏览器:Chrome 84.0.4147.89 / macOS 10.15.5
用户角色会在应用时清除所有关联的 cookie,因此您将无法使用两个用户角色来完成此操作。
您可以创建一个在两个页面上执行登录的角色,或者使用第一个用户角色并从测试主体手动登录第二个用户。
我正在尝试使用 testcafé 通过 testcafé 的 role
-mechanism/concept 登录多个服务。我的测试需要同时登录多个服务(即他们不想在角色之间切换)。
根据本指南 (https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html),应该可以使用具有多个角色的 testcafé。但是,我的测试只能在角色之间切换(即它们 不是 同时登录多个服务)
引用上面的指南:
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.
以下是我完成上述目标的主要尝试,但 none 成功了。
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"
});
同时登录多个服务需要做什么?
testcafé 版本:1.8.8
浏览器:Chrome 84.0.4147.89 / macOS 10.15.5
用户角色会在应用时清除所有关联的 cookie,因此您将无法使用两个用户角色来完成此操作。
您可以创建一个在两个页面上执行登录的角色,或者使用第一个用户角色并从测试主体手动登录第二个用户。