【问题标题】:Testcafe introduce entry point for tests after authorizationTestcafe 授权后引入测试入口点
【发布时间】:2020-12-24 11:23:00
【问题描述】:

我有一个测试套件(夹具),其中包含用于测试咖啡馆的多项功能测试。它们看起来像这样:

fixture('Test suite')
  .page(login_url)
  .beforeEach(async (t) => {
    await t.maximizeWindow()
    await page.signIn('username', 'pass');
  });

test('Test case 1', async (t) => {
  await t.expect(page.title.textContent).eql('My Page');}
test('Test case 2', async (t) => {
  await do some other stuff}

这显然在每次测试之前浪费了很多时间,因为我们每次都需要登录。 如何登录一次,将该页面设置为入口点,然后从该页面开始每个测试?

【问题讨论】:

  • 只是一个注释来说明问题所在。首先,fixture 挂钩无法访问测试页面。这可以通过使用变量和条件来处理 beforeEach 挂钩中的某些代码仅执行一次。但真正的问题是,TestCafe 会在每次测试之前删除所有内容(缓存、cookie 等),如 here 所述。因此,只记录一次在 TestCafe 中是一个真正的麻烦。我删除了我的答案,因为它仅针对第一个问题提出了解决方法。

标签: javascript testing testcafe fixtures pageobjects


【解决方案1】:

您可以使用 TestCafe 角色机制仅登录一次。所有进一步的测试都不需要额外的身份验证。详情请看以下文章:https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html#user-roles

【讨论】:

    猜你喜欢
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-24
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 2015-06-13
    相关资源
    最近更新 更多