示例#1
0
 private static void StartDriver()
 {
     if (TestRun.GetSelectedBrowser().Equals(BrowserType.CHROME))
     {
         StartChromeDriver();
     }
     else if (TestRun.GetSelectedBrowser().Equals(BrowserType.FIREFOX))
     {
         StartFirefoxDriver();
         SetWindowSize();
     }
     else if (TestRun.GetSelectedBrowser().Equals(BrowserType.IE))
     {
         StartIEDriver();
         SetWindowSize();
     }
     else if (TestRun.GetSelectedBrowser().Equals(BrowserType.EDGE))
     {
         StartEdgeDriver();
         SetWindowSize();
     }
     else
     {
         string exceptionMessage = string.Format("Browser '{0}' is not recognised, please use one of the supported browser types (chrome, firefox, ie or edge)", TestRun.GetSelectedBrowser());
         throw new Exception(exceptionMessage);
     }
 }
示例#2
0
        private static void KillDriverProcesses()
        {
            //IF RELEASE
#if (!DEBUG)
            //There is an issue where driver denies the Agent access to the EPC/bin folder,
            //thus preventing it from building after a test suite has finished. This will
            //ensure that any left over driver processes or sessions are killed so that the agent
            //can execute a successful clean & build

            if (TestRun.GetSelectedBrowser().Equals(BrowserType.CHROME))
            {
                KillProcess("chromedriver.exe");
                KillProcess("chrome.exe");
            }
            else if (TestRun.GetSelectedBrowser().Equals(BrowserType.FIREFOX))
            {
                KillProcess("firefox.exe");
                KillProcess("geckodriver.exe");
            }
            else if (TestRun.GetSelectedBrowser().Equals(BrowserType.IE))
            {
                KillProcess("iexplore.exe");
                KillProcess("IEDriverServer.exe");
            }
            else if (TestRun.GetSelectedBrowser().Equals(BrowserType.EDGE))
            {
                KillProcess("MicrosoftWebDriver.exe");
            }
#endif
        }
示例#3
0
        public void Click()
        {
            string stepDesciption = TestLogger.CreateTestStep("Click", name, pageName);

            IWebElement element  = null;
            int         attempts = 0;

            while (attempts <= 3)
            {
                try
                {
                    if (TestRun.GetSelectedBrowser().Equals(BrowserType.EDGE))
                    {
                        Thread.Sleep(5000); // Hard coded wait to avoid flakiness of the Driver

                        Actions actions = new Actions(WebDriverHelper.Driver);
                        actions.Click(FindWebElement(true)).Build().Perform();
                    }
                    else
                    {
                        FindWebElement(false).Click();
                    }

                    break;
                }
                catch (Exception ex)
                {
                    attempts += 1;
                    string exceptionMessage = ex.Message.ToLower();

                    if (exceptionMessage.Contains("not clickable at point") &&
                        attempts < 4)
                    {
                        try
                        {
                            Thread.Sleep(5000);

                            //Clicks the coordinates of the element;
                            //Note: selenium is unable to click this element the convential way because the control
                            //****  is overlapped.
                            element = FindWebElement(false);
                            new Actions(WebDriverHelper.Driver).MoveToElement(element).Click().Build().Perform();
                            break;
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    else if ((exceptionMessage.Contains("could not be scrolled into view")))
                    {
                        try
                        {
                            MoveElementToMiddleOfPage(element);
                            new Actions(WebDriverHelper.Driver).MoveToElement(element).MoveByOffset(0, 0).Click().Build().Perform();
                        }
                        catch
                        {
                            Thread.Sleep(5000);
                            continue;
                        }
                    }
                    else if ((exceptionMessage.Contains("element is no longer valid") ||
                              exceptionMessage.Contains("element is not displayed") ||
                              exceptionMessage.Contains("element is not attached to the page document") ||
                              exceptionMessage.Contains("element not visible") ||
                              exceptionMessage.Contains("no such element") ||
                              exceptionMessage.Contains("unknown error")) &&
                             attempts < 4)
                    {
                        Thread.Sleep(5000);
                        continue;
                    }
                    else
                    {
                        TestHelper.HandleActionOrAssertionException(stepDesciption, ex);
                    }
                }
            }
        }