private static void Click(Func <IWebDriver, IWebElement> findFunction, BasicPageElement pageElement)
        {
            IWebElement   element = null;
            TimeSpan      timeout = new TimeSpan(0, 0, Settings.Default.TestTimeout);
            WebDriverWait wait    = new WebDriverWait(pageElement.WebDriver, timeout);

            if (pageElement.ParentPageObject.PageSettings.PageUsesJquery && !pageElement.ParentPageObject.PageSettings.HasEndlessJQueryAnimation)
            {
                string errorMessage = null;
                try
                {
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    wait.Timeout = new TimeSpan(0, 0, 0, 0, Settings.Default.WatiForAnimationsToComplete);
                    wait.Until(driver => AllAnimationsFinished(driver, pageElement.ParentPageObject.PageSettings, out errorMessage));
                    TestLog.Add("Waited " + stopwatch.ElapsedMilliseconds + " milliseconds for all anmiations to complete.");
                }
                catch (WebDriverTimeoutException e)
                {
                    throw new TimeoutException(errorMessage + "  Waited " + Settings.Default.WatiForAnimationsToComplete + " milliseconds to complete animations. Inner-exception: ", e);
                }
            }

            try
            {
                wait.Timeout = timeout;
                element      = wait.Until(findFunction);
            }
            catch (WebDriverTimeoutException e)
            {
                string timeoutMessage = BuildTimeoutMessage(pageElement.By, Visibility.Hidden, e.Message, Settings.Default.TestTimeout, element);
                throw new TimeoutException(timeoutMessage, e);
            }

            element.Click();
        }
        private static bool DoTabSwitchWithIndex(int index, IWebDriver webDriver, string urlSegment, AsyncWebDriverCalls asyncCalls,
                                                 ReadOnlyCollection <string> windowHandles)
        {
            string        windowHandle      = windowHandles[index];
            Task <string> getCurrentUrlTask = asyncCalls.GetCurrentUrlTask(webDriver);

            getCurrentUrlTask.Wait();
            webDriver.SwitchTo().Window(windowHandle);

            Task <bool> nextUrlTask = asyncCalls.TabActuallySwitched(webDriver, urlSegment, getCurrentUrlTask.Result);

            nextUrlTask.Wait();

            if (!nextUrlTask.Result)
            {
                return(false);
            }

            Task <string> task = asyncCalls.GetCurrentUrlTask(webDriver);

            task.Wait();
            string urlAfterSwitch = task.Result;

            TestLog.Add("Switched to tab with url-segment " + urlSegment + ". Full url = " + urlAfterSwitch);
            asyncCalls.WaitWindowMaximize(webDriver);
            return(true);
        }
        /// <summary>
        /// Perfom a safe click on an element
        /// </summary>
        /// <param name="webDriver">the webdriver</param>
        /// <param name="pageElement">the webelement to click</param>
        public static void ClickElement(this IWebDriver webDriver, BasicPageElement pageElement)
        {
            Stopwatch startNew = Stopwatch.StartNew();

            Click(FindAndScrollToElement(pageElement.By, Visibility.Visible, pageElement.ParentPageObject.PageSettings), pageElement);
            startNew.Stop();
            TestLog.Add("Waited " + startNew.ElapsedMilliseconds + " milliseconds to scroll and click element '" + pageElement.By + "'.");
        }
        /// <summary>
        /// Perfom a safe click on an element
        /// </summary>
        /// <param name="webDriver">the webdriver</param>
        /// <param name="pageElement">the webelement to click</param>
        public static void ClickElementWithoutScrolling(this IWebDriver webDriver, BasicPageElement pageElement)
        {
            Stopwatch startNew = Stopwatch.StartNew();

            Click(Find(pageElement.By, Visibility.Visible), pageElement);
            startNew.Stop();
            TestLog.Add("Waited " + startNew.ElapsedMilliseconds + " milliseconds to click element '" + pageElement.By + "'.");
        }
        public void Type(DateTime dateTime)
        {
            CultureInfo currentUiCulture = Thread.CurrentThread.CurrentUICulture;
            string      dateString       = dateTime.ToString("d", currentUiCulture);

            TestLog.Add("FillDate (use culture " + currentUiCulture + "): " + _pageElement.By + " -> " + dateString);
            _pageElement.WebDriver.WaitForElement(_pageElement.By).Type(dateString);
        }
        public void Type(DateTime dateTime)
        {
            Stopwatch     stopwatch = Stopwatch.StartNew();
            WebDriverWait wait      = new WebDriverWait(new SystemClock(), _pageElement.WebDriver, _timeOut, new TimeSpan(0, 0, 0, 0, 500))
            {
                Message = GetErrorMessage()
            };

            wait.Until(InputIsEmptyOrNotExampleText);
            stopwatch.Stop();
            TestLog.Add("Waited " + stopwatch.ElapsedMilliseconds + " milliseconds for input-field to be empty.");
            _fillBehaviour.Type(dateTime);
        }
