为每个浏览器挂机前运行

时间:2019-10-17 12:46:38

标签: testing browser automation hook testcafe

在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

2 个答案:

答案 0 :(得分:4)

答案 1 :(得分:3)

我重新考虑了此解决方案,并认为您可以在方案中使用TestCafe User Roles功能。您可以为不同的浏览器创建单独的角色,然后根据beforeEach字符串在userAgent挂钩中选择其中一个。这是example如何使用客户端功能获取userAgent的方法。