开发者

Is there a browser-agnostic way to detect client-side script errors with Watin?

开发者 https://www.devze.com 2022-12-20 01:55 出处:网络
We\'re using WatiN to test our web portals.During the course of an E2E test, we\'ll occasionally see client-side script errors on the IE status bar.I\'d like to chain a handler onto the script error e

We're using WatiN to test our web portals. During the course of an E2E test, we'll occasionally see client-side script errors on the IE status bar. I'd like to chain a handler onto the script error event and record the error for later analysis and bug filing.

Problem is, I don't know that there's a global script error event or how to chain into it. And if there's not a browser-agnostic way to accomplish this, I can create MyIE and MyFF subclasses but then this becomes two browser-specific questions.

In essence, I'm thinking of something like this enti开发者_C百科rely made-up call:

browser.ScriptEngine.SetCustomErrorHandler(LogScriptingError);

... where LogScriptErrors is my code that does the obvious.

Many of our client-side scripting errors don't necessarily prevent the test from continuing (a pretty UI element didn't animate, for example, but the underlying form is still submittable), so I'd like to log the error and forge ahead in most cases.


You probably looking for this:

window.onerror=function(message, url, line){logError();};

You can add this code to your pages to handle errors in logError(). but this may not work in all browser(works in IE), check this for browser compatibility:

http://www.quirksmode.org/dom/events/error.html

Or you may try this commercial product:

exceptionhub.com/


You could maybe co-opt the ability to inject eval code (described under "Added Eval functionality") to add a script that caught all errors, not just errors from the eval'ed script. I'm not sure if this would work, but it's an area to explore. Another resource might be this blog post, which discusses how to evaluate Javascript in WatiN.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号