Exemple #7
0
 public void Click(TimeSpan waitBeforeClick, TimeSpan waitAfterClick)
 {
     if (waitBeforeClick > TimeSpan.Zero)
     {
         Thread.Sleep(waitBeforeClick);
         TestLog.Add("Waited '" + Convert.ToInt32(waitBeforeClick.TotalMilliseconds) + "' milliseconds before click.");
     }
     _pageElement.WebDriver.ClickElement(_pageElement);
     if (waitAfterClick > TimeSpan.Zero)
     {
         Thread.Sleep(waitAfterClick);
         TestLog.Add("Waited '" + Convert.ToInt32(waitAfterClick.TotalMilliseconds) + "' milliseconds after click.");
     }
 }
        public static void SwitchToTab(this IWebDriver webDriver, string urlSegment)
        {
            if (string.IsNullOrWhiteSpace(urlSegment))
            {
                throw new ArgumentNullException();
            }
            AsyncWebDriverCalls asyncCalls = new AsyncWebDriverCalls();
            Task <ReadOnlyCollection <string> > getWindowHandlesTask = asyncCalls.GetWindowHandlesAsync(webDriver);

            getWindowHandlesTask.Wait();
            ReadOnlyCollection <string> windowHandles = getWindowHandlesTask.Result;

            if (windowHandles.Count <= 1)
            {
                TestLog.Add("Only one Tab recognized. Cancelling tabswitch => unnecessary.");
                return;
            }


            TestLog.Add("Try switching to tab with url containing '" + urlSegment + "'. tabcount: " + windowHandles.Count);
            bool tabFound = false;
            int  currentTabWindowIndex = windowHandles.IndexOf(webDriver.CurrentWindowHandle);

            for (int index = currentTabWindowIndex; index <= windowHandles.Count; index++)
            {
                int realIndex = (index + currentTabWindowIndex + 1) % windowHandles.Count;

                if (DoTabSwitchWithIndex(realIndex, webDriver, urlSegment, asyncCalls, windowHandles))
                {
                    tabFound = true;
                    break;
                }
            }
            if (tabFound)
            {
                return;
            }

            TestLog.Add("No window with url containing: " + urlSegment);
            TestLog.Add("Current WindowHandle-Url: " + webDriver.Url);
            throw new Exception("No window with url-segment: '" + urlSegment + "'");
        }
        private static IWebElement WaitForElementImpl(IWebDriver webDriver, By locator, TimeSpan timeout, Visibility visibilityFilter)
        {
            IWebElement element = null;

            WebDriverWait wait = new WebDriverWait(new SystemClock(), webDriver, timeout, new TimeSpan(0, 0, 0, 0, 500));

            try
            {
                Stopwatch startNew = Stopwatch.StartNew();
                element = wait.Until(Find(locator, visibilityFilter));
                startNew.Stop();
                TestLog.Add("Waited " + startNew.ElapsedMilliseconds + " milliseconds to find element '" + locator + "'.");
            }
            catch (WebDriverTimeoutException e)
            {
                string timeoutMessage = BuildTimeoutMessage(locator, visibilityFilter, e.Message, Settings.Default.TestTimeout, element);
                throw new TimeoutException(timeoutMessage, e);
            }

            return(element);
        }
        /// <summary>
        /// Wait for all animations to be finished.
        /// </summary>
        private static bool AllAnimationsFinished(IWebDriver driver, AbstractPageSettings pageSettings, out string errorMessage)
        {
            if (pageSettings.PageUsesJquery && pageSettings.HasEndlessJQueryAnimation)
            {
                errorMessage = "Page has a endless animation. Cannot wait for animations finished.";
                return(true);
            }

            bool jqueryIsLoaded;

            if (pageSettings.PageUsesJquery)
            {
                jqueryIsLoaded = JQueryIsLoaded(driver);
            }
            else
            {
                errorMessage = "Cannot wait for animations, page uses no JQuery. ";
                return(true);
            }
            if (jqueryIsLoaded)
            {
                TestLog.Add("Get all running JQuery animations...");
                ReadOnlyCollection <IWebElement> animatedObjects = driver.ExecuteScript <ReadOnlyCollection <IWebElement> >(pageSettings, "return $(':animated').toArray();");
                if (animatedObjects.Count != 0)
                {
                    errorMessage = "Tried to click but there were still running JQuery animations on the webpage which are not excluded from waiting for them to finish."
                                   + " || Objects still animated: " + GetAnimatedObjectMessage(animatedObjects) + " ||.";
                    return(false);
                }
                errorMessage = string.Empty;
                return(true);
            }

            errorMessage = "JQuery was not loaded. Cannot wait for Animations";
            return(false);
        }
