Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I'm using a technique I found here, to capture javascript errors for testing purposes. It's a technique that is frequently recommended on Stack Overflow for those who need to catch JavaScript errors on the fly, and it at least got me something I could work with.

The implementation is as follows:

My web dev put the following into a script called "error.js":

window.jsErrors = [];
window.onerror = function(errorMessage) {
    window.jsErrors[window.jsErrors.length] = errorMessage;
}

Which is getting loaded into the of every page, via an include.

I have a method set up to return the collected errors to my tests, as an array, like so:

public static Array JsErrorList(this IWebDriver driver)
{
    try
    {
        return ((IJavaScriptExecutor)driver)
            .ExecuteScript("return window.jsErrors.toString()")
            .ToString().Split(",".ToCharArray());
    }
    catch
    {
        return new string[,] {};
    }
}

When running my tests cross-browser, I've noticed something very odd. On Chrome(18) and Firefox(10) the only thing that ever gets reported back, is the string "Script error." IE(8) is the only browser that reports the actual JavaScript error text.

I wonder if the problem might lie in the way I'm invoking window.jsErorrs, but I'm not sure exactly. Could this be a problem with differences between the browser drivers? What has everyone else's experience been? If anyone has any suggestions, I'd surely be grateful.

My Environment:

  • Windows 7 (64bit)
  • .Net Framework 4.0.30319 (C#)
  • Visual Studio 2010 (10.0.40219.1)
  • Nunit 2.6.12051
  • C# WebDriver 2.20.0
  • InternetExplorerDriver 2.2.0.1
  • ChromeDriver 19
  • Firefox 10
share|improve this question
    
This appears to be related: stackoverflow.com/questions/5913978/… –  user246 Mar 16 '12 at 1:23
    
You're quite right. I was searching for the wrong things. Thanks for pointing this out. –  Greg Gauthier Mar 16 '12 at 12:22

1 Answer 1

up vote 2 down vote accepted

Apologies to all for duplicating this question. Turns out, that indeed, the failing script in question lives on a separate domain than the place where my error.js was being included from. So, it was indeed a cross-domain trigger of "same origin".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.