コード例 #1
0
        public static void SwitchTo(string windowTitle, bool partialMatch = false)
        {
            RetriableRunner.Run(() =>
            {
                var handles = Web.PortalDriver.WindowHandles;

                try {
                    var handle = partialMatch
                                        ? handles.First(h => Web.PortalDriver.SwitchTo().Window(h).Title.Contains(windowTitle))
                                        : handles.First(h => Web.PortalDriver.SwitchTo().Window(h).Title == windowTitle);
                    Web.PortalDriver.SwitchTo().Window(handle);
                } catch (Exception) {
                    var windowTitles = handles.Select(h => Web.PortalDriver.SwitchTo().Window(h).Title);
                    var titleList    = String.Join(",", windowTitles);
                    Trace.WriteLine("unable to find '" + windowTitle + "'");
                    Trace.WriteLine("available windows: [" + titleList + "]");
                    throw;
                }
                var wait = new WebDriverWait(Web.PortalDriver, TimeSpan.FromSeconds(10));
                try
                {
                    wait.Until(ExpectedConditions.TitleContains(windowTitle));
                }
                catch (Exception ex)
                {
                    ExceptionHandler.HandleException(ex, false);
                }
            });
        }
コード例 #2
0
        public static Boolean IsOpen(String windowTitle, bool partialMatch = false)
        {
            var currentWindow = CCPage.CurrentWindowTitle;
            var count         = 0;

            RetriableRunner.Run(() =>
            {
                var handles = Web.PortalDriver.WindowHandles;
                count       = partialMatch
                                        ? handles.Count(h => Web.PortalDriver.SwitchTo().Window(h).Title.Contains(windowTitle))
                                        : handles.Count(h => Web.PortalDriver.SwitchTo().Window(h).Title == windowTitle);
            });
            SwitchTo(currentWindow);
            return(count > 0);
        }
コード例 #3
0
        /// <summary>
        /// Called every time to check the existence of an element, sets the elementIdentifier used for logging purposes.
        /// </summary>
        /// <returns></returns>
        public bool Initialize()
        {
            if (CCByLocator != null)
            {
                Trace.WriteLine(String.Format("Finding element with By identifier '{0}'", CCByLocator));
                return(RetriableRunner.Run(() =>
                {
                    Trace.WriteLine("... " + CCByLocator);
                    webElement = Web.PortalDriver.FindElement(CCByLocator);
                    ElementIdentifier = webElement.TagName;
                    return webElement != null;
                }));
            }

            // this path assumes element has already been found (used by getDescendents)
            return(webElement != null);
        }
コード例 #4
0
        /// <summary>
        /// Wait for page load.  Use if Selenium blocking API is not sufficient.
        /// </summary>
        public static void WaitForPageLoad(int msTimeout)
        {
            RetriableRunner.Run(() => {
                var isPageLoaded = false;
                var endTime      = DateTime.Now.AddMilliseconds(msTimeout);

                while (isPageLoaded == false && DateTime.Now < endTime)
                {
                    isPageLoaded = JavascriptExecutor.Execute <string>("return document.readyState").Equals("complete");
                    System.Threading.Thread.Sleep(100);
                }

                if (isPageLoaded == false)
                {
                    throw new Exception("Timeout period of " + msTimeout + "ms expired for page load to finish.");
                }

                return(string.Empty);
            });
        }
コード例 #5
0
 public static void Until(Func <IWebDriver, bool> func)
 {
     RetriableRunner.Run(() => Pause.Until(func));
 }