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

web application doesn't load correctly with Cypress #4042

Closed
pinko2512 opened this issue Apr 27, 2019 · 9 comments
Closed

web application doesn't load correctly with Cypress #4042

pinko2512 opened this issue Apr 27, 2019 · 9 comments

Comments

@pinko2512
Copy link

pinko2512 commented Apr 27, 2019

My team is working on a web application and we decided to use Cypress for automated tests. Problem is, when we run these tests, they only get past login screen. Home screen doesn't load correctly. This happens ONLY in Chrome driven by Cypress and Electron driven by Cypress. In normal Chrome the application runs without errors.

Current behavior:

When running Cypress tests, web application doesn't load correctly and console displays these errors on home screen:

Uncaught SyntaxError: Invalid or unexpected token
Uncaught Error: Cannot find module 'jquery'
Uncaught Error: Cannot find module 'angular-cookies'

Desired behavior:

Behaviour should be the same in standalone Chrome and Chrome driven by Cypress (and Electron).

Versions

Windows 10
Cypress 3.2.0,
Chrome 74, Electron 59

If somebody knows what's happening and how can it be fixed, please let me know. Thank you

@jennifer-shehane
Copy link
Member

Hey @pinko2512 are there any errors displaying within the Cypress Test Runner? Could you print those?

Unfortunately, this will be quite difficult to track down without being able to reproduce on our end, but any more information you can provide, screenshots/videos may be helpful.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Apr 29, 2019
@pinko2512
Copy link
Author

pinko2512 commented Apr 29, 2019

When the test fails, Test Runner shows this error:
02
Chrome console doesn't show anything.

If I add these lines to the test:

Cypress.on('uncaught:exception', (err, runnable) => {
  return false
})

then the test fails because it can't select an element (home page is not loaded correctly) and Chrome console shows this:
03

@pinko2512
Copy link
Author

pinko2512 commented Apr 29, 2019

We fixed the issue. The problem was that when we opened first Uncaught SyntaxError - Invalid token, we found this:
04

The same file run on the standalone Chrome was loaded correctly, so it had to be issue with Cypress encoding. After some googling we found that Cypress settings has a default settings with this property:
"modifyObstructiveCode": true

https://on.cypress.io/configuration#modifyObstructiveCode

After setting it to false it works well.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented May 2, 2019

@pinko2512 Nice investigating. Could you provide the original function code as it appeared in normal Chrome versus the function code that displays within the Cypress browser when modifyObstructiveCode: true was set?

