在TestCafé中,我想在不同的浏览器中并行运行测试。每个会话应注册并使用不同的用户帐户登录。
我尝试使用before
钩子实现这一目标:
let user = null;
fixture("My fixture")
.page("http://localhost:8080")
.before(() => {
user = faker.internet.email();
});
test("login", async t => {
// using user in here
});
但是,此挂钩仅对所有浏览器执行一次,我需要针对每个浏览器运行该挂钩,以便每次可以使用不同的凭据。
这可行吗?
这是NPM脚本:
testcafe firefox,chrome,edge tests.js
答案 0 :(得分:4)
是的,您可以使用beforeEach
挂钩。
https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#test-hooks
答案 1 :(得分:3)
我重新考虑了此解决方案,并认为您可以在方案中使用TestCafe User Roles功能。您可以为不同的浏览器创建单独的角色,然后根据beforeEach
字符串在userAgent
挂钩中选择其中一个。这是example如何使用客户端功能获取userAgent
的方法。