I would like to have a flexible assertion which checks if a string is one of several values.
I have just started running my WebdriverIO + Mocha tests on BrowserStack, but they have US locale machines which render dates differently, so my tests are failing. There doesn’t seem to be a locale setting in BrowserStack config.
e.g.
expectDOB_AU = '29/02/2024'
expectDOB_US = '2/29/2024'
await expect(await MyPage.inputDOB.getValue()).toBe([expectDOB_AU, expectDOB_US])
I can see that hasText
can take an array, but this doesn’t work for a string fetched from an input value.
I have looked at this related question Multiple values in a single assertion in webdriverio
2
Answers
I have implemented this as a custom matcher - but still would like to know if it's possible in standard webdriverio.
test/cusom/customMatcher.js
optional:
test/custom/CustomMatchers.d.ts
wdio.conf.js
in the test spec
I realised I can use "native" Jest expects in webdriverio, and by inverting the assertion I can use a standard array matcher without need for custom matcher.
It feels unusual to me to have the expect value on the other side, but it works.