Reputation: 641
I'm testing with Selenium webdriver using C#. How can I log all JavaScript errors that could happen through my tests?
Upvotes: 3
Views: 3402
Reputation: 585
Regarding some of the comments to the above reply, you should get the javascript errors generated during test execution by using the webdrivers built-in methods for this:
Driver().Manage().Logs.GetLog();
By specifying what log you are interested in you can get the browser log, that is:
Driver().Manage().Logs.GetLog(LogType.Browser);
That will return a ReadOnlyCollection with all the log entries from the webdriver browser window.
Upvotes: 0
Reputation: 15397
That depends what you mean, if you want to capture javascript errors generated in your code when you use:
((IJavaScriptExecutor)_driver).ExecuteScript("some javascript code here")
Then just wrap those statements in a try/catch/finally and log the exception.
If you want to capture javascript errors generated by the browser, then the short answer is: you can't easily do so.
The long answer:
SetPreference()
so that it will automatically export the console to a location of your choiceIf you need some sample code, let me know and I'll give you the really long answer...
Upvotes: 3