Reputation: 11
Is it possible to add multiple possible values to a single expectation? As in my case the title might have different text values depending on other processes on the website (the code below does not work as I would want to).
it('card should have a one of two names', () => {
expect(MyPage.cardName).toHaveText('Good Products' || 'Wonderfull Products');
});
The same question goes to chai's deep.equal
. Is it possible to have multiple variants in one assertion?
it('should verify the card titles list', () => {
// an array is created here
const cardTitles = MyPage.cardTitlesText();
chaiExpect(cardTitles).to.deep.equal(['Apples', 'Carrots', 'Tomatoes', 'Potatoes'] || ['Potatoes', 'Apples', 'Carrots', 'Tomatoes']);
});
Or perhaps I miss something in an overall concept of testing and this should be approached differently in the first place?
Upvotes: 1
Views: 3907
Reputation: 3950
It's now possible in the latest version of built-in expect-webdriverio, just pass an array of strings, see https://webdriver.io/docs/api/expect-webdriverio.html#tohavetext
Feel free ro raise feature requests to https://github.com/webdriverio/expect-webdriverio
Upvotes: 2
Reputation: 8322
'Good Products' || 'Wonderfull Products'
this basically means "if the operand on the left is false, return the value on the right". But you always have Good Products
there, which will never evaluate to false.
Similarly with the array in the second example. This wouldn't evaluate to false even if you had an empty array:
[] || [4]
still returns []
.
It's all just JavaScript, so you can read about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR
Upvotes: 0