Comparing text values in Cypress

I'm trying to compare two values on a page to make an assertion. I want to capture the value of one text element and compare it with another value on the same page. I'm not sure how to do that in javascript. In Java/selenium this is easy but cypress seems less flexible on this..

3

1 Answer

This is a test comparing two generated strings and if they are not equal after clicking a button:

 it('Test generating new password', () => { let password1; cy.get('#password').should(($div) => { password1 = $div.text(); }); cy.get('#generate-button').click(); cy.get('#password').should(($div) => { const password2 = $div.text(); expect(password1).not.equal(password2); }); });
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like