/// <summary>
        /// Waits for a <see cref="List{T}"/>/<<see cref="IWebElement"/>/> to be visible in the page
        /// </summary>
        /// <param name="locator">The <see cref="List"/>/<<see cref="By"/>/> locators of the <see cref="IWebElement"/>s</param>
        /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
        /// <returns><see langword="true"/> if the <see cref="IWebElement"/> is visible; otherwise, <see langword="false"/></returns>
        public static bool WaitUntilVisible(this ISearchContext iSearchContext, List <By> locators, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
        {
            var failedLocs = new List <By>();

            foreach (var loc in locators)
            {
                if (!iSearchContext.WaitUntil(ExpectedCondition.ElementIsVisible(loc), maxWaitTimeInSeconds))
                {
                    failedLocs.Add(loc);
                }
            }
            if (failedLocs.Count == 0)
            {
                return(true);
            }
            if (failedLocs.Count > 0 && maxWaitTimeInSeconds > 1)
            {
                return(iSearchContext.WaitUntilVisible(failedLocs, maxWaitTimeInSeconds / 2));
            }
            if (failedLocs.Count > 0 && maxWaitTimeInSeconds <= 1)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private static Func <IWebDriver, IWebElement> GetWebelementFunc(By locator, ExpectedCondition expectedCondition)
        {
            Func <IWebDriver, IWebElement> getWebelementFunc;

            switch (expectedCondition)
            {
            case ExpectedCondition.ElementExists:
                getWebelementFunc = ExpectedConditions.ElementExists(locator);
                break;

            case ExpectedCondition.ElementIsVisible:
                getWebelementFunc = ExpectedConditions.ElementIsVisible(locator);
                break;

            default:
                throw new NotSupportedException(
                          string.Format(
                              "This method {0} does not support the selected option of the enum {1}. Please select either {2} or {3}",
                              "FindByClassName",
                              expectedCondition,
                              "ElementExists",
                              "ElementIsVisible"
                              ));
            }
            return(getWebelementFunc);
        }
Exemplo n.º 3
0
 public void TestClickWaitForCondition(By locator)
 {
     _ajaxyControlPage.GreenRadio.Click();
     _ajaxyControlPage.NewLabelText.SendKeys("TestIsPageLoaded");
     _ajaxyControlPage.SubmitButton.ClickWaitForCondition(Driver, ExpectedCondition.ElementExists(locator));
     Assert.AreEqual(true, Driver.ElementExists(locator));
 }
Exemplo n.º 4
0
        public virtual IWebElement FindByClassNameClick(
            string className,
            ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
            int?seconds = null)
        {
            IWebElement element = FindByClassName(className, expectedCondition, seconds);

            return(ClickWebElement(className, seconds, element, FinderStrategy.ClassName));
        }
 /// <summary>
 /// Waits for a <see cref="IWebElement"/> to not be visible in the page
 /// </summary>
 /// <param name="locator">The <see cref="By"/> locator of the <see cref="IWebElement"/></param>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become not visible</param>
 /// <returns><see langword="true"/> if the <see cref="IWebElement"/> is not visible; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilNotVisible(this ISearchContext iSearchContext, By locator, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     if (!iSearchContext.ElementExists(locator))
     {
         Console.WriteLine("Element did not exist, element cannot be visable, by: {0}", locator);
         return(true);
     }
     return(iSearchContext.WaitUntil(ExpectedCondition.ElementNotVisible(locator), maxWaitTimeInSeconds));
 }
Exemplo n.º 6
0
        public virtual IWebElement FindByXPathClick(
            string domElement,
            ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
            int?seconds = null)
        {
            IWebElement element = FindByXPath(domElement, expectedCondition, seconds);

            return(ClickWebElement(domElement, seconds, element, FinderStrategy.XPath));
        }
Exemplo n.º 7
0
        public virtual IWebElement FindByXPath(
            string domElement,
            ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
            int?seconds = null)
        {
            Func <IWebDriver, IWebElement> getWebelementFunc = GetWebelementFunc(By.XPath(domElement), expectedCondition);

            return(FindWebElement(By.XPath(domElement), seconds, getWebelementFunc));
        }
Exemplo n.º 8
0
        public virtual IWebElement FindByCssSelectorClick(
            string cssSelector,
            ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
            int?seconds = null)
        {
            IWebElement element = FindByCssSelector(cssSelector, expectedCondition, seconds);

            return(ClickWebElement(cssSelector, seconds, element, FinderStrategy.Css));
        }
Exemplo n.º 9
0
        public virtual IWebElement FindByCssSelector(
            string cssSelector,
            ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
            int?seconds = null)
        {
            Func <IWebDriver, IWebElement> getWebelementFunc = GetWebelementFunc(By.CssSelector(cssSelector), expectedCondition);

            return(FindWebElement(By.CssSelector(cssSelector), seconds, getWebelementFunc));
        }
 /// <summary>
 /// Waits for a <see cref="IWebElement"/> to not contain specific text
 /// </summary>
 /// <param name="locator">The <see cref="By"/> locator of the <see cref="IWebElement"/></param>
 /// <param name="text">The text it should contain</param>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
 /// <returns><see langword="true"/> if the <see cref="IWebElement"/> not contains the text; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilTextNotContains(this ISearchContext iSearchContext, By locator, string text, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     if (!iSearchContext.WaitUntilExists(locator, maxWaitTimeInSeconds))
     {
         Console.WriteLine("Element did not exist, could not compare text of element with locator: {0}", locator);
         return(false);
     }
     return(iSearchContext.WaitUntil(ExpectedCondition.ElementTextNotContains(locator, text), maxWaitTimeInSeconds));
 }
 /// <summary>
 /// Waits for a <see cref="IWebElement"/> to not have specific attribute value
 /// </summary>
 /// <param name="locator">The <see cref="By"/> locator of the <see cref="IWebElement"/></param>
 /// <param name="text">The value the <see cref="IWebElement"/> attribute not should equal</param>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
 /// <returns><see langword="true"/> if the <see cref="IWebElement"/> attribute value is not a match; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilAttributeNotEquals(this ISearchContext iSearchContext, By locator, string htmlTagAttribute,
                                                string attributeValue, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     if (!iSearchContext.WaitUntilExists(locator, maxWaitTimeInSeconds))
     {
         return(false);
     }
     return(iSearchContext.WaitUntil(ExpectedCondition.ElementAttributeNotEquals(locator, htmlTagAttribute, attributeValue), maxWaitTimeInSeconds));
 }