There should have been something surrounding this code related to window, parent, or top` like one of these examples in our code, if you can paste the code starting from there - https://github.com/cypress-io/cypress/blob/develop/packages/driver/test/cypress/fixtures/security.html#L15

We certainly don't intend to create any malformed tokens like this.

@jennifer-shehane
Copy link
Member

@pinko2512 Any update on this?

@jennifer-shehane jennifer-shehane added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: needs information Not enough info to reproduce the issue labels May 30, 2019
@jennifer-shehane
Copy link
Member

Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.

@jennifer-shehane jennifer-shehane removed the stage: awaiting response Potential fix was proposed; awaiting response label Jul 11, 2019
@paopao1983
Copy link

Hello Jennifer. I'm new in cypress and I'm getting this error too, but I don't identify how can localice the "wrong" code. The Dev team made some changes last week and I started to get this error today that I have updated project, and I don't know how to tell them what search for and adjust. If I add ("modifyObstructiveCode": false) to the config, my script runs but i don't know if this can affect other scripts.

image

isaacplmann pushed a commit to isaacplmann/nx that referenced this issue Oct 23, 2019
chore(nx): move some schematics into @nrwl/angular

chore(nx): add e2e test

feat(nx): add storybook schematics and builder

test: Add tests

test: remove test

chore: Move some schematics into @nrwl/angular

test: fix tests

chore: Add e2e test

chore: Bump storybook versions

chore: createTestUiLib takes a libName argument

chore: configs extend root config

fix: Remove custom scss loader

feat: add storybook builder

fix: generate documentation and fix linting

chore: Builder tests passing

fix(nx): configuration schematic can run multiple times

feat(nx): component story format

docs(nx): update storybook docs

fix(nx): pin core-js dev dependency to ^2.6.9

chore(nx): fix formatting

chore(nx): match core-js version for web/storybook

chore(nx): remove storybook's angular dependencies

chore(nx): modifyObstructiveCode to false in cypress.json

See: cypress-io/cypress#4042 (comment)

chore(nx): storybook tests --no-interactive

chore(nx): add storybook to e2e tests

chore(nx): reorder e2e tests
isaacplmann pushed a commit to isaacplmann/nx that referenced this issue Oct 23, 2019
    chore(nx): move some schematics into @nrwl/angular

    chore(nx): add e2e test

    feat(nx): add storybook schematics and builder

    test: Add tests

    test: remove test

    chore: Move some schematics into @nrwl/angular

    test: fix tests

    chore: Add e2e test

    chore: Bump storybook versions

    chore: createTestUiLib takes a libName argument

    chore: configs extend root config

    fix: Remove custom scss loader

    feat: add storybook builder

    fix: generate documentation and fix linting

    chore: Builder tests passing

    fix(nx): configuration schematic can run multiple times

    feat(nx): component story format

    docs(nx): update storybook docs

    fix(nx): pin core-js dev dependency to ^2.6.9

    chore(nx): fix formatting

    chore(nx): match core-js version for web/storybook

    chore(nx): remove storybook's angular dependencies

    chore(nx): modifyObstructiveCode to false in cypress.json

    See: cypress-io/cypress#4042 (comment)

    chore(nx): storybook tests --no-interactive

    chore(nx): add storybook to e2e tests

    chore(nx): reorder e2e tests
vsavkin pushed a commit to nrwl/nx that referenced this issue Oct 23, 2019
    chore(nx): move some schematics into @nrwl/angular

    chore(nx): add e2e test

    feat(nx): add storybook schematics and builder

    test: Add tests

    test: remove test

    chore: Move some schematics into @nrwl/angular

    test: fix tests

    chore: Add e2e test

    chore: Bump storybook versions

    chore: createTestUiLib takes a libName argument

    chore: configs extend root config

    fix: Remove custom scss loader

    feat: add storybook builder

    fix: generate documentation and fix linting

    chore: Builder tests passing

    fix(nx): configuration schematic can run multiple times

    feat(nx): component story format

    docs(nx): update storybook docs

    fix(nx): pin core-js dev dependency to ^2.6.9

    chore(nx): fix formatting

    chore(nx): match core-js version for web/storybook

    chore(nx): remove storybook's angular dependencies

    chore(nx): modifyObstructiveCode to false in cypress.json

    See: cypress-io/cypress#4042 (comment)

    chore(nx): storybook tests --no-interactive

    chore(nx): add storybook to e2e tests

    chore(nx): reorder e2e tests
Doginal pushed a commit to Doginal/nx that referenced this issue Oct 30, 2019
    chore(nx): move some schematics into @nrwl/angular

    chore(nx): add e2e test

    feat(nx): add storybook schematics and builder

    test: Add tests

    test: remove test

    chore: Move some schematics into @nrwl/angular

    test: fix tests

    chore: Add e2e test

    chore: Bump storybook versions

    chore: createTestUiLib takes a libName argument

    chore: configs extend root config

    fix: Remove custom scss loader

    feat: add storybook builder

    fix: generate documentation and fix linting

    chore: Builder tests passing

    fix(nx): configuration schematic can run multiple times

    feat(nx): component story format

    docs(nx): update storybook docs

    fix(nx): pin core-js dev dependency to ^2.6.9

    chore(nx): fix formatting

    chore(nx): match core-js version for web/storybook

    chore(nx): remove storybook's angular dependencies

    chore(nx): modifyObstructiveCode to false in cypress.json

    See: cypress-io/cypress#4042 (comment)

    chore(nx): storybook tests --no-interactive

    chore(nx): add storybook to e2e tests

    chore(nx): reorder e2e tests
@saas2813
Copy link

saas2813 commented Jan 9, 2020

I tried adding
"modifyObstructiveCode": false
to my cypress.json but it did not help with my problem from #4889.
Is cypress.json the right file? should the setting be located on top-level or somewhere else ?

@jennifer-shehane
Copy link
Member

Yes, cypress.json is the correct file for this setting. You can read more here. https://docs.cypress.io/guides/references/configuration.html#modifyObstructiveCode

If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

@cypress-io cypress-io locked and limited conversation to collaborators Jan 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants