cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

[Documentation] Add incorrect usage to `cy.get`

Open Rc85 opened this issue 3 years ago • 1 comments

What would you like?

I have been declaring a variable with cy.get and was causing inconsistency as to which element it was asserting. The documentation doesn't state that this is actually an incorrect way of using it. Here is an example

const nameInput = cy.get('[data-testid="name-input"]');
const addressInput = cy.get('[data-testid="google-autocomplete-input"]');

addressInput.type('mcdonalds north road');

cy.wait(1000);

addressInput.type('{downArrow}{enter}');

nameInput.should('have.value', `McDonald's`);

nameInput.should will assert if addressInput has the value of McDonald's. I don't know why this is happening.

Why is this needed?

Save new developer times on producing a bug and debugging.

Other

No response

Rc85 avatar Sep 29 '22 16:09 Rc85

We do cover this in the docs under Core Concepts > Querying Elements, but I think adding a reference here as well could be useful.

astone123 avatar Sep 29 '22 17:09 astone123