Is it possible to catch and log all JS errors that could happen through my test runs in IE?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are typically two classes of JavaScript error that one wants to catch when asking a question like this. The first is wanting to catch JavaScript errors in the source code of the website being automated. The second type of error is to attempt to catch JavaScript errors in JavaScript code executed by your WebDriver code. Unfortunately, there is not a good way to catch all JavaScript errors in IE via Selenium WebDriver. This is a common feature request for the library, with an open enhancement in the project’s issue tracker. There are some techniques you can use to make a best effort at catching JavaScript errors, but they all have their limitations.
For the first class of JavaScript error, you can try to inject a script that hooks the
window.onErrorevent in the page. The limitation here is that it will miss any JavaScript errors that occur in scripts that execute before your onError hook is activated. Frequently, this will miss many errors that occur in scripts that are executed during theonLoadevent.For the second class of errors, the way the IE driver executes JavaScript, the script execution engine of IE does not allow us to catch the errors in execution. When the script is executed, if there is an error, the driver receives an HRESULT from the script engine that says, “I already displayed the error in the UI, so I’m not going to give you any further information.” In this case, increasing the logging level of the driver will only tell you that a JavaScript error occurred, but not any other information about the JavaScript error. For this class of error, the development team is actively investigating possible solutions, but there is no clear-cut road forward here, nor is there any timeframe for a change in this behavior.