运行 每个浏览器的挂钩之前
Run before hook for every browser
在 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
是的,您可以为此使用 beforeEach
挂钩。
https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#test-hooks
我重新考虑了这个解决方案,认为您可以使用 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 如何使用客户端函数获取 userAgent
。
在 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
是的,您可以为此使用 beforeEach
挂钩。
https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#test-hooks
我重新考虑了这个解决方案,认为您可以使用 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 如何使用客户端函数获取 userAgent
。