playwright 中断言失败的自定义消息(使用 cucumber.js)

问题描述 投票:0回答:1

在项目中我使用node js 20.5.1,playwright 1.37。与黄瓜8.0.0。 如果预期方法返回失败,我想添加自己的客户消息。我想我可以像下面这样做:

expect(3),"My custom message").toBeLessThanOrEqual(2);

在测试结果中我应该执行该步骤 错误:我的自定义消息,

,但我只看到

Error: expect(received).toBeLessThanOrEqual(expected)

你知道我该怎么处理吗? :) 感谢您的任何提示:)

playwright assertion cucumberjs playwright-test
1个回答
0
投票

自定义期望消息:

await expect(page.getByText('Name'), 'should be logged in').toBeVisible();

错误看起来像这样:

    Error: should be logged in

Call log:
  - expect.toBeVisible with timeout 5000ms
  - waiting for "getByText('Name')"


  2 |
  3 | test('example test', async({ page }) => {
> 4 |   await expect(page.getByText('Name'), 'should be logged in').toBeVisible();
    |                                                                  ^
  5 | });
  6 |
© www.soinside.com 2019 - 2024. All rights reserved.