Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I'm using a technique I found here, to capture javascript errors for testing purposes. It's a technique that is frequentlyfrequently recommendedrecommended on Stack OverflowStack 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

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

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
added 572 characters in body
Source Link

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

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. If anyone has any suggestions, I'd surely be grateful.

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
Source Link

Inconsistent results when capturing javascript errors with WebDriver

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. If anyone has any suggestions, I'd surely be grateful.