Exemplo n.º 12
0
        public virtual IWebElement FindByClassName(
            string className,
            ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
            int?seconds = null)
        {
            Func <IWebDriver, IWebElement> webelementFunc = GetWebelementFunc(By.ClassName(className), expectedCondition);

            return(FindWebElement(By.ClassName(className), seconds, webelementFunc));
        }
Exemplo n.º 13
0
        public bool FindByXPathClickWithRetries(string domElement, ExpectedCondition expectedCondition = ExpectedCondition.ElementIsVisible,
                                                int?seconds = null, int?numberOfRetries = 20)
        {
            Action action = () =>
            {
                IWebElement element = FindByXPath(domElement, expectedCondition, seconds);
                ClickWebElement(domElement, seconds, element, FinderStrategy.XPath);
            };

            return(ExecuteActionWithRetries(action, numberOfRetries));
        }
Exemplo n.º 14
0
 public static void ForElementTOBeVisible(By elementLocator, int timeout = 0)
 {
     timeout = timeout == 0 ? int.Parse(ConfigurationManager.AppSettings["waitTimeOut"]) : timeout;
     try
     {
         // SeleniumExecutors.GetWaitDriver(timeout).Until(ExpectedConditions.)
         SeleniumExecutors.GetWaitDriver(timeout).Until(ExpectedCondition.ElementIsVisble(elementLocator));
         // SeleniumExecutors.GetWaitDriver(timeout).Until(Expected)
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element with locator:'{elementLocator}' wasn't visible within timeout limlit", e);
     }
 }
        public static bool WaitUntilRested(this ISearchContext iSearchContext, Func <ISearchContext, bool> condition, int restTimeInSeconds, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
        {
            if (restTimeInSeconds > maxWaitTimeInSeconds)
            {
                throw new ArgumentException("The restTimeInSeconds cannot be greater than the maxWaitTimeInSeconds");
            }
            bool rested   = false;
            var  timeSpan = new Stopwatch();

            timeSpan.Start();
            while (timeSpan.Elapsed.Seconds <= 10 && rested == false)
            {
                if (iSearchContext.WaitUntil(ExpectedCondition.ElementRested(condition, restTimeInSeconds), maxWaitTimeInSeconds))
                {
                    rested = true;
                }
            }
            timeSpan.Stop();

            return(rested);
        }
 public static bool WaitUntilAlertTextContains(this IWebDriver iWebDriver, string text, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     return(DriverWaitUntil(iWebDriver, ExpectedCondition.AlertTextContains(text), maxWaitTimeInSeconds));
 }
 /// <summary>
 /// Waits for an IAlert
 /// </summary>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
 /// <returns><see langword="true"/> if the alert exists; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilAlertExists(this IWebDriver iWebDriver, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     return(DriverWaitUntil(iWebDriver, ExpectedCondition.AlertIsPresent(), maxWaitTimeInSeconds));
 }
 /// <summary>
 /// Waits for a page title to be a specific text
 /// </summary>
 /// <param name="title">The title of the page</param>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
 /// <returns><see langword="true"/> if the title is a match; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilTitleIs(this IWebDriver iWebDriver, string title, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     return(iWebDriver.DriverWaitUntil(ExpectedCondition.TitleIs(title), maxWaitTimeInSeconds));
 }
 /// <summary>
 /// Waits for a <see cref="IWebElement"/> to have contain specific text
 /// </summary>
 /// <param name="locator">The <see cref="By"/> locator of the <see cref="IWebElement"/></param>
 /// <param name="text">The text it should contain</param>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
 /// <returns><see langword="true"/> if the <see cref="IWebElement"/> contains the text; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilTextContains(this ISearchContext iSearchContext, By locator, string text, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     return(iSearchContext.WaitUntil(ExpectedCondition.ElementTextContains(locator, text), maxWaitTimeInSeconds));
 }
 /// <summary>
 /// Waits for a <see cref="IWebElement"/> to be visible in the page
 /// </summary>
 /// <param name="locator">The <see cref="By"/> locator of the <see cref="IWebElement"/></param>
 /// <param name="maxWaitTimeInSeconds">Maximum amount of seconds as <see cref="int"/> to wait for the <see cref="IWebElement"/> to become visible</param>
 /// <returns><see langword="true"/> if the <see cref="IWebElement"/> is visible; otherwise, <see langword="false"/></returns>
 public static bool WaitUntilVisible(this ISearchContext iSearchContext, By locator, int maxWaitTimeInSeconds = GlobalConstants.MaxWaitTimeInSeconds)
 {
     return(iSearchContext.WaitUntil(ExpectedCondition.ElementIsVisible(locator), maxWaitTimeInSeconds));
 }