Exemple #1
0
        public void SelectByValue(string elementName, By byObject, string value)
        {
            ReadOnlyCollection <IWebElement> listElements = null;

            try
            {
                listElements = WaitForVisibilityOfAllElementsLocatedBy(elementName, byObject);

                foreach (IWebElement e in listElements)
                {
                    string text = e.GetAttribute("value");
                    if (text.Equals(value))
                    {
                        e.Click();
                        break;
                    }
                }

                string info = string.Format("Get list of elements [{0}].", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                foreach (IWebElement element in listElements)
                {
                    ScreenShotCapturing.HighlightElement(driver, element);
                }
                string message    = string.Format("An error happens when trying to get list of elements [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #2
0
        public void ClickAll(string elementName, By byObject)
        {
            IReadOnlyCollection <IWebElement> listElements = null;

            try
            {
                listElements = WaitForVisibilityOfAllElementsLocatedBy(elementName, byObject);

                foreach (IWebElement e in listElements)
                {
                    e.Click();
                }

                string info = string.Format("Click on all elements [{0}].", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                foreach (IWebElement element in listElements)
                {
                    ScreenShotCapturing.HighlightElement(driver, element);
                }
                string message    = string.Format("An error happens when trying to click all on list of elements [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #3
0
        public List <string> GetTextFromElements(string elementName, By byObject)
        {
            ReadOnlyCollection <IWebElement> listElements = null;

            try
            {
                List <string> listElementText = new List <string>();
                listElements = WaitForVisibilityOfAllElementsLocatedBy(elementName, byObject);
                foreach (IWebElement element in listElements)
                {
                    string text = element.Text;
                    listElementText.Add(text);
                }

                string info = string.Format("Get text from list of elemets [{0}]", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);

                return(listElementText);
            }
            catch (WebDriverException ex)
            {
                foreach (IWebElement element in listElements)
                {
                    ScreenShotCapturing.HighlightElement(driver, element);
                }
                string message    = string.Format("An error happens when trying to get text for list of elements [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #4
0
        public void SwitchToFrame(string elementName, By byObject)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeVisible(elementName, byObject);
                driver.SwitchTo().Frame(element);

                string info = string.Format(string.Format("Switch to frame. Frame information: {0}", elementName));
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when switching to frame [{0}]", elementName);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #5
0
        public void UploadFile(string elementName, By byObject, string filename)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeVisible(elementName, byObject);
                element.SendKeys(filename);

                string info = string.Format("Uploading file. File name: [{0}]; Element Name [{1}]", filename, elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when trying to send text [{0}] to element [{1}].", filename, elementName);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #6
0
        public void Clear(string elementName, By byObject)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeVisible(elementName, byObject);
                element.Clear();

                string info = string.Format("Clear element content [{0}]", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when trying to clear element content [{0}].", elementName);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #7
0
        public string GetValue(string elementName, By byObject)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeVisible(elementName, byObject);

                string info = string.Format("Get the value of elemet [{0}]", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);

                return(element.GetAttribute("value"));
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when trying to get the value of element [{0}].", elementName);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #8
0
        public void HoverMouseOn(string elementName, By byObject)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeClickable(elementName, byObject);
                Actions action = new Actions(driver);
                action.MoveToElement(element).Perform();

                string info = string.Format(string.Format("Hover mouse on element. Element information: {0}", elementName));
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when trying to hover mouse on element [{0}].", elementName);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #9
0
        public void SelectComboItemByText(string elementName, By byObject, string itemText)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeVisible(elementName, byObject);
                SelectElement select = new SelectElement(element);
                select.SelectByText(itemText);

                string info = string.Format("Select [{0}] from element [{1}].", elementName, itemText);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when trying to SelectComboItemByText [{0}] from element [{1}].", elementName, itemText);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #10
0
        public void VerifyDouble(string elementName, By byObject, double expectedDouble)
        {
            double actualDouble = 0;

            try
            {
                actualDouble = double.Parse(GetText(elementName, byObject));
                Assert.AreEqual(expectedDouble, actualDouble);

                string info = string.Format("Double of element [{0}] as expectation [{1}]", elementName, expectedDouble);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (AssertFailedException ex)
            {
                IWebElement element = WaitForElementToBeVisible(elementName, byObject);
                string      message = string.Format("Verify Double for element [{0}] failed. Expected [{1}] but actual [{2}]", elementName, expectedDouble, actualDouble);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Exemple #11
0
        public void HoverMouseAndClick(string elementName, By byObject)
        {
            IWebElement element = null;

            try
            {
                element = WaitForElementToBeVisible(elementName, byObject);
                HoverMouseOn(elementName, byObject);
                IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
                executor.ExecuteScript("arguments[0].click();", element);

                string info = string.Format("Hover mouse and click on element [{0}].", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message = string.Format("An error happens when trying to hover mouse and click element on [{0}]", elementName);
                ScreenShotCapturing.HighlightElement(driver, element);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }