Beispiel #1
0
        public void SetProductQuantity(string productQuantity, string productName)
        {
            IWebElement product = SeleniumExecutor.GetDriver().FindElement(locators.product(productName));

            product.Clear();
            product.SendKeys(productQuantity);
        }
Beispiel #2
0
        public static bool WaitForUrl(string url, int secondsWait = SeleniumExecutor.Timeout)
        {
            SeleniumExecutor.ChangeWaitTimeout(0);
            bool result = false;

            for (int i = 0; i < 2 * secondsWait; ++i)
            {
                if (SeleniumExecutor.ignoreCurrentTest)
                {
                    Assert.Ignore(SeleniumExecutor.ignoreByNoConnection);
                }

                try
                {
                    if (SeleniumExecutor.GetUrl().Equals(url))
                    {
                        result = true;
                        break;
                    }
                }
                catch (Exception) { }

                System.Threading.Thread.Sleep(500);
            }

            SeleniumExecutor.SetDefaultWaitTimeout();
            return(result);
        }
 public static void BeforeScenario()
 {
     if (TestConfigurationSection.SectionDetails.Browser == BrowserType.Chrome)
     {
         SeleniumExecutor.PrepareForDesktop();
     }
 }
Beispiel #4
0
        public static IList <IWebElement> FindElementsWithWait(By by, int secondsWait = SeleniumExecutor.Timeout)
        {
            SeleniumExecutor.ChangeWaitTimeout(0);
            IWebDriver          driver         = SeleniumExecutor.GetDriver();
            IList <IWebElement> elementsReturn = new List <IWebElement>();

            for (int i = 0; i < 2 * secondsWait; ++i)
            {
                if (SeleniumExecutor.ignoreCurrentTest)
                {
                    Assert.Ignore(SeleniumExecutor.ignoreByNoConnection);
                }

                try
                {
                    elementsReturn = driver.FindElements(by);
                    if (elementsReturn.Count > 0)
                    {
                        break;
                    }
                }
                catch (Exception) { }

                System.Threading.Thread.Sleep(500);
                elementsReturn = new List <IWebElement>();
            }

            SeleniumExecutor.SetDefaultWaitTimeout();
            return(elementsReturn);
        }
Beispiel #5
0
 public void FirstSetUp()
 {
     // Before each test
     SeleniumExecutor.BaseSetUp();
     executor = SeleniumExecutor.GetExecutor();
     executor.OpenPage(SeleniumExecutor.pageDefaultUrl);
 }
Beispiel #6
0
        public static bool WaitForElementToBeStillNotDisplayed(IWebElement e, int secondsWait = 2)
        {
            bool result = true;

            SeleniumExecutor.ChangeWaitTimeout(0);

            for (int i = 0; i < 2 * secondsWait; ++i)
            {
                if (SeleniumExecutor.ignoreCurrentTest)
                {
                    Assert.Ignore(SeleniumExecutor.ignoreByNoConnection);
                }

                try
                {
                    if (e.Displayed == true)
                    {
                        result = false;
                        break;
                    }
                }
                catch (Exception) { }
                System.Threading.Thread.Sleep(500);
            }

            SeleniumExecutor.SetDefaultWaitTimeout();
            return(result);
        }
Beispiel #7
0
        public static IWebElement FindElementWithWait(By by, int secondsWait = SeleniumExecutor.Timeout)
        {
            SeleniumExecutor.ChangeWaitTimeout(0);
            IWebElement elementFind;
            IWebDriver  driver = SeleniumExecutor.GetDriver();

            for (int i = 0; i < 2 * secondsWait; ++i)
            {
                if (SeleniumExecutor.ignoreCurrentTest)
                {
                    Assert.Ignore(SeleniumExecutor.ignoreByNoConnection);
                }

                try
                {
                    elementFind = driver.FindElement(by);
                    SeleniumExecutor.SetDefaultWaitTimeout();
                    return(elementFind);
                }
                catch (Exception) { }

                System.Threading.Thread.Sleep(500);
            }

            SeleniumExecutor.SetDefaultWaitTimeout();
            return(null);
        }
