2

Is it possible to catch and log all JS errors that could happen through my test runs in IE?

2 Answers 2

4

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.onError event 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 the onLoad event.

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ok, maybe exists some kind of a plugin which logged everything goes through IE in some log file?
1

I believe you can use the log switch

--log-file=<logFile>

as explained in the documentation: http://code.google.com/p/selenium/wiki/InternetExplorerDriver

1 Comment

Unfortunately, this won't give the original poster what they're asking for. At the moment, there's no way to log when a JavaScript error occurs in the JavaScript code of the site being tested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.