When checking value of input box like this
<input id="foo">
we have to use have.value
which is hard to remember https://docs.cypress.io/guides/references/assertions.html#Value
cy.get('#foo').type('something')
cy.get('#foo').should('have.value', 'something')
It would be nice to also detect input
or textarea
and allow these assertions in this case
cy.get('#foo').should('equal', 'something') // DOES NOT WORK NOW!
cy.get('#foo').should('contain', 'something') // DOES NOT WORK NOW!
Cypress 1.1.2
@bahmutov I like the idea of allowing should('contain', 'asdf')
, but that opens up more questions, will using cy.contains('asdf')
chained from cy.
also find the input field text?
I like the idea of us being "smarter" about the assertions but the problem to me is consistency and documentation.
I would prefer to error when using these assertions and telling you the "right" one to do. I think there is already a huge amount of confusion as to how to use assertions, which one to use, what the differences are, and then taking assertions that only ever mean a specific thing and making them more broadly applicable (only in Cypress land) will add to the confusion, for sure.
Perhaps re-evaluating how we document and present the assertions would be better.
Um, is it actually possible to do should('contain', 'asdf')
against input value? I am looking through docs and trying things like should('value.contain', 'asdf')
, but that checks for a full value.
@FredyC No, the test cases written above are suggestions for how they would like the API to work.
The valid way to check for an input value would be:
cy.get('input').should('have.value', 'asdf')
@jennifer-shehane I know about have.value
, but I am asking if there is a way to assert for partial value of an input? This is the only way I was able to figure out and it's rather ugly imo. Is there some more direct assertion for that? It's undocumented in that case. The suggestion above would kinda fix it.
cy.get('input').then($input => {
expect($input.val()).to.contain('partial')
})
@FredyC Ah, I see. I think you may be able to write:
cy.get('input').invoke('val').should('contain', 'partial')
Hi @jennifer-shehane and @FredyC and of course everybody! ))
I understand that my comment is little bit offtop, but for now I was not found better place for ask.
I can't figure out of how to check for partial content of textarea
.
Maybe anyone can suggest me some example?
Thank you all!
@rossanoua the code @jennifer-shehane mentioned above should do the trick:
cy.get('textarea').invoke('val').should('contain', 'partial')
@Bkucera
yes! it's worked!
i was tried this code before, but without success. (so, some where was a mistake made by me)
thanks a lot!
Partial value,html,text,and id matchers are in #3259
Thanks @jennifer-shehane. Just ran into this today. I was actually trying out the exact scenario that @bahmutov proposed at the top of the thread to do a contains() on a textarea. Couldn't get it to work and stumbled across this - thanks for the invoke() suggestion. It does feel like contains() should work here, but it sounds like there are additional things to take into consideration.
Thanks, @Bkucera your solution works for me
Most helpful comment
@FredyC Ah, I see. I think you may be able to write: