Example #1
0
        /// <summary>
        /// Executes the code to test detection of JavaScript errors from the browser.
        /// </summary>
        /// <param name="driver">The driver to use with the browser.</param>
        public void TestJavaScriptErrors(IWebDriver driver)
        {
            // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
            // which provides a page that contains a JavaScript error on page load.
            string url = this.builder.BuildUrl("javascript_error");

            Console.WriteLine("Navigating to {0}", url);
            driver.NavigateToWithErrorDetection(url);
            IList <string> javaScriptErrors = driver.GetJavaScriptErrors();

            if (javaScriptErrors == null)
            {
                Console.WriteLine("Could not access JavaScript errors collection. This is a catastrophic failure.");
            }
            else
            {
                if (javaScriptErrors.Count > 0)
                {
                    Console.WriteLine("Found the following JavaScript errors on the page:");
                    foreach (string javaScriptError in javaScriptErrors)
                    {
                        Console.WriteLine(javaScriptError);
                    }
                }
                else
                {
                    Console.WriteLine("No JavaScript errors found on the page.");
                }
            }
        }
        /// <summary>
        /// Executes the code to test collection of JavaScript errors on the page.
        /// </summary>
        /// <param name="driver">The driver to use with the browser.</param>
        private static void TestJavaScriptErrors(IWebDriver driver)
        {
            // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
            // which provides pages that return various HTTP status codes.
            string url = "http://the-internet.herokuapp.com/javascript_error";

            Console.WriteLine("Navigating to {0}", url);
            driver.NavigateTo(url);
            IList <string> javaScriptErrors = driver.GetJavaScriptErrors();

            if (javaScriptErrors == null)
            {
                Console.WriteLine("Could not access JavaScript errors collection. This is a catastrophic failure.");
            }
            else
            {
                if (javaScriptErrors.Count > 0)
                {
                    Console.WriteLine("Found the following JavaScript errors on the page:");
                    foreach (string javaScriptError in javaScriptErrors)
                    {
                        Console.WriteLine(javaScriptError);
                    }
                }
                else
                {
                    Console.WriteLine("No JavaScript errors found on the page.");
                }
            }
        }
        public static bool CheckJavaScriptError(this IWebDriver driver, string url)
        {
            driver.Url = url;
            Console.WriteLine("Testing: " + url);
            IEnumerable <JavaScriptError> javaScriptErrors = driver.GetJavaScriptErrors();

            bool hasError = false;

            foreach (var x in javaScriptErrors)
            {
                PrintErrorMessage(x);

                if (x.ErrorMessage.Contains("Error:"))
                {
                    hasError = true;
                }
            }
            return(hasError);
        }
 /// <summary>
 /// Executes the code to test collection of JavaScript errors on the page.
 /// </summary>
 /// <param name="driver">The driver to use with the browser.</param>
 private static void TestJavaScriptErrors(IWebDriver driver)
 {
     // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
     // which provides pages that return various HTTP status codes.
     string url = "http://the-internet.herokuapp.com/javascript_error";
     Console.WriteLine("Navigating to {0}", url);
     driver.NavigateTo(url);
     IList<string> javaScriptErrors = driver.GetJavaScriptErrors();
     if (javaScriptErrors == null)
     {
         Console.WriteLine("Could not access JavaScript errors collection. This is a catastrophic failure.");
     }
     else
     {
         if (javaScriptErrors.Count > 0)
         {
             Console.WriteLine("Found the following JavaScript errors on the page:");
             foreach (string javaScriptError in javaScriptErrors)
             {
                 Console.WriteLine(javaScriptError);
             }
         }
         else
         {
             Console.WriteLine("No JavaScript errors found on the page.");
         }
     }
 }