'Cypress `.type` enters same text twice (duplicating each letter)
I have a cypress test that uses cy.get(...).clear().type('some-text')
. When it runs, it sometimes works as expected, and sometimes enters ssoommee--tteexxtt
instead of some-text
. Yes, each letter is entered twice. This seems to be happening roughly 50% of the time.
I have other tests that use .type(...)
, none of which present this behavior. Only the first test using .type(...)
does this.
Solution 1:[1]
Inspecting the surrounding tests, I found a stray async
on the test right before the flaky one:
it('Tests some element', async () => {
cy.visit('/')
cy.get('[id="some-element"]').should('exist')
})
it('Types into a text box', () => {
cy.visit('/')
cy.get('input[name="q"]').clear().type('some-text')
...
})
That async
on the previous test was the culprit! Removing it sorted it all out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Anton Drukh |