示例#1
0
        /// <summary>
        /// Finds and clicks the top left corner of the locator element a specified number of times with option to wait for ~30seconds
        /// </summary>
        /// <param name="input"></param>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <param name="waitFor"></param>
        /// <param name="clicks"></param>
        /// <param name="delay"></param>
        public void FindAndMultiClick(string input, By locator, BrowserDriver driver, bool waitFor, int clicks, bool delay)
        {
            errLocator = locator.ToString();
            errMethod  = "FindAndMultiClick";

            if (waitFor)
            {
                WaitForElement(locator, driver);
            }
            IWebElement elementFound = driver.Driver.FindElement(locator);

            for (int i = 0; i < clicks; i++)
            {
                if (delay)
                {
                    AddDelay(200);
                }
                elementFound.Click();
            }

            // The point of the multi click input is to highlight and replace preexisting data in the input box
            if (input != "")
            {
                elementFound.SendKeys(input);
            }
        }
示例#2
0
        /// <summary>
        /// Used to close popup windows. Closes all windows except the current(hopefully main) window
        /// </summary>
        /// <param name="driver"></param>
        public void ClosePopUp(BrowserDriver driver)
        {
            errLocator = "";
            errMethod  = "ClosePopUp";

            //get the current window handles
            string popupHandle = string.Empty;
            ReadOnlyCollection <string> windowHandles = driver.Driver.WindowHandles;

            string currentWindowHandle = windowHandles.ElementAt(0);

            foreach (string handle in windowHandles)
            {
                if (handle != currentWindowHandle)
                {
                    popupHandle = handle;

                    //switch to new window
                    driver.Driver.SwitchTo().Window(popupHandle);

                    //close the new window to navigate to the previous one
                    driver.Driver.Close();

                    break;
                }
            }

            //switch back to original window
            driver.Driver.SwitchTo().Window(currentWindowHandle);
        }
示例#3
0
        /// <summary>
        /// Finds an element and clicks within the element. Options are to single/double click and click and drag
        /// </summary>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <param name="xOffset"></param>  Defines the location on the element to be clicked
        /// <param name="yOffset"></param>
        /// <param name="clickHow"></param> What kind of click. Options are "single", "double", and "drag"
        /// <param name="xOffset2"></param> Defines the movement vector to drag the mouse to after click. Only used on "drag" option
        /// <param name="yOffset2"></param>
        public void ClickOnPage(By locator, BrowserDriver driver, int xOffset, int yOffset, string clickHow, int xOffset2, int yOffset2)
        {
            errLocator = locator.ToString();
            errMethod  = "ClickOnPage";

            IWebElement marker  = driver.Driver.FindElement(locator);
            Actions     builder = new Actions(driver.Driver);

            if (clickHow == "drag")
            {
                builder.MoveToElement(marker, xOffset, yOffset).ClickAndHold().MoveByOffset(1, 1).MoveByOffset(xOffset2, yOffset2);
            }
            else if (clickHow == "double")
            {
                builder.MoveToElement(marker, xOffset, yOffset).KeyDown(Keys.Shift).Click().KeyUp(Keys.Shift);
            }
            else
            {
                builder.MoveToElement(marker, xOffset, yOffset).Click();
            }

            builder.Build().Perform();

            if (clickHow == "drag")
            {
                AddDelay(200);
                builder.Release();
                builder.Build().Perform();
            }
        }
示例#4
0
        /// <summary>
        /// Grabs the inner HTML of a tag, so useful for checking report values
        /// </summary>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <returns></returns>
        public string FindValue(By locator, BrowserDriver driver)
        {
            errLocator = locator.ToString();
            errMethod  = "FindValue";

            IWebElement elementFound = driver.Driver.FindElement(locator);
            string      value        = elementFound.GetAttribute("innerHTML");

            return(value);
        }
示例#5
0
 /// <summary>
 /// Checks if the locator element is visible on the screen. Similar to IsElementPresent()
 /// </summary>
 /// <param name="driver"></param>
 /// <param name="locator"></param>
 /// <returns></returns>
 public static bool IsElementDisplayed(BrowserDriver driver, By locator)
 {
     try
     {
         return(driver.Driver.FindElement(locator).Displayed);
     }
     catch (NoSuchElementException)
     {
         return(false);
     }
 }
示例#6
0
        /// <summary>
        /// Finds and clicks the top left corner of the locator element with option to wait for ~30seconds
        /// </summary>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <param name="waitFor"></param>
        /// <summary>
        ///
        /// </summary>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <param name="waitFor"></param>
        public void FindAndClick(By locator, BrowserDriver driver, bool waitFor)
        {
            errLocator = locator.ToString();
            errMethod  = "FindAndClick";

            if (waitFor == true)
            {
                WaitForElement(locator, driver);
            }
            IWebElement elementFound = driver.Driver.FindElement(locator);

            elementFound.Click();
        }
