On the initial spec run, with a new browser, the exception is thrown from my application
TypeError: Cannot read property 'page_type' of undefined at getPageType
If I rerun the test, without closing the browser, the test passes and the error is not thrown.
I don't expect you to solve my applications errors. However, this does not occur in a local chrome window, might be useful.
The real issue is when the uncaught exception is thrown by my application it stops Cypress from executing the test and any other tests. However, the page still loads. (See the video attached)
If I am correct, Cypress should not stop with application errors with
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
})
in commands.js, which it is
Cypress does not stop executing when the application throws an exception.
Okay so there are two issues here:
@brian-mann Sorry, the uncaught exception is being thrown by my application. However Cypress should not stop because of that, I update my issue.
I know why the error is being thrown on my application, kind of. I know the line it is breaking on and why. Not exactly sure on why the code isn't running though.
If you want I can post that information also?
Can you prove that is happening? Put a debugger in the uncaught:exception
event handler to prove Cypress is catching this as a failure.
Alternatively just bind to Cypress.on('fail', (err) => debugger)
and this will show you the exact error and stack trace wheret his originated.
Both
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
debugger
return false
})
Cypress.on('fail', (err) => {
debugger
})
Did not trigger the debugger
did you have dev tools open before the tests ran?
I'm 100% sure the fail
event will absolutely be caught because Cypress is failing the test. You either didn't have dev tools open soon enough or you aren't adding your event listeners in the right place.
Where are you putting them?
I added
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});
to support/index.js and tests fail anyways because of app's runtime exceptions.
If I use
Cypress.on('fail', (err, runnable) => {return false});
then tests don't fail but they also don't run.
I am facing same problem.
Commands.js
Can you prove that is happening? Put a debugger in the uncaught:exception event handler to prove Cypress is catching this as a failure.
Alternatively just bind to Cypress.on('fail', (err) => debugger) and this will show you the exact error and stack trace wheret his originated.
@asos-arun @Gennadiii Could you both also follow these directions by adding the debugger
?
@jennifer-shehane Thanks a lot for your quick response . I have tried with below code and its not working.
Cypress.on('uncaught:exception', (err, runnable) => {
debugger
return false
})
Cypress.on('fail', (err) => {
debugger
})
Let me know if i am missing anything?
Here is a much more in depth explanation on why the uncaught:exception may not be being hit: https://github.com/cypress-io/cypress/issues/1385#issuecomment-369082559
We will need a reproducible example to truly investigate the issue further.
In my case I get error in Cypress: Cannot read property 'payload' of undefined. But weird thing is that I don't see this error in console. It is caught by Cypress and I can see it in console only if I click it in Cypress panel.
url
url
This code in support/index.js doesn't work:
Cypress.on('uncaught:exception', (err, runnable) => {
console.log(`11111111111111111111111 ${err}`);
debugger;
return false;
});
No log, no debugger.
This code works as expected:
Cypress.on('fail', (err) => {
debugger;
});
But doesn't do what I need to do.
I can't provide environment and exact code since it's a commercial project.
@Gennadiii We are a small team and have invested a lot of time into this issue. We believe this is a problem with Cypress, but we are unable to reproduce or recreate. We will have to have a reproducible repo in order to get this fixed. We will keep this issue open as reference until someone provides how this is happening.
Since you expressed hesitation to provide a reproducible repo because you're working on a commericial project, please note that we do offer premium support for users to prioritize bug fixes, do screensharing, and code reviews. If you're interested in this kind of premium support, we can look directly at how/why this is happening. Please let us know by emailing [email protected].
@brian-mann Thanks for your suggestion we will consider the support option. Meanwhile I have some more info that might help on this one. There are some http queries that site makes.
When everything is fine:
But sometimes one query doesn't get any response at all. And next test fails.
Have you tried setting up a .route()
to listen to the api/config
endpoint and ensuring you .wait()
for that endpoint before continuing with the rest of your test steps? Cypress has no way to know that your view depends on this endpoint's returning otherwise. https://docs.cypress.io/api/commands/wait.html#Alias
Hi, I have a similar problem. I request my application with cy.visit('/'). The application starts fetching data, but most of the times this will result in a 401. (even on the login page). This is expected behaviour, but catching the error with Cypress and returning false still results in the tests not continuing.
Is there a way to recover from an XHR error? This should not affect my tests
I'm dealing with the same issue i think. i can't get it to do a cy.log when it throws an XHR request error. you can see my issue (different issue?) here: #1710
Same here. Getting following error in my application:
Uncaught TypeError: Cannot read property 'getElementsByClassName' of null
Every test is failing due to it even though I have
Cypress.on('uncaught:exception', () => false);
Can you please fix this issue after 1 year of waiting?
+1
My issue was I did not put
cy.on('uncaught:exception', (err) => {
expect(err.message).to.include('Ignoring error for now');
return false;
});
inside of my beforeEach
, which was running it too late to catch an error being caused by a third party ads script in the head of the page. This fixed things up for me
context('Page Availability', () => {
beforeEach(() => {
cy.on('uncaught:exception', (err) => {
expect(err.message).to.include('Ignoring error for now');
return false;
});
});
});
As @bmarti44 stated - please ensure you have your listener set up properly to catch uncaught exceptions within Cypress.
Unfortunately we'll have to close this issue if no reproducible example is provided. Can anyone provide a way to reproduce this?
@mgrybyk Maybe I've missed it. Could you point me to the exact application code and test code that I can run locally on my machine to produce this error?
@jennifer-shehane Just figured out why some people always has it and others have never faced this issue. Cypress can't catch exceptions thrown by 3rd party javascript that is loaded from different origin.
Not sure about reproducible example, it might take some time on my side
@jennifer-shehane got it.
Just create test like this:
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});
won't work here.
Cypress crashes with error like:
Error: Script error. (:0)
at global.onerror (http://www.sickchirpse.com/__cypress/runner/cypress_runner.js:23142:10)
Thanks so much @mgrybyk for providing a reproducible example.
Failing example
it('Does not catch script error', () => {
Cypress.on('uncaught:exception', (err, runnable) => {
throw err
})
cy.visit('http://www.sickchirpse.com/10-of-the-worst-websites-ever/')
})
I'm not sure if this is totally relevant so let me know if not and I'll make a new issue, but thought I'd mention just in case.
I've been facing a very similar issue with exceptions of XHR response objects being undefined and this only arising in beforeAll
hooks.
My current working theory is that when a page is loaded and tests and all assertions pass, Cypress moves onto the next test, and _kills all pending XHR requests_. Resulting in the XHR logic which depends on the Response object to exist (rightly so) fails due to trying to read properties on undefined
etc, and the error shows up in the _next_ beforeEach hook when the callback finally fails.
This only ever happens for us as flake on our CI machines so it's incredibly hard to capture.
@brian-mann is my theory correct that any pending requests are cancelled when assertions pass? Is it possible that pending response callbacks are fired with undefined response objects?
Hey @dannyshaw, go ahead and open a new issue with a reproducible example. Also, be sure you are on the latest version of Cypress (3.1.5), as we have done some work around aborting XHR's behavior.
@jennifer-shehane Just figured out why some people always has it and others have never faced this issue. Cypress can't catch exceptions thrown by 3rd party javascript that is loaded from different origin.
Not sure about reproducible example, it might take some time on my side
I think @mgrybyk is right.
I am using Cypress 3.1.5 (3.2.0 is a showstopper for me due to #3867 ) and I have this problem when a third party js file triggers an exception error.
Any ideas?
Cypress 3.2.0, tests are failing because of 3rd party scripts errors =(
Is there an ETA for a fix?
I am interested as well in ETA.
Cypress 3.3.1 tests also failing because of 3rd party scripts errors
Hello,I hope for your advice:
Besides i have error type "Can't read property 'foo' of undefined" i also have
error type "e.filter is not a function" in random tests for some specs from 3rd party,I think.
'Uncaught:exception' handler is set.
How i can understand i can't do something with this "Can't read property 'foo' of undefined" type of error, but maybe i can do some with "e.filter is not a function" error? Look at screenshoot:
Same thing here (Chrome 73), cypress tests fail due to a 3rd party library error, although I tried placing uncaught:exception
handlers in different locations (describe( beforeEach() )
, it( cy.on() )
, support/index.js Cypress.on()
). They never get triggered by my error which is a Uncaught TypeError: Cannot read property 'getBoundingClientRect' of undefined
. I want cypress to just ignore this error, which used to work in the past via the handler placed in support/index.js
. Would love to be able to do this again as I have no control over the 3rd party library to fix this.
Due to this error, I am not able to execute TestCases.
Even I am using below code in index.js
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false;
})
Using cypress version 3.1.5
and chrome 69
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
console.log('inside Cypress.on ')
return false;
})
Is there any possible workaround/solution for this? Every single one of my tests fails because of this. I've implemented them all with plan on solving this as the last thing. I'd be very disappointed if it was all justa waste of time..
Is there any possible workaround/solution for this? Every single one of my tests fails because of this. I've implemented them all with plan on solving this as the last thing. I'd be very disappointed if it was all just a waste of time.
I used this piece of code
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
console.log('inside Cypress.on ')
return false;
})
If it does not work then please check your web application and make sure that your application should not throw any error in the console in dev tool.
Is there any possible workaround/solution for this? Every single one of my tests fails because of this. I've implemented them all with plan on solving this as the last thing. I'd be very disappointed if it was all just a waste of time.
I used this piece of code
Cypress.on('uncaught:exception', (err, runnable) => { // returning false here prevents Cypress from // failing the test console.log('inside Cypress.on ') return false; })
If it does not work then please check your web application and make sure that your application should not throw any error in the console in dev tool.
Well that's exactly what this thread is about. The piece of code you've pased doesn't trigger in my case and should. I can't fix the error because it's coming from 3rd party lib.
Any update on this from Cypress team? ETA or something?
I found solution for my problem:
I added url of 3rd party from where i
received this errors (some
different types) to cypress.json file:
https://docs.cypress.io/guides/references/configuration.html#Folders-Files
https://docs.cypress.io/guides/references/configuration.html#Command-Line
Maybe this will help someone!
@jennifer-shehane this very simple spec always fails (i corrected the Cypress
-> cy
) and does open the debugger multiple times. shouldn't the spec still pass since it should be ignoring errors coming from the application?
context('User Registration Availability', () => {
beforeEach(() => {
cy.on('fail', (err) => {
debugger;
return false;
});
cy.on('uncaught:exception', (err, runnable) => {
debugger;
return false
});
});
it('should allow registration', () => {
cy.visit('https://www.nba.com/membership/user/login');
});
});
if i add the following to my index.js
, the debugger does open, but the test still fails.
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
debugger;
return false;
});
Cypress.on('fail', (err) => {debugger; return false;});
Hi,
Is there any update on this issue yet?
I am also facing a similar issue. Logs below:
Uncaught TypeError: Cannot read property 'find' of undefined
This error originated from your application code, not from Cypress.
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.
=============================================================
I have added the following in support/index.js:
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
})
I can't believe it's open for 2 years and there's still no solution for this bug 😮
Think yourselves lucky. This only happens inside of jenkins inside of docker for me. I really have nowhere to go, just 2 weeks work on the shelf after saying we must use Cypress!
I can't even see/scrape the console.
You can just switch to https://webdriver.io that does everything Cypress can for free and actually has much more features, also it supports puppeteer so you don't need to worry about browser driver, and of course it works well in docker with any screen size, it can run headless chrome, it doesn't fail on 3rd party script error, it has proper parallelisation, it fully supports all mocha features, it supports corporate proxy, it work properly with reporters and much more.
Hi @jennifer-shehane,
Is there ANY update on this issue. This is one of the most critical bugs open on this one I guess. It is truly a deal breaker for me as you just can not move forward with testing if something like this breaks your test and does not let the page load.
Does cypress atleast have a hack or a work around?
Ok, I've found the issue. We don't have a handler on top.onerror
, only on the spec iframe and app iframe, and some errors will bubble straight to top.
mocha
is registering a handler on top.onerror
when it's loaded in, hence the failing test but no uncaught:exception
emission. I'll open a PR to fix
your issue may be solved by the following workaround, but there are still edge cases: in your spec file or support/index.js
:
// ignore uncaught exceptions
Cypress.on('uncaught:exception', (err) => {
return false
})
// patch Cypress top.onerror
Object.defineProperty(top, 'onerror', {
value: window.onerror,
})
Oh my
Sent from my iPhone
On Sep 24, 2019, at 17:22, Ben Kucera notifications@github.com wrote:
In the meantime, add this to the top of your spec file or support/index.js:
// ignore uncaught exceptions
Cypress.on('uncaught:exception', (err) => {
return false
})// patch Cypress top.onerror
Object.defineProperty(top, 'onerror', {
value: window.onerror,
})
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
OFFICIAL WORKAROUND
it didn't help, still same issue
@xlenz tested against the only reproducible test case in this thread (https://github.com/cypress-io/cypress/issues/987#issuecomment-523707229).
Kindly provide yours so we can get this figured out.
@xlenz Please provide a reproducible example of the issue you are having that was not fixed by the workaround - we really want to make sure our next release addresses all edge cases. Thank you.
@jennifer-shehane @Bkucera you are right that reproducible example is needed, sorry to say I'm not able to provide you with it as far as it's only reproducible with my app, spent already couple of hours, tried different approaches...
@Bkucera thank you for providing with official workaround, it works in some cases for me.
I am also facing this issue and what I figured out is that whenever I am trying to fill a form and click on save button which has a 'onClick = javascript function'
attached, then Cypress catches application error.
In my application, its like this -onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphMain$btnDoSave", "", true, "Trade", ""))"
@jennifer-shehane You might be able to replicate if you create a similar environment.
Hey All
who ever is facing this issue, You can try the following solution. I also struggled for a week because of this. It worked for me, you need to add the below code along with uncaught exception command in your support/index.js
.
In your sepc files:
cy.visit(url, {
onBeforeLoad: (win) => {
win.onerror = null // this is a hack to ignore the uncaught exceptions
}
});
@automationJatinder and Cypress.on('uncaught:exception')
is not fired?
Any news about fixing this one?
Both handlers added to support/index
but didnt catch the error...
Cypress.on('uncaught:exception', (err, runnable) => false);
Object.defineProperty(top, 'onerror', {
value: window.onerror,
})
@automationJatinder and
Cypress.on('uncaught:exception')
is not fired?
No.
@maximkoshelenko Please share your code where you are facing error. I think I have solution for the same.
@maximkoshelenko Please share your code where you are facing error. I think I have solution for the same.
@automationJatinder Thanks. Here you go
shortCypress.zip
I have copied the same test a couple of times because the error may occur or may not occur during one execution.
@maximkoshelenko awesome, I was able to reproduce with this. We're not catching errors thrown by wrapped setTimeout
calls. So I'll add that to the fixing PR
@Bkucera Super. Hope fix will be published soon :) my POC project are burning because of that issue.
The code for this is done in cypress-io/cypress#5249, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Released in 3.6.0
.
@jennifer-shehane I have been following this thread and I am still experiencing this issue in version 4.0.0. I noticed that it is pointing out issues in node_modules in node_modules which doesn't make sense. We successfully used our custom npm package on our api tests.
@azaeng04 if you are experiencing this issue, please open a new issue with fully reproducible example we can run
@bahmutov I can show an image of what I am seeing and I can mention the node_module where the error is being thrown
@bahmutov I can show an image of what I am seeing and I can mention the node_module where the error is being thrown
Not sure why it would be pointing to a node_module in the node_modules? And the fs-extra package to be exact.
Not sure what we can determine from just images. A reproducible example would nice IF this is a bug in Cypress and not an artifact of bundling specs or your own application
Sent from my iPhone
On Mar 3, 2020, at 14:39, Azariah notifications@github.com wrote:
@bahmutov I can show an image of what I am seeing and I can mention the node_module where the error is being thrownNot sure why it would be pointing to a node_module in the node_modules? And the fs-extra package to be exact.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
@bahmutov it seems to be pointing out errors in the fs-extra
package. Just calling fs.copy
throws the following error:
Uncaught (in promise) TypeError: fs.stat is not a function
This package is in a custom package of ours and Cypress seems to throw an error and fail because of a variable(s) that is not a function as per the above.
Help on this would be much appreciated @jennifer-shehane @bahmutov @brian-mann
@azaeng04 this issue has been closed, so any comments here are usually non-productive. Second, your issue seems to be unrelated to the original - it seems you are trying to run Node file commands from Cypress tests which is impossible (Cypress tests run in the browser). If you want to use fs-extra
package, please move these commands to plugins file and call them using https://on.cypress.io/task command
This issue will be closed to further comment as the exact issue here was resolved and tested in 3.6.0.
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.
Also, check out our community chat, it can be helpful for debugging or answering questions on how to use Cypress.
Most helpful comment
Same here. Getting following error in my application:
Uncaught TypeError: Cannot read property 'getElementsByClassName' of null
Every test is failing due to it even though I have
Cypress.on('uncaught:exception', () => false);
Can you please fix this issue after 1 year of waiting?