cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.77k stars 3.17k forks source link

Cypress Doesn't Finish Typing Strings Before Continuing to Next Field #17231

Closed maga-polito closed 1 year ago

maga-polito commented 3 years ago

Experiencing the same issue described on https://github.com/cypress-io/cypress/issues/5480

This happens on angular dialogs from AngularJS Material library

cypress version: 6.8.0

I implemented the workaround described but when text is long this increment test execution time a lot

T0BiD commented 3 years ago

@maga-polito facing the same problem (since forever)

Which workaround are you talking about?

Our strings are between 20 and 30 chars and roughly every fifth time are missing one or more characters.

szamanr commented 2 years ago

i'm on cypress 8.3.1 and still experiencing this issue. just now i had a test try to type 200 into a field and ended up typing 20 and proceeding to the next one. unfortunately i don't have a reproducible example as the behaviour seems random. this is the code for typing that value, if that helps:

cy.get("[data-cy=foo-bar]").clear().type(value, { scrollBehavior: false });

szamanr commented 2 years ago

also experiencing this on 8.7 and it seems to happen more on chrome than on electron. the behaviour seems kind of random.

let value = "some value";
cy.get("[data-cy=foo-bar]").clear();
cy.get("[data-cy=foo-bar]").type(value));
// types: "so" or "som", or "some v"...
BlueWinds commented 2 years ago

Unfortunately, none of these comments contain enough information to reproduce the issue. A code snippet that can be run in isolation, or a public repository demonstrating the issue would be very helpful for looking into it.

describe("typing long strings", function() {
  for (let i=0; i < 20; i++) {
    it("fails? " + i, function() {
      cy.document().then(doc => {
        doc.body.innerHTML = `
          <form>
            <input id="foo" />
          </form>
        `
      })

      const str = 'some value, a very long value, typing in a string'

      cy.get('#foo').type(str)
      cy.get('#foo').should('have.value', str)
    })
  }
})

This passes every time, but clearly it's far simpler than a real app, so there must be something else going wrong, and there's no way to tell what without having a reproducible test case we can look into.

alihejazi commented 1 year ago

Ladies and gents, I finally figured this out after a few hours of testing. You need to use the force optional parameter like this:

.type('your string here', { force: true })

I hope that helps!

alihejazi commented 1 year ago

cc @maga-polito

cypress-app-bot commented 1 year ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot commented 1 year ago

This issue has been closed due to inactivity.

jikol1906 commented 8 months ago

I had the same problem.

I realized that some other element on the page was stealing the focus from the element I was typing in.