【问题标题】:How to fix assertion error using playwright?如何使用剧作家修复断言错误?
【发布时间】:2022-08-09 23:37:56
【问题描述】:

我正在使用剧作家进行 e2e 测试以检查电子邮件是否存在,并且在我运行测试时它说: \"已完成测试流程,状态通过\"

但它告诉我测试失败了,因为我有断言错误而不是因为我做错了什么

这是我的一段代码:

const fillEmail = async (page: Page, value: string) =>
    await page.fill(\"email-for-test\", value);

const fillPassword = async (page: Page, value: string) =>
    await page.fill(\"password-for-test\", value);


  await fillName(page, name);
  await fillEmail(page, email);
  const res = await page.locator(\'.email-error\').innerText(); // return error string
  expect(res).toContain(\"Email is already in used\");

我得到了错误,你可以在我上传的图片中看到 任何想法如何删除或修复此错误

    标签: testing e2e-testing playwright playwright-test


    【解决方案1】:

    你用这个怎么样:

    await expect(page.locator('.email-error')).toContainText(
      'Email is already in used'
    )
    

    还要检查断言消息的最后一个单词是used 还是use

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 2018-02-20
      • 1970-01-01
      • 2020-06-20
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多