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

TypeError: Cannot read property 'length' of undefined when run test by cypress run #7676

Closed
sergeyblohin opened this issue Jun 11, 2020 · 5 comments · Fixed by #7746
Closed
Assignees
Labels
topic: shadow dom Issues when testing shadow dom type: bug v4.8.0 🐛 Issue present since 4.8.0

Comments

@sergeyblohin
Copy link

Current behavior:

I have testing site with shadow DOM.

it('test', () => {
  cy
    .get('div[class="oneAppNavContainer"]')
    .find('one-appnav')
    .find('span[title="          Config"]', {includeShadowDom: true})
    .contains('          Config');
});

It's code work correctly when I use cypress open.

Screenshot 2020-06-11 at 10 53 53

But not work when I use cypress run.

TypeError: Cannot read property 'length' of undefined
    at superMatcher (https://example.com/__cypress/runner/cypress_runner.js:86701:17)
    at Sizzle.select (https://example.com/__cypress/runner/cypress_runner.js:86897:44)
    at Function.Sizzle [as find] (https://example.com/__cypress/runner/cypress_runner.js:85065:9)
    at jQuery.fn.init.find (https://example.com/__cypress/runner/cypress_runner.js:87096:11)
    at find (https://example.com/__cypress/runner/cypress_runner.js:153939:31)
    at getEl (https://example.com/__cypress/runner/cypress_runner.js:154030:18)
    at getElements (https://example.com/__cypress/runner/cypress_runner.js:154058:17)
    at Context.<anonymous> (https://example.com/__cypress/runner/cypress_runner.js:154082:14)
    at Context.<anonymous> (https://example.com/__cypress/runner/cypress_runner.js:163288:21)
    at https://example.com/__cypress/runner/cypress_runner.js:162724:15
    at tryCatcher (https://example.com/__cypress/runner/cypress_runner.js:10161:23)
    at Promise._settlePromiseFromHandler (https://example.com/__cypress/runner/cypress_runner.js:8096:31)
    at Promise._settlePromise (https://example.com/__cypress/runner/cypress_runner.js:8153:18)
    at Promise._settlePromiseCtx (https://example.com/__cypress/runner/cypress_runner.js:8190:10)
    at _drainQueueStep (https://example.com/__cypress/runner/cypress_runner.js:4872:12)

Desired behavior:

What I do wrong?

Versions

Cypress: 4.8.0
Chrome Canary 85

@jennifer-shehane
Copy link
Member

Hey @sergeyblohin, thanks for opening an issue. Shadow DOM is experimental, so there could be an issue in your case.

In order to look into this, we'll need a fully reproducible example so that we can see where the error is throwing from and recreate it ourselves.

Please provide a repo with a failing test, or the application code required to run against this. Otherwise, we'll have to close the issue as there's no way forward to investigate.

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue topic: shadow dom Issues when testing shadow dom labels Jun 12, 2020
@sergeyblohin
Copy link
Author

@jennifer-shehane, thank you for responding.
I was able to find a site that exactly reproduces the defect I described.
I created a public repository: https://github.com/sergeyblohin/cypress-issue-7676
To play it, just do the following:

git clone git@github.com:sergeyblohin/cypress-issue-7676.git
cd cypress-issue-76
npm install

npm run cypress:open
# or
npm run cypress:run

cypress:open work correctly:

cypress_open

cypress:run returns error:

TypeError: Cannot read property 'length' of undefined

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Jun 16, 2020

@sergeyblohin Thanks for providing a repro!

Reproducible example

cypress.json

{
  "experimentalShadowDomSupport": true
}

spec.js

it('experimentalShadowDomSupport', () => {
    cy.visit('https://developer.salesforce.com/docs/component-library/overview/components');
    cy.get('componentreference-header[class="header dscVisible"]')
    .shadow()
    .find('componentreference-nav-bar[class="navigation"]')
    .should('exist');
})

cypress open

Screen Shot 2020-06-16 at 3 43 14 PM

cypress run

This will error regardless of Electron or Chrome. The best way to debug the error is to pass cypress run --browser chrome --no-exit

Screen Shot 2020-06-16 at 3 48 22 PM

Screen Shot 2020-06-16 at 3 44 41 PM

  1) experimentalShadowDomSupport:
     TypeError: Cannot read property 'length' of undefined
      at superMatcher (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:86701:17)
      at Sizzle.select (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:86897:44)
      at Function.Sizzle [as find] (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:85065:9)
      at jQuery.fn.init.find (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:87096:11)
      at getEl (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:154039:35)
      at getElements (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:154058:17)
      at Context.<anonymous> (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:154082:14)
      at Context.<anonymous> (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:163288:21)
      at https://developer.salesforce.com/__cypress/runner/cypress_runner.js:162724:15
      at tryCatcher (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:10161:23)
      at Promise._settlePromiseFromHandler (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:8096:31)
      at Promise._settlePromise (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:8153:18)
      at Promise._settlePromiseCtx (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:8190:10)
      at _drainQueueStep (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:4872:12)
      at _drainQueue (https://developer.salesforce.com/__cypress/runner/cypress_runner.js:4861:9)

@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: needs information Not enough info to reproduce the issue labels Jun 16, 2020
@jennifer-shehane jennifer-shehane added type: bug v4.8.0 🐛 Issue present since 4.8.0 labels Jun 16, 2020
@chrisbreiding chrisbreiding self-assigned this Jun 17, 2020
@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] 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 There is an open PR for this issue [WIP] labels Jun 17, 2020
@cypress-bot cypress-bot bot added the stage: pending release There is a closed PR for this issue label Jun 18, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 18, 2020

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

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Jun 18, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 23, 2020

Released in 4.9.0.

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

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Jun 23, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: shadow dom Issues when testing shadow dom type: bug v4.8.0 🐛 Issue present since 4.8.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants