2

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

4

2 回答 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.

于 2012-07-09T20:40:33.947 回答
1

我相信你可以使用日志开关

--log-file=<logFile>

如文档中所述:http ://code.google.com/p/selenium/wiki/InternetExplorerDriver

于 2012-07-09T20:05:27.173 回答