cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.01k stars 3.18k forks source link

ReferenceError: http is not defined #2454

Closed jordandlaman closed 6 years ago

jordandlaman commented 6 years ago

When executing a cy.visit(url) I am getting ReferenceError: http is not defined at XMLHttpRequest.xhttp.onreadystatechange.

screen shot 2018-09-10 at 12 30 05 pm

I know the problem child seems to have to do with /pkmslogout but no idea why its acting like http is not defined.

Here is also the console output.

screen shot 2018-09-10 at 12 33 19 pm

I am already catching all uncaught exceptions as well. Have tried catching this specific error with the recipe in the docs as well inside the test.

UPDATE: I have successfully gotten cypress to swallow the bug by switching the context block to a describe block and adding a before/beforeEach block right below that to register the uncaught exception to return false. For some reason this particular error is not respecting my support/index.ts files global uncaught exception handler. Attached is both my index file and the relevant describe and beforeAll block for someone to look at in case I have made a mistake somewhere that is obvious.

describe('Viewing Opportunity', () => {
    before(() => {
        Cypress.on('uncaught:exception', (err, runnable) => {
            // returning false here prevents Cypress from
            // failing the test if uncaught exceptions from the application appear
            return false;
        });
    })
    it('should login and view an opportunity', () => {
        cy.visit('url');
        cy.get('button').click();
        cy.get('[href="/web/secure/my/messages/new"]').click();
    });
});

index.ts file:

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Cypress.on('uncaught:exception', (err, runnable) => {
    // returning false here prevents Cypress from
    // failing the test
    return false;
});

UPDATE 2: Looks like the describe switch isn't a total fix. When that /pkms endpoint is aborted the test will pass with the exception handler but if it returns 200 http is not defined will still fail the test.

jordandlaman commented 6 years ago

I am going to close as this seems to be the environment I am trying to run. I solved the issue by diving further into the /pkmslogout endpoint. It was calling some adobe service that was using http.responseText and I used blacklistHosts in the cypress.json to block their endpoint. While not a fix for cypress not swallowing the error it has hacked a fix for my testing needs. From the searching I have done online I am not sure if the cypress dev team could investigate any further into this as I can't create a repo for them to diagnose (company env) . I am attempting to get my team and company to adopt cypress as their primary e2e testing framework and as such the premium support model may be in our future but not currently. Hopefully this might help anyone who runs in to a problem that is similar.

jennifer-shehane commented 6 years ago

Yeah, unfortunately it is very difficult to look into an issue without a reproducible example. 🙁

kashif-afk commented 1 year ago

hi im also facing this issue here is my code

describe('template spec', () =>{
  it('passes', () => {
    cy.visit('https://test.nexelus.net/Nexelus-QA-Verification') 
    cy.get('#ctl00_MainContentPlaceHolder_username').type('kashifh')
    cy.get('#ctl00_MainContentPlaceHolder_password').type('sa')
    cy.get('#aIdLoginButton')
    .should("be.visible")
    .click({timeout:50})
  })
})

even if I visit the link it throws the error and for that i used the code but after pressing the login button im still facing this refrence error and unable to process to next screen image

 Cypress.on('uncaught:exception', (err, runnable) => {
    // returning false here prevents Cypress from
    // failing the test
    return false
  })
jennifer-shehane commented 1 year ago

@kashif-afk This issue is specifically tracking 'http is not defined' error, which you are not seeing. The error you are seeing is being thrown from your application under test.