I have this HTML element:
invoke() calls a jquery function on the element. To get the value of an input, use the function val()
:
cy.get('input').invoke('val').should('contain', 'mytext')
This is not the same as getting the value attribute which will not update with user input, it only presets the value when the element renders. To get an attribute, you can use the jquery function attr()
:
cy.get('input').invoke('attr', 'placeholder').should('contain', 'username')
Now there is a plugin for your need.
https://github.com/Lakitna/cypress-commands/blob/develop/docs/attribute.md
With this, you'll be able to do :
cy.get('input').attribute('placeholder').should('contain', 'username');