question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.visit randomly not loading the web application.

See original GitHub issue

I am testing Cypress to see If we can use it for the automation of our test cases. I have created 4 test cases. And, cy.visit(desired link) is placed in beforeEach

Current behavior:

Sometimes all four of them run and pass without issues. Randomly, web application doesn’t load correctly for one of the four test cases. Console displays the following message:

Uncaught syntax error: Unexpected end of input

Desired behavior:

Every time cy.visit(desired link) is launched I should be able to land on the Login screen.

Versions:

Windows 10 Pro Cypress 3.8.1 Chrome 79

I have also added "modifyObstructiveCode":false in the cypress.json

Issue screenshot attached.

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

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Jan 13, 2020

@sarfrazwk Your application may be using “frame busting”. By default Cypress modifies code it detects as frame busting so the application under test runs properly in the Cypress Test Runner (which runs your app inside an iframe itself). Can you try disabling this by setting modifyObstructiveCode=false in your configuration? Further explanation can be found here: https://on.cypress.io/configuration#modifyObstructiveCode

This is a bit of a guess though since I can’t run the code provided.

0reactions
cadesalaberrycommented, Jun 17, 2021

I had the same issue, the fix took me a while. My problem was with how angular mangles the index.html file.

...
<script>
  function getName() {
    // do not show in production
    if (window.production) return '';
    return 'beta';
  }
</script>

the code would turn into a single line of js, leading to a Unexpected end of input

<script>
  function getName() {    // do not show in production    if (window.production) return '';    return 'beta';  }
</script>

Which would lead to the end of the code being commented out. Turning them into multi-line comments did the trick.

...
<script>
  function getName() {
    /* do not show in production */
    if (window.production) return '';
    return 'beta';
  }
</script>
<script>
  function getName() {    /* do not show in production */    if (window.production) return '';    return 'beta';  }
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress cy.visit doesn't load a website, Timed out after waiting
I have no previous experience working with Cypress and i'm stuck on such simple problem - cypress can't reach the united.com website.
Read more >
Troubleshooting | Cypress Documentation
Open Cypress via cypress open · Go to Developer Tools -> View App Data · This will take you to the directory in...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
Imagine you are trying to check how your application handles a network communication error. Internet is unreliable, servers go down and come ...
Read more >
Cypress tests fail randomly
cypresserror: cy.visit() failed trying to load: ... cy.visit () failed because you are attempting to visit a different origin domain Two URLs have...
Read more >
End-to-End Testing with Cypress and Auth0
If you do not know Cypress, check out this article for more. ... Visit the web application and invoke a redirect to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found