I have some input
<input />
How to assert that input has truthy value?
I think it's possible with
cy('input').should('not.have.value', '')
but I think it's slightly unreliable. Or maybe not. But anyway, would be nice to know some other way to check for truthy value.
Cypress can validate the text on an element with the help of jQuery text() method. This method shall help us to fetch the text content on the selected element. We can also put assertions on the text content of the element. cy.
To find elements by data attribute, query using the attribute selector. cy. get() yields a jQuery object, you can get its attribute by invoking the . attr() method.
The only way for you to "see" and debug why Cypress thought an element was not visible is to use a debugger statement.
Handling Assertions in Cypress: Tutorial. For every test, it is essential to have a validation that checks whether it functions as expected or not. Assertions are these validations in the test automation, which determine whether the test is working as expected or not.
Just found that invoke thing, so it's possible to do so:
cy.get('input').invoke('val').should("be.ok");
cy.get('input').invoke('val').should('not.be.empty') // works in the same way.
invoke is the way to call functions (jquery command in that case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With