How to Correctly Use. Wrap() in Cypress
I'm Using Cypress 3.3.1 as an Example That Others Can Test, Consider the Following Code: Cy. Visit(') Cy. Get('Input[Type=Text]'). Each((El, Index) => { If...
I'm using Cypress 3.3.1
As an example that others can test, consider the following code:
cy.visit(')
cy.get('input[type=text]').each((el, index) => {
if (index === 0) {
cy.wrap(el).type('some text')
}
})
cy.contains('Google Search').click()
For some reason cy.contains('Google Search').click() is not able to find the element.
If I call cy.wrap('body') before I call .contains('Google Search') that now works. Suggesting that if you wrap an element, it changes some global context, and then has to be reset. No mention of this in the docs as far as I can see.
This code works:
cy.visit(')
cy.get('input[type=text]').each((el, index) => {
if (index === 0) {
cy.wrap(el).type('some text')
}
})
cy.wrap('body')
cy.contains('Google Search').click()
Are you supposed to 'reset' the context after using wrap() or am I misunderstanding how it should be used?