示例#1
0
        public static bool IsNotAttribtuePresentFulentWait(IWebElement element, string attribute, int timeoutInSeconds = 10, int pollingInMillisec = 200)
        {
            try
            {
                DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);
                wait.Timeout         = TimeSpan.FromSeconds(timeoutInSeconds);
                wait.PollingInterval = TimeSpan.FromMilliseconds(pollingInMillisec);

                Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
                {
                    if (Helpers.Exists_safely(ele))
                    {
                        if (!IsAttribtuePresent(ele, attribute))
                        {
                            return(true);
                        }
                    }
                    return(false);
                });
                try
                {
                    wait.Until(waiter);
                }
                catch (NoSuchElementException)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Assert.Fail("'Timeout'. Test fail due to: {0}, {1}", ex.Message, ex.InnerException);
                return(false);
            }
        }
示例#2
0
        public static void ClickElementSafly(IWebDriver driver, IWebElement element, int seconds = 15)
        {
            try
            {
                Helpers.FindElement(driver, element);
                DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);
                wait.Timeout         = TimeSpan.FromSeconds(10);//timeoutInSeconds
                wait.PollingInterval = TimeSpan.FromMilliseconds(200);

                Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
                {
                    if (Helpers.Exists_safely(ele))
                    {
                        if (ele.Enabled)
                        {
                            element.Click();
                            return(true);
                        }
                    }
                    return(false);
                });

                wait.Until(waiter);
                //new WebDriverWait(driver, TimeSpan.FromSeconds(seconds)).Until(ExpectedConditions.ElementToBeClickable(element)).Click();
            }
            catch (Exception ex)
            {
                Assert.Fail("Helpers method 'ClickElementSafly'.\nElemement: \n" + element.GetAttribute("outerHTML") + "\n does not clickable.\nElement CssSelector:\n'" +
                            Helpers.GetElementCssSelector(driver, element) + "'\nTest fail due to: {0}, {1}, {2}", ex.Message, ex.InnerException, ex);
            }
        }
示例#3
0
        public static bool FulentWait_notContainsElementAttribute(IWebDriver driver, IWebElement element, string exp_attribute, string exp_value, int timeoutInSeconds = 15, int pollingInMillisec = 200)
        {
            try
            {
                //bool isExpected = false;
                string actual_value;
                DefaultWait <IWebElement> wait = new DefaultWait <IWebElement>(element);
                wait.Timeout         = TimeSpan.FromSeconds(timeoutInSeconds);
                wait.PollingInterval = TimeSpan.FromMilliseconds(pollingInMillisec);

                Func <IWebElement, bool> waiter = new Func <IWebElement, bool>((IWebElement ele) =>
                {
                    if (Helpers.Exists_safely(ele))
                    {
                        if (IsAttribtuePresent(ele, exp_attribute))
                        {
                            actual_value = ele.GetAttribute(exp_attribute).ToString();
                            //Console.WriteLine("Wait, expected no contains attribute: '" + exp_value + "', but was: " + actual_value);
                            if (!actual_value.Contains(exp_value))
                            {
                                //Console.WriteLine("Success, the item has no attribute: " + exp_attribute);
                                //isExpected = true;
                                return(true);
                            }
                        }
                    }
                    return(false);
                });
                //try
                //{
                wait.Until(waiter);//this suchExeception
                //}
                //catch (NoSuchElementException)
                //{
                //Assert.Fail("'Timeout' Locator:\n"+ GetElementCssSelector(driver, element) + "\nFulentWait_notContainsElementAttribute");
                //return false;
                //}
                return(true);
            }
            catch (Exception ex)
            {
                Assert.Fail("'Timeout' Locator:\n" + GetElementCssSelector(driver, element) + "\nTest fail due to: {0}, {1}, {2}", ex.Message, ex.InnerException, ex);
                return(false);
            }
        }