Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public void WaitForFullPageLoaded()
        {
            try
            {
                IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

                for (int i = 0; i < 60; i++)
                {
                    Thread.Sleep(1000);
                    if (js.ExecuteScript("return document.readyState").ToString().Equals("complete"))
                    {
                        break;
                    }
                }

                string info = string.Format("Wait for page to be loaded completedly");
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (Exception ex)
            {
                string message    = string.Format("WaitForFullPageLoaded: Error occurs");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 5
0
        public void SwitchToNewWindow()
        {
            try
            {
                string currentWindowHandle = driver.CurrentWindowHandle;
                var    windowHandles       = driver.WindowHandles;
                foreach (string windowHandle in windowHandles)
                {
                    if (windowHandle != currentWindowHandle)
                    {
                        driver.Close();
                        driver.SwitchTo().Window(windowHandle);
                    }
                }

                string info = string.Format(string.Format("Switch to new window"));
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message    = string.Format("An error happens when trying to switch to new window");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 6
0
        public void ClickAndWait(string elementName, By byObject)
        {
            try
            {
                Click(elementName, byObject);
                WaitForFullPageLoadedA();

                string info = string.Format("Click on element [{0}] and wait for loading", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message    = string.Format("An error happens when trying to click on [{0}] and wait for loading", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 7
0
        public void ScrollUpPage(string elementName, int pixels)
        {
            try
            {
                IJavaScriptExecutor je = (IJavaScriptExecutor)driver;
                je.ExecuteScript("window.scrollBy(0,-" + pixels + ")", "");

                string info = string.Format("Scroll page up");
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (Exception ex)
            {
                string message    = string.Format("Can't scroll page up.");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 8
0
        public void WaitForPageTitleEqual(string title)
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                wait.Until(ExpectedConditions.TitleIs(title));

                string info = string.Format("Wait for page title equal [{0}]", title);
                HtmlReporter.Pass(info);
                NLogger.Info(info);
            }
            catch (WebDriverTimeoutException ex)
            {
                var    message    = string.Format("Page title does not appear as expected. Title information: {0}", title);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 9
0
        public void WaitForFullPageLoadedA()
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.XPath("//body[@class='loading']")));

                string info = string.Format("Wait for page to be loaded completedly");
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverTimeoutException ex)
            {
                string message    = string.Format("Page is still loading");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 10
0
        public void ScrollPage()
        {
            try
            {
                IJavaScriptExecutor je = (IJavaScriptExecutor)driver;
                je.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)", "");

                string info = string.Format("ScrollPage");
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (Exception ex)
            {
                string message    = string.Format("Can't ScrollPage.");
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 11
0
        public void WaitForElementToBeInvisible(string elementName, By byObject)
        {
            try
            {
                NLogger.Info(string.Format("Wait for element [{0}] to be invisible.", elementName));
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                wait.Until(ExpectedConditions.InvisibilityOfElementLocated(byObject));

                string info = string.Format("Wait for element [{0}] to be invisible.", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverTimeoutException ex)
            {
                var    message    = string.Format("Element [{0}] is still visible.", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 12
0
        public void ClickButtonAndWaitToLoad(string elementName, By byObject, By obicon)
        {
            try
            {
                IWebElement element = WaitForElementToBeClickable(elementName, byObject);
                element.Click();
                WaitForElementToBeInvisible("", obicon);
                WaitForFullPageLoadedA();

                string info = string.Format("Click on element [{0}] and wait for loading", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message    = string.Format("An error happens when trying to click on [{0}] and wait for loading", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 13
0
        public void ScrolltillElement(string elementName, By byObject)
        {
            try
            {
                IJavaScriptExecutor je = (IJavaScriptExecutor)driver;

                IWebElement element = WaitForElementToBeVisible(elementName, byObject);
                je.ExecuteScript("arguments[0].scrollIntoView(true);", element);

                string info = string.Format("Scroll page to element [{0}]", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (Exception ex)
            {
                string message    = string.Format("Can't scroll page to element [{0}]", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 14
0
        public string WaitForVisibilityOfURL(string url)
        {
            try
            {
                WebDriverWait wait       = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                string        actual_url = wait.Until(CustomExpectedConditions.urlContainedBy(url));

                string info = string.Format("Wait for URL [{0}] displays", url);
                NLogger.Info(info);
                HtmlReporter.Pass(info);

                return(actual_url);
            }
            catch (WebDriverTimeoutException ex)
            {
                var    message    = string.Format("The URL [{0}] is not presented as expected", url);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 15
0
        public ReadOnlyCollection <IWebElement> WaitForVisibilityOfAllElementsLocatedBy(string elementName, By byObject)
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                ReadOnlyCollection <IWebElement> elements = wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(byObject));

                string info = string.Format("Wait for elements [{0}] to be visible", elementName);
                HtmlReporter.Pass(info);
                NLogger.Info(info);

                return(elements);
            }
            catch (WebDriverTimeoutException ex)
            {
                var    message    = string.Format("Elements [{0}] are not visible as expected.", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 16
0
        public IWebElement WaitForElementToBeClickable(string elementName, By byObject)
        {
            try
            {
                WebDriverWait wait    = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                IWebElement   element = wait.Until(ExpectedConditions.ElementToBeClickable(byObject));

                string info = string.Format("Wait for element [{0}] to be clickable.", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);

                return(element);
            }
            catch (WebDriverTimeoutException ex)
            {
                var    message    = string.Format("Element [{0}] is not clickable as expected.", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 17
0
        public bool WaitForTextToBePresentInElementLocated(string elementName, By byObject, string text)
        {
            try
            {
                WebDriverWait wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                bool          status = wait.Until(ExpectedConditions.TextToBePresentInElementLocated(byObject, text));

                string info = string.Format("Wait for text [{0}] to be present in element [{1}].", text, elementName);
                HtmlReporter.Pass(info);
                NLogger.Info(info);

                return(status);
            }
            catch (WebDriverTimeoutException ex)
            {
                var    message    = string.Format("Text [{0}] is not present in element [{1}] as expected.", text, elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 18
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);
            }
        }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
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);
            }
        }
Ejemplo n.º 21
0
        public void SelectValueInDropBoxByElement(string elementName, By byObject, By item)
        {
            try
            {
                IWebElement comboBox = WaitForElementToBeClickable(elementName, byObject);
                comboBox.Click();

                IWebElement selectedItem = WaitForElementToBeClickable("", item);
                selectedItem.Click();

                string info = string.Format("SelectValueInDropBoxByElement from element [{0}].", elementName);
                NLogger.Info(info);
                HtmlReporter.Pass(info);
            }
            catch (WebDriverException ex)
            {
                string message    = string.Format("An error happens when trying to SelectValueInDropBoxByElement from element [{0}].", elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 22
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);
            }
        }
Ejemplo n.º 23
0
        public List <string> WaitForVisibilityOfAllElementTextsLocatedBy(string elementName, By byObject, List <string> itemList)
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(GetWaitTimeoutSeconds()));
                List <string> list = wait.Until(CustomExpectedConditions.VisibilityOfAllElementTextsLocatedBy(byObject, itemList));

                string info = string.Format("Wait for text list to be present in element. String list: [{0}]; Element information: {1}",
                                            string.Join(", ", itemList.ToArray()), elementName);
                HtmlReporter.Pass(info);
                NLogger.Info(info);

                return(list);
            }
            catch (WebDriverTimeoutException ex)
            {
                var message = string.Format("Text list is not present in element as expected. String list: [{0}]; Element information: {1}",
                                            string.Join(", ", itemList.ToArray()), elementName);
                string screenshot = ScreenShotCapturing.TakeScreenShoot(driver, message);
                HtmlReporter.Fail(message, ex, screenshot);
                throw new ErrorHandler(message, ex);
            }
        }
Ejemplo n.º 24
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);
            }
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
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);
            }
        }