I need some assistance.This is a weird one.Basically I am writing out some testcafe tests where: a user goes to the order summary page and verifies that the total on the check out page matches the total on the order details page.
The issue: There are instances where the order details total is off by a penny(not a bug worthy of fixing any time soon. according to the developers).So for example, on the checkout page your order total is $3.50. On the order details page the total is $3.51
Is there a way to combat a penny extra in a testcafe assertion?
Here is what my assertion looks like:
await t
.expect(totalOnCheckoutPage)
.eql(totalOnOrderDetails);
totalOnCheckoutPage and totalOnOrderDetails are selector variables.
You can write custom util to round. Sample
function round(x, precision) { var y = +x + (precision === undefined ? 0.5 : precision/2); return y - (y % (precision === undefined ? 1 : +precision)); } console.log(round(3.51, 0.1)) console.log(round(3.55, 0.1))
Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
You can try Within assertion method
await t.expect(5).within(3, 10, 'this assertion will pass');
extract the inner text of both values, and add the needed round off range
https://devexpress.github.io/testcafe/documentation/test-api/assertions/assertion-api.html#within
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.