示例#7
0
        /// <summary>
        /// Checks once if the Element defined by the locator is present on the page
        /// </summary>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <returns></returns>
        public bool IsElementPresent(By locator, BrowserDriver driver)
        {
            errLocator = locator.ToString();
            errMethod  = "IsElementPresent";

            try
            {
                IWebElement element = driver.Driver.FindElement(locator);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#8
0
 public void Wait30Minutes(By locator, BrowserDriver driver)
 {
     try
     {
         driver.Driver.FindElement(locator);
     }
     catch
     {
         if (_waitIndex < 3600)
         {
             Thread.Sleep(500);
             _waitIndex++;
             Wait30Minutes(locator, driver);
         }
     }
 }
示例#9
0
        public string ElementSize(By locator, BrowserDriver driver, bool waitFor)
        {
            errLocator = locator.ToString();
            errMethod  = "ElementSize";

            if (waitFor)
            {
                WaitForElement(locator, driver);
            }

            IWebElement marker = driver.Driver.FindElement(locator);
            var         size   = marker.Size.ToString();



            return(size);
        }
示例#10
0
 public void WaitLongTime(By locator, BrowserDriver driver)
 {
     try
     {
         driver.Driver.FindElement(locator);
         _waitIndex = 0;
     }
     catch
     {
         if (_waitIndex < 600)
         {
             Thread.Sleep(500);
             _waitIndex++;
             WaitLongTime(locator, driver);
         }
     }
 }
示例#11
0
        public CGlobalTest(string whichBrowser, string whichTest)
        {
            driver        = new BrowserDriver(whichBrowser);
            gMethods      = new GeneralTestMethods();
            _whichTest    = whichTest;
            _whichBrowser = whichBrowser;

            gMethods.SetErrorStrings("none", "CGlobalTestConstructor");

            try
            {
            }
            catch (Exception)
            {
                {
                }
                throw;
            }
        }
示例#12
0
        private static CFarmEmail CreateTestObjects(string path, CFarmEmail cFarmEmail, GeneralTestMethods gMethods, String browser, string url)
        {
            if (path != "")
            {
                {
                    var driver = new BrowserDriver(browser);

                    try
                    {
                        if (path.Contains("CFarm") && path.Contains("xml"))
                        {
                            var cFarmXml     = new CFarmXmlLister(path);
                            var cFarmXmlTest = new CFarmXmlTest(driver, gMethods, cFarmXml, "Tester", url);

                            cFarmEmail.SetSuccessData(driver, cFarmXml, cFarmXml._xmlDoc.CFarmReportData);
                        }
                        _failCount = 0;
                        cFarmEmail.IncPassCount();
                        cFarmEmail.IncTestCount();

                        driver.Driver.Quit();
                    }

                    catch (Exception e)
                    {
                        driver.Driver.Quit();
                        if (_failCount < 2)

                        {
                            _failCount++;
                            CreateTestObjects(path, cFarmEmail, gMethods, browser, url);
                        }
                        else
                        {
                            cFarmEmail.IncTestCount();
                            cFarmEmail.SetFailData(path, e);
                        }
                    }
                }
            }

            return(cFarmEmail);
        }
示例#13
0
        /// <summary>
        /// Types keys into locator element. Useful for general page hotkeys.
        /// </summary>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <param name="key1"></param>     Pressed and Held Key
        /// <param name="key2"></param>     Positive pressed Key
        /// <param name="key3"></param>     Used in conjuction with negative "presses" values
        /// <param name="holdKey1"></param> True if key1 needs held down while key2 pressed
        /// <param name="presses"></param>  How many times does this key combo need pressed?
        public void EnterKeys(By locator, BrowserDriver driver, string key1, string key2, string key3, int presses)
        {
            errLocator = locator + key1 + key2;
            errMethod  = "EnterKeys";

            if (presses != 0)
            {
                IWebElement marker  = driver.Driver.FindElement(locator);
                Actions     builder = new Actions(driver.Driver);

                if (key1 != null)
                {
                    if (presses < 0)
                    {
                        builder.MoveToElement(marker).KeyDown(key1).SendKeys(key3).KeyUp(key1);
                    }
                    else
                    {
                        builder.MoveToElement(marker).KeyDown(key1).SendKeys(key2).KeyUp(key1);
                    }
                }
                else
                {
                    if (presses < 0)
                    {
                        builder.MoveToElement(marker).SendKeys(key3);
                    }
                    else
                    {
                        builder.MoveToElement(marker).SendKeys(key2);
                    }
                }
                IAction pressNextElement = builder.Build();
                for (int i = 0; i < Math.Abs(presses); i++)
                {
                    AddDelay(20);
                    pressNextElement.Perform();
                }
            }
        }
示例#14
0
        /// <summary>
        /// Finds locator element and sends a key combination to the input box (like typing)
        /// </summary>
        /// <param name="input"></param>
        /// <param name="locator"></param>
        /// <param name="driver"></param>
        /// <param name="waitFor"></param>
        /// <param name="enter"></param>
        public void FindAndInput(string input, By locator, BrowserDriver driver, bool waitFor, bool enter)
        {
            errLocator = locator.ToString();
            errMethod  = "FindAndInput";

            if (waitFor)
            {
                WaitForElement(locator, driver);
            }

            IWebElement elementFound = driver.Driver.FindElement(locator);

            elementFound.Click();

            elementFound.SendKeys(Keys.Backspace + input);

            // Option to hit "Enter" after key input
            if (enter)
            {
                elementFound.Submit();
            }
        }