Reputation: 11
How to extract 3 from this and compare it with same if this integer value changes 3
Upvotes: 0
Views: 351
Reputation: 1746
Easy ways to extract element text and compare it with expected value are:
cy.get(locatorOfElement).invoke("text").then((value) => {
expect(value).to.equal("3");
});
cy.get(locatorOfElement).invoke("text").should("be.eq", "3");
and if you want to compare it with integer value then you have to convert the extracted value to an integer and then compare it to an expected integer value.
cy.get(locatorOfElement).invoke("text").then((value) => {
expect(parseInt(value)).to.equal(3);
});
cy.get(locatorOfElement).invoke("text").then(parseInt).should('eq', 3)
Upvotes: 1