0
await t.expect(Selector('#elementId').innerText)
       .eql('Discounted 20% with your subscription');

Here the text - Discounted 20% with your membership
20% is not constant, it may change to 15% or 19%

how can I "assert" this?

I have tried

await t.expect(Selector('#elementId').innerText)
       .eql('Discounted' + 'with your subscription');

But doesn’t work

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

2 Answers2

2

You can use regular expressions.

const regexp = new RegExp (your regular expression);

await t.expect(Selector('#elementId').innerText).match(regexp);

Refer to this documentation article for more information: https://devexpress.github.io/testcafe/documentation/reference/test-api/testcontroller/expect/match.html

0

This is probably not the most elegant way to solve this, but one solution I can think of is the following:

const myDiscountList = ["20", "19", "15"];
const innerTextOfMyElement = await Selector('#elementId').textContent;

await t.expect(myDiscountList.some(discount => innerTextOfMyElement === ("Discounted " + discount + " with your membership"))).ok("At least one of the expected discounts should match!");

A more elegant way to solve this would probably be making use of regex.

Martin H.
  • 538
  • 1
  • 7
  • 21