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.

Cypress Error for a simpe cy.visit()

See original GitHub issue

Cypress throwing error for a simple method

cy.visit('http://demo.automationtesting.in/')

Current behavior:

My Current Code :

describe('Demo Automation Testing', () => {
    it('Register Page', () => {
        cy.request('http://demo.automationtesting.in/')
        cy.visit('http://demo.automationtesting.in/')
    })
})

Error :

visit http://demo.automationtesting.in/
**CypressError**
The following error originated from your application code, not from Cypress.
  > Script error.
Cypress detected that an uncaught error was thrown from a cross origin script.
We cannot provide you the stack trace, line number, or file where this error occurred.
Check your Developer Tools Console for the actual error - it should be printed there.
It's possible to enable debugging these scripts by adding the crossorigin attribute and setting a CORS header.
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the uncaught:exception event.Learn moreLearn more

Stack Trace-

  at cypressErr (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:171356:17)
    at Object.errByPath (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:171411:11)
    at Object.createUncaughtException (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:161127:46)
    at $Cy.onUncaughtException (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:168996:25)
    at onError (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:168058:40)
From previous event:
    at run (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:168400:20)
    at $Cy.cy.<computed> [as request] (http://demo.automationtesting.in/__cypress/runner/cypress_runner.js:168852:12)
From Your Spec Code:
    at Context.eval (webpack:///cypress/integration/demoautomationtesting/register.spec.js:5:12)

image

Desired behavior:

Cypress should open the given webpage and pass the testcase

Test code to reproduce

Very simple Project.

  1. Opened VS Code with new project.
  2. ran npm init
  3. ran npm install cypress
  4. under cypress>integration>demoautomationtesting>register.spec.js

Enter Code

/// <reference types="cypress" />
describe('Demo Automation Testing', () => {
  it('Register Page', () => {
    cy.request('http://demo.automationtesting.in/')
    cy.visit('http://demo.automationtesting.in/')
  })
})
  1. ran npx cypress open with Chrome 84
  2. clicked on register.spec.js

PLEASE NOTE : When i try the URL : https://www.google.co.in it works fine.

For Better reproduction, please try below forked repo: npx cypress run Please Fork or Clone https://github.com/ManjunathPrabhakar/cypress-test-tiny to reproduce.

Versions

Cypress 5.0.0 Windows 10 Chrome 84 (When i ran with GUI Runner in original project) Edge Headless (When ran in https://github.com/ManjunathPrabhakar/cypress-test-tiny)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
ManjunathPrabhakarcommented, Aug 22, 2020

Thank you for your quick response and resolution. Closing this issue.

1reaction
ManjunathPrabhakarcommented, Aug 22, 2020

@csvan Thank you! it worked. I tired below

Approach 01

/// <reference types="cypress" />

Cypress.on('uncaught:exception', (err, runnable) => {
    Cypress.log("Browser log has Error(s) : " + err.name)
    return false
})

describe('Demo Automation Testing', () => {
    it('Register Page', () => {
        cy.request('http://demo.automationtesting.in/')
        cy.visit('http://demo.automationtesting.in/')
    })
})

Approach 02

/// <reference types="cypress" />

describe('Demo Automation Testing', () => {
    it('Register Page', () => {

        cy.on('uncaught:exception', (err, runnable) => {
            cy.log("Browser log has Error(s) : " + err.name)
            return false
        })

        cy.request('http://demo.automationtesting.in/')
        cy.visit('http://demo.automationtesting.in/')
    })
})

Also do let me know if there is a better way to handle these types. We can close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Messages | Cypress Documentation
cy.visit() failed because you are attempting to visit a different origin domain. Note. This error only pertains to Cypress version v11.0.0 ...
Read more >
Cypress - cy.visit() failed trying to load - Stack Overflow
Maybe someone had the same issue we were facing which is that the cypress.json file was not in the root. We had it...
Read more >
cypress-io/cypress - Gitter
I am trying to spin up my first ever test with Cypress and I am kinda bummed at not being able to get...
Read more >
Fixing Cypress cross-origin errors - Reflect.run
... avoiding cross-origin errors in Cypress tests via the cy.origin() ... simple example that demonstrates a cross-domain error in Cypress.
Read more >
How to handle Errors in Cypress | BrowserStack
Cypress provides the option failOnStatusCode: false, where you need to pass this option to cy.visit() command. Example: Webpage throwing 400 Bad ...
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