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..
31 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