2

In project I use node js 20.5.1, playwright 1.37. with cucumber 8.0.0. I want to add own customer message if expected method return me a failed. I thought I could do it like below:

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

And in test result I should for that step Error: My custom message,

,but I only see

Error: expect(received).toBeLessThanOrEqual(expected)

Do you know how I could handled with that ? :) Thanks for any tips :)

Marcin
  • 97
  • 7
  • 8.0.0 cucumber version is quite old, what if switch to latest one? – Renat Aug 11 '23 at 11:51
  • Unfortunately no, I updated to the latest version and problem is still occuring :) But I created workaround try { expect.soft(3).toBeLessThanOrEqual(2); } catch (error) { throw new Error(My custom message); } – Marcin Aug 11 '23 at 12:35
  • You are using expect from playwright or from somewhere else? Could you use: https://playwright.dev/docs/test-assertions#custom-expect-message – Jaky Ruby Aug 14 '23 at 22:09

1 Answers1

0

Custom Expect Error Message:

That's how I would write it:

expect(3,"Custom Message").toBeLessThanOrEqual(2);  

Note: As its not asynchronous operation, we don't need to await it.

Reference: ​​​​

https://playwright.dev/docs/test-assertions#custom-expect-message

Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23