I need to check if the input element has one of 3 values as I am automating AI feautre and it sometimes generates random text, but still uses at least one value.
So I need to check if input has A or B or C value, one of this values
How can I do this?
Tried this from one of questions here –
cy.get('section div:nth-child(4)').invoke('text').then((text) => {
expect(text).not.equal(companyNameText);
expect(text).not.equal(descriptionText);
expect(text).not.equal(purposeText);
})
Does not work in my case
2
Answers
You an use Chai’s
oneOf
method to achieve this. There is a caveat from the docs:You are testing using
expect(...).not.equal(...)
on all three strings, which results in the opposite test.Instead you can use string comparison and OR operator,
Another way is Array.includes
or a variation with
.to.include()
matcherEven more, it’s possible to use
cy.contains()
with a RegExp that has OR operator built inAnother one, with
.should()