コード例 #1
0
        /// <summary>
        ///
        /// This one is a tricky one. I will preface it by saying that for the most part you should not need this method.
        /// Most Selenium methods (Click, Submit, FindElement, etc) use the implicit timeout to wait for an element to appear
        /// and then wait until the page finishes loading before returning control back to your program. Usually if you feel
        /// like you need to wait for the page to load, it is better to try adjusting the implicit wait time first or use the
        /// WaitWebDriver class. Now, with those disclamers, sometimes it can be useful to have the ability to wait for the page
        /// to finish loading.For example, SendKeys does not wait for the page to finish loading.
        ///
        /// element.SendKeys(Keys.Enter);
        /// driver.WaitForPageToLoad();
        /// Same thing as
        /// element.Click();
        ///
        /// </summary>
        /// <param name="driver">Current Web Driver</param>
        public static void WaitForPageToLoad(this IWebDriver driver)
        {
            if (!(driver is IJavaScriptExecutor javascript))
            {
                throw new ArgumentException("Driver must support javascript execution", nameof(driver));
            }

            //To get around the pop up issue, particualrly in internet explorer
            //https://stackoverflow.com/questions/6852732/selenium-webdriver-how-to-close-browser-popup
            javascript.ExecuteScript("window.onbeforeunload = function(e){};");

            WebTestManager.Instance().BrowserWait.Until((d) =>
            {
                try
                {
                    string readyState = javascript.ExecuteScript("if (document.readyState) return document.readyState;").ToString();
                    return(readyState.ToLower() == "complete");
                }
                catch (InvalidOperationException e)
                {
                    //Window is no longer available
                    return(e.Message.ToLower().Contains("unable to get browser"));
                }
                catch (WebDriverException e)
                {
                    //Browser is no longer available
                    return(e.Message.ToLower().Contains("unable to connect"));
                }
                catch
                {
                    return(false);
                }
            });
        }
コード例 #2
0
 public static bool TryWait(this IWebDriver driver, By by)
 {
     try
     {
         WebTestManager.Instance().BrowserWait
         .Until(d => d.FindElement(by));
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #3
0
        public static bool VisibleWait(this IWebElement elm, uint timeOut = 10, uint polling = 550)
        {
            try
            {
                var wait = new DefaultWait <IWebElement>(elm)
                {
                    Timeout         = TimeSpan.FromSeconds(timeOut),
                    PollingInterval = TimeSpan.FromMilliseconds(polling)
                };

                wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(WebDriverException), typeof(StaleElementReferenceException));

                return(wait.Until(element => element.Displayed && element.Enabled));
            }
            catch (System.Exception exp)
            {
                var loggingUtility = WebTestManager.Instance().LoggingUtility;
                loggingUtility.Warning(exp.Message + exp.StackTrace);
                return(false);
            }
        }
コード例 #4
0
 public static void Cleanup()
 {
     WebTestManager.Instance().OnDisposeAssemblyDependencies();
 }
コード例 #5
0
 public static void Initialise(TestContext testContext)
 {
     WebTestManager.Instance().OnInitialiseAssemblyDependencies(testContext);
 }
コード例 #6
0
 public void Init()
 {
     WebTestManager.Instance().OnInitialiseAssemblyDependencies(TestContext.Parameters);
 }
コード例 #7
0
 public static void Wait(this IWebDriver driver, By by)
 {
     WebTestManager.Instance().BrowserWait
     .Until(d => d.FindElement(by));
 }
コード例 #8
0
 /// <summary>
 ///     Waits for a specified function to be satisfied within the specified timeout.
 /// </summary>
 /// <param name="driver">The Web Driver</param>
 /// <param name="func">The function to be satisfied</param>
 public static void Wait(this IWebDriver driver, Func <IWebDriver, IWebElement> func)
 {
     WebTestManager.Instance().BrowserWait
     .Until(func);
 }