Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'indexOf' of undefined when using .type() #6125

Closed
srideeps opened this issue Jan 8, 2020 · 6 comments · Fixed by #8255
Closed

Cannot read property 'indexOf' of undefined when using .type() #6125

srideeps opened this issue Jan 8, 2020 · 6 comments · Fixed by #8255
Labels
topic: cy.type ⌨️ type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0

Comments

@srideeps
Copy link

srideeps commented Jan 8, 2020

Current behavior:

I'm currently using Cypress version 3.4.1 to run automation tests.
I have a SignIn test suite to validate the login functionality . They are pretty straightforward tests that run against the application URL and validate if the user is able to login to the the app or not.

In Cypress 3.4.1, the login tests are executed successfully.
But when I tried to upgrade to a version > 3.4.1, for example: latest version 3.8.1, I see this error
TypeError: Cannot read property 'indexOf' of undefined

Let's take this one test should display en error on invalid login attempt as an example

I see the following error when I try to type in the username into the #login_username input field.

cypress_login_error

Console output:

image

Desired behavior:

Cypress should Type the username into the input text box successfully.

Console output when the behavior is correct.

image

Test code to reproduce

Below is the code for the Invalid Login test

    it('should display en error on invalid login attempt', () => {
      cy.get('#login_username')
        .type('insuranceproctor');

      cy.get('#login_password')
        .type('54321drowssap');

      cy.get('#signin-btn')
        .should('be.enabled')
        .click();

      cy.get('h3')
        .should('be.visible')
        .and('contain', 'Whoops!');

      cy.get('p')
        .eq(0)
        .should('be.visible')
        .and('contain', 'Your username and password don\'t match, please try again.');

      cy.url()
        .should('contain', 'signin');
    });

Versions

Currently used version:
Cypress 3.4.1
Chrome 79

Seeing this error in versions 3.5.0 and above.

Extra Info

The URL loads just fine and I'm able to see the sign-in screen and the cookies are loading correctly.
All other tests where I have the login functionality mocked pass 100%
I'm seeing this issue only with these tests which interact directly with the UI to login.

Workaround

I'm able to use invoke to change the value of the input fields, but that's not the actual purpose of the login test so I definitely need a solution.
I'm a fan of Cypress and I'm super excited to see all the improvements you guys are doing! thanks a lot ❤️

@jennifer-shehane
Copy link
Member

I'm able to recreate this error with the code below. This is a regression introduced in Cypress 3.5.0

it('throws error', () => {
  cy.visit('https://signin.simple.com')
  cy.get('#login_username')
    .type('foobar')
})

3.4.1

Screen Shot 2020-01-13 at 4 21 54 PM

3.5.0

Screen Shot 2020-01-13 at 4 20 34 PM

@jennifer-shehane jennifer-shehane added v3.5.0 🐛 Issue present since 3.5.0 type: regression A bug that didn't appear until a specific Cy version release topic: cy.type ⌨️ labels Jan 13, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jan 13, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review stage: ready for work The issue is reproducible and in scope and removed stage: ready for work The issue is reproducible and in scope stage: work in progress stage: needs review The PR code is done & tested, needs review labels Jan 27, 2020
@srideeps
Copy link
Author

srideeps commented Feb 12, 2020

@jennifer-shehane .. just following up on this? any ETA on when this would get fixed? I'm super excited to try out 4.0 but unfortunately can't due to this bug.

@sainthkh
Copy link
Contributor

sainthkh commented Jul 9, 2020

event = new win['Event'](eventType, eventOptions)

Changing Event to CustomEvent works. But the problem is that it's hard to explain why it works.

@jennifer-shehane jennifer-shehane changed the title Sign In tests fail with Type Error while trying to upgrade to >3.4.1 version Cannot read property 'indexOf' of undefined when using .type() Jul 29, 2020
@sainthkh
Copy link
Contributor

sainthkh commented Aug 11, 2020

It seems that the problem is more with simple.com's code than Cypress.

When you beautify the problematic code, you can find that Event class is extended.

n = this.Event = this.DOMEvent = new Type("DOMEvent", function(n, i) {
    if (i || (i = window),
        n = n || i.event,
        n.$extended)
        return n;
    this.event = n,
        this.$extended = !0,
        this.shift = n.shiftKey,
        this.control = n.ctrlKey,
        this.alt = n.altKey,
        this.meta = n.metaKey;
    for (var r = this.type = n.type, s = n.target || n.srcElement; s && 3 == s.nodeType;)
        s = s.parentNode;
    if (this.target = document.id(s),
        0 == r.indexOf("key")) {

But the problem is that they only considered the case when the type of n is an Event, not string.

So, when Cypress sent a simple Event with "keydown" as the first argument, r.indexOf("key") couldn't work.

I'm currently fixing this. It might take a little bit longer than expected because I need to simplify this problem and create a test case.

And it also should be fixed with #5650. Interestingly, they're 2 separate problems, but the solution is the same.

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress stage: needs review The PR code is done & tested, needs review labels Aug 12, 2020
@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Sep 10, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Sep 10, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 10, 2020

The code for this is done in cypress-io/cypress#8255, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 15, 2020

Released in 5.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.2.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.type ⌨️ type: regression A bug that didn't appear until a specific Cy version release v3.5.0 🐛 Issue present since 3.5.0
Projects
None yet
3 participants