Exemple #11
0
 /// <summary>
 /// Get the inner text of an element
 /// </summary>
 /// <returns>the inner text of the element</returns>
 public new string GetInnerText()
 {
     TestLog.Add("ReadInnerText: " + By);
     return(WebDriver.WaitForElement(By, Visibility.Hidden).Text);
 }
 /// <summary>
 /// Get the inner text of an element
 /// </summary>
 /// <returns>the inner text of the element</returns>
 public string GetInnerText()
 {
     TestLog.Add("ReadInnerText: " + By);
     return(WebDriver.WaitForElement(By).Text);
 }
Exemple #13
0
 public void WaitForSpecificValue(string value)
 {
     TestLog.Add("WaitForSpecificValue: " + By + " should be " + value);
     WebDriver.WaitForElement(By).WaitForSpecificValue(value);
 }
Exemple #14
0
 public string GetValue()
 {
     TestLog.Add("ReadInputValue: " + By);
     return(WebDriver.WaitForElement(By).GetAttribute("value"));
 }
 public void Type(DateTime dateTime)
 {
     TestLog.Add(GetTestLogString());
     _pageElement.Click();
     _fillBehaviour.Type(dateTime);
 }
Exemple #16
0
 public string GetValue()
 {
     TestLog.Add("GetValue: " + By);
     return(new SelectElement(WebDriver.WaitForElement(By)).SelectedOption.GetAttribute("value"));
 }
 public void Type(string text)
 {
     TestLog.Add("Fill: " + _pageElement.By + " -> " + text);
     _pageElement.WebDriver.WaitForElement(_pageElement.By).Type(text);
 }
Exemple #18
0
 public string GetText()
 {
     TestLog.Add("GetText: " + By);
     return(new SelectElement(WebDriver.WaitForElement(By)).SelectedOption.Text);
 }
 public void Type(string text)
 {
     TestLog.Add(GetTestLogString());
     _pageElement.Click();
     _fillBehaviour.Type(text);
 }