How to capture JS error through out the testcase?

classic Classic list List threaded Threaded
2 messages Options
jyo
Reply | Threaded
Open this post in threaded view
|

How to capture JS error through out the testcase?

jyo
I have to try below statement to capture JS error.Is this the right way or not?
((JavascriptExecutor) driver).executeScript("return window.jsErrors");

To verify JS error on any page through out the testcase,Do i have call this above method on every page through out the test case or Is there a way to it call once and say to check for any JS errors throughout the testcase?



Reply | Threaded
Open this post in threaded view
|

Re: How to capture JS error through out the testcase?

softwaretestingforum
Administrator
I think this is one of the Selenium question which has not been discussed more.
I have never used such mechanism but did you try to execute it on a page which has js errors?

jyo wrote
((JavascriptExecutor) driver).executeScript("return window.jsErrors");
If it works then it might be a way to go about.
I guess you could use a java-listeners to keep check on your pages.  Thought I am not sure how this could be achieved.

There is one Interesting article on catching js errors using Selenium -

http://www.silverwareconsulting.com/index.cfm/2010/6/7/Checking-for-JavaScript-Errors-with-Selenium

In a gist, you need to inject js on every page of site as described in the article. This should be done by development team.
Now to see if it works, have one js error injected to a page explicitly and follow the instruction in article to see if Selenium catches it.

~ seleniumtests.com