Beispiel #8
0
        public static void ContextClick(this IWebElement objectName)
        {
            Actions actionProvider = new Actions(SeleniumExecutor.GetDriver());

            actionProvider.ContextClick(objectName)
            .Build().Perform();
        }
Beispiel #9
0
        public static String GetAttributeWithWait(this IWebElement e, String attribute)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();

            driver.WaitForNoAjaxRequestsPending();
            return(e.GetAttribute(attribute));
        }
Beispiel #10
0
        public static bool SwitchToWindowWithTitle(this IWebDriver driver, String title)
        {
            if (SeleniumExecutor.GetTitle().Contains(title))
            {
                return(true);
            }

            IWebDriver popup = null;

            SeleniumExecutor.SetWindowIterator();
            IEnumerator <String> windowIterator = SeleniumExecutor.GetWindowIterator();

            while (windowIterator.MoveNext())
            {
                String windowHandle = windowIterator.Current;

                popup = driver.SwitchToWindow(windowHandle);
                if (popup.Title.Contains(title))
                {
                    return(true);
                }
            }

            driver.SwitchToParentWindow();
            return(false);
        }
Beispiel #11
0
        public static IList <IWebElement> FindElementsWithWait(this IWebElement e, By by)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();

            driver.WaitForNoAjaxRequestsPending();
            return(e.FindElements(by));
        }
Beispiel #12
0
        public static void PerformClick(this IWebElement we)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();
            Actions    action = new Actions(driver);

            action.MoveToElement(we).Click().Perform();
        }
Beispiel #13
0
 public void Initialize()
 {
     // Intialize driver
     SeleniumExecutor.Initialize();
     //Get scenario Name
     scenario = featureName.CreateNode <Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
 }
Beispiel #14
0
        public static bool WaitForElementsToBeDisplayedExWithException(IList <IWebElement> e, string element_str, int secondsWait = SeleniumExecutor.Timeout)
        {
            bool result = true;

            SeleniumExecutor.ChangeWaitTimeout(0);

            try
            {
                if (!WaitForElementToBeDisplayedEx(e[0], secondsWait))
                {
                    result = false;
                }
            }
            catch (Exception)
            {
                result = false;
            }

            if (!result)
            {
                string err_str = "Cannot reach element: " + element_str;
                Console.WriteLine(err_str);
                throw new Exception(err_str);
            }

            SeleniumExecutor.SetDefaultWaitTimeout();
            return(result);
        }
Beispiel #15
0
        public static bool ClickWithWaitEx(IWebElement e, bool checkByDisplayed = true, int secondsWait = SeleniumExecutor.Timeout)
        {
            if (checkByDisplayed)
            {
                SeleniumWait.WaitForElementToBeDisplayedEx(e, secondsWait);
            }
            else
            {
                SeleniumWait.WaitForElementToBeEnabledEx(e, secondsWait);
            }

            SeleniumExecutor.ChangeWaitTimeout(0);
            for (int i = 0; i < 2 * secondsWait; ++i)
            {
                if (SeleniumExecutor.ignoreCurrentTest)
                {
                    Assert.Ignore(SeleniumExecutor.ignoreByNoConnection);
                }

                try
                {
                    e.Click();
                    SeleniumExecutor.SetDefaultWaitTimeout();
                    return(true);
                }
                catch (Exception)
                {
                    System.Threading.Thread.Sleep(500);
                }
            }

            SeleniumExecutor.SetDefaultWaitTimeout();
            return(false);
        }
Beispiel #16
0
        public static void ClearWithWait(this IWebElement e)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();

            driver.WaitForNoAjaxRequestsPending();
            driver.WaitForElementToBeDisplayed(e);
            e.Clear();
        }
Beispiel #17
0
        public static void SendKeysWithWait(this IWebElement e, String text)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();

            driver.WaitForNoAjaxRequestsPending();
            driver.WaitForElementToBeDisplayed(e);
            e.SendKeys(text);
        }
Beispiel #18
0
        public void DragAndDropProduct(string productLogo)
        {
            IWebElement logo   = SeleniumExecutor.GetDriver().FindElement(locators.logo(productLogo));
            Actions     action = new Actions(SeleniumExecutor.GetDriver());

            action.DragAndDrop(logo, locators.dropPlace);
            action.Perform();
        }
Beispiel #19
0
        public static IWebElement FindElementWithWait(this IWebElement e, By by)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();

            driver.WaitForNoAjaxRequestsPending();
            IWebElement element = e.FindElement(by);

            element.ScrollToElement();
            return(element);
        }
 public static void AfterStep()
 {
     if (ScenarioContext.Current.TestError != null)
     {
         var featureTitle  = TestRunnerManager.GetTestRunner().FeatureContext.FeatureInfo.Title;
         var scenarioTitle = TestRunnerManager.GetTestRunner().ScenarioInfo.Title;
         var fileName      = $@"{featureTitle}--{scenarioTitle}";
         SeleniumExecutor.TakeScreenshot(fileName);
     }
 }
Beispiel #21
0
        public static IWebElement ScrollToElement(this IWebElement element)
        {
            IWebDriver driver   = SeleniumExecutor.GetDriver();
            String     position = element.Location.Y.ToString();
            String     script   = String.Format($"('#main-container').scrollTop({position})");

            ((IJavaScriptExecutor)driver).ExecuteScript(script);

            return(element);
        }
Beispiel #22
0
        public static void ClickWithWait(this IWebElement e)
        {
            IWebDriver driver = SeleniumExecutor.GetDriver();

            driver.WaitForNoAjaxRequestsPending();
            e.ScrollToElement();
            driver.WaitForElementToBeDisplayed(e);
            e.Click();
            driver.WaitUntilSpinnerIsNotDisplayed();
        }
Beispiel #23
0
 public static void UntilElementIsClickable(this By elementLocator, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(ExpectedConditions.ElementToBeClickable(elementLocator));
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element with locator: '{elementLocator}' wasn't clickable within specified timeout limit", e);
     }
 }
Beispiel #24
0
 public static void UntilElementIsEnabled(IWebElement element, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(d => element.Enabled);
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element wasn't enabled within specified timeout limit", e);
     }
 }
Beispiel #25
0
 public static void UntilElementIsEnabled(this By elementLocator, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(d => d.FindElement(elementLocator).Enabled);
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element with locator: '{elementLocator}' wasn't enabled within specified timeout limit", e);
     }
 }
Beispiel #26
0
 public static void UntileElementsCollectionHasSize(By elementsLocator, int size, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(d => elementsLocator.GetElements().Count == size);
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Elements collection didn't have expected size. Expected: {size}, Actual: {elementsLocator.GetElements().Count}", e);
     }
 }
Beispiel #27
0
 public static void UntilElementHasAttributesValue(IWebElement element, string attribute, string expectedValue, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(d => element.GetAttribute(attribute).Equals(expectedValue));
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element didn't have expected value '{expectedValue}' in '{attribute}' attribute within specified timeout limit", e);
     }
 }
Beispiel #28
0
 public static void UntilElementIsNotDisplayed(IWebElement element, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(d => !element.Displayed);
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element didn't disappear within specified timeout limit", e);
     }
 }
Beispiel #29
0
 public static void UntilElementIsNotDisplayed(this By elementLocator, TimeSpan?customTimeout = null)
 {
     try
     {
         SeleniumExecutor.WaitDriver(customTimeout).Until(ExpectedConditions.InvisibilityOfElementLocated(elementLocator));
     }
     catch (WebDriverTimeoutException e)
     {
         throw new WebDriverTimeoutException($"Element with locator: '{elementLocator}' didn't disappear within specified timeout limit", e);
     }
 }
Beispiel #30
0
        public static void WaitForElementToBeNotDisplayed(this IWebDriver driver, By by)
        {
            WebDriverWait waitDriver = SeleniumExecutor.GetWaitDriver();

            try
            {
                waitDriver.Until(d => d.FindElement(by).Displayed == false);
            }
            catch (Exception)
            {
                waitDriver.Until(d => d.FindElements(by).Count == 0);
            }
        }