/// <summary> /// This function will append text to the already present text /// </summary> /// <param name="element"></param> /// <param name="text"></param> public void ConcatinateText(IWebElement element, String text) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, "", ""); try { element.SendKeys(text); LogHandler.Info("TypeText::The text " + text + " has been entered in InputBox with value: " + text); } catch (Exception e) { LogHandler.Error("TypeText::NoSuchElementException - " + e.Message); throw new NoSuchElementException("TypeText::" + e.Message); } }
/// <summary> /// Verifies if an element text content is cleared or not. /// </summary> /// <param name="actualText">the actual text inside the web element</param> /// <param name="expectedText">the expected text inside the web element</param> /// <param name="elementName">the element name</param> /// <param name="page">the element page name</param> protected void IsElementEmpty(IWebElement element, String elementName, String page) { WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), element, elementName, page); try { string value = element.GetAttribute("value"); Assert.True((value == "" || value == null), "The element " + elementName + " text is not empty on " + page); LogHandler.Info("IsElementEmpty::The element " + elementName + " text is empty on " + page); } catch (Exception e) { LogHandler.Error("IsElementEmpty::The element " + elementName + " text is not empty on " + page); Assert.True(false, e.Message); } }
/// <summary> /// Selects value from element using specified index. /// </summary> /// <param name="element"> Element to locate on web page</param> /// <param name="index">Index number for selection</param> public void SelectByIndex(IWebElement element, int index) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, "", ""); try { SelectElement select = new SelectElement(element); select.SelectByIndex(index); LogHandler.Info("SelectByText::The option has been selected by index: " + index); } catch (Exception e) { LogHandler.Error("SelectByIndex::NoSuchElementException - " + e.Message); throw new NoSuchElementException("SelectByIndex::" + e.Message); } }
/// <summary> /// Selects value from element using specified text /// </summary> /// <param name="element"> Element to locate on web page</param> /// <param name="text">Text value for selection</param> public void SelectByText(IWebElement element, String text, String elementName) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, elementName, ""); try { SelectElement select = new SelectElement(element); select.SelectByText(text); LogHandler.Info("SelectByText::The element '" + elementName + "' select option has been selected by text: " + text); } catch (Exception e) { LogHandler.Error("SelectByText::The element '" + elementName + "' - " + "NoSuchElementException - " + e.Message); throw new NoSuchElementException("SelectByText::" + e.Message); } }
/// <summary> /// Verifies if an element is displayed on the page. /// </summary> /// <param name="element">the web element</param> /// <param name="by">the web element locator</param> /// <param name="elementName">the element name</param> /// <param name="page">the element page name</param> /// <returns>true = If element is visible; /// false = If eltemen is not visible /// </returns> public bool IsElementDisplayed(IWebElement element, By by, String elementName, String page) { WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), element, elementName, page); try { WebDriverWait wait = new WebDriverWait(DriverManager.GetDriver(), ConfigurationReader.FrameworkConfig.GetExplicitlyTimeout()); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(by)); LogHandler.Info("IsElementDisplayed::The element " + elementName + " located by is visible on the page " + page); return(true); } catch (Exception e) { LogHandler.Error("IsElementDisplayed::Exception - " + e.Message); return(false); } }
/// <summary> /// This function enter text in the specified element. /// 1. Clear the field /// 2. Send keys (Text) to the web element /// </summary> /// <param name="element"> Element to enter text into </param> /// <param name="text">Text to enter in element </param> public void TypeText(IWebElement element, String text, String elementName) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, elementName, ""); try { element.Clear(); element.SendKeys(text); LogHandler.Info("TypeText::The text has been entered in InputBox '" + elementName + "' with value: " + text); } catch (Exception e) { LogHandler.Error("TypeText::The text has been failed to enter in InputBox '" + elementName + "' with value: " + text); LogHandler.Error("TypeText::NoSuchElementException - " + e.Message); throw new NoSuchElementException("TypeText::" + e.Message); } }
/// <summary> /// Selects value from element using specified value /// </summary> /// <param name="locator"> String for element to locate </param> /// <param name="type">Option for selection such as id / Xpath /..etc </param> /// <param name="index">Index value for selection</param> public void SelectByValue(IWebElement element, String value, String elementName) { WaitsHandler.WaitForElementToBeVisible(baseDriver, element, elementName, ""); try { SelectElement select = new SelectElement(element); IWebElement sdsd = select.SelectedOption; select.SelectByValue(value); LogHandler.Info("SelectByValue::The element '" + elementName + "' select option has been selected by value: " + value); } catch (Exception e) { LogHandler.Error("SelectByValue::The element '" + elementName + "' - " + "NoSuchElementException - " + e.Message); throw new NoSuchElementException("SelectByValue::" + e.Message); } }
/// <summary> /// Close active tab. /// </summary> public void CloseActiveTab() { string active = "active"; string path = "//*[@id='tabsContainer']/li"; WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), By.XPath(path), "Active Tab", "Current Page"); IList <IWebElement> tablist = DriverManager.GetDriver().FindElements(By.XPath(path)); foreach (var v in tablist) { if (active == v.GetAttribute("class")) { string actual_path = path + "[contains(@class, 'active')]/span/i"; WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), By.XPath(actual_path), "Active Tab Button", "Current Page"); DriverManager.GetDriver().FindElement(By.XPath(actual_path)).Click(); } } }
/// <summary> /// Verifies if an element is on the page. /// If is on the page then WaitForElementToBeVisible /// </summary> /// <param name="element">the element</param> /// <param name="condition">the expected condition. True the element should be on the page.</param> /// <param name="elementName">the element name</param> /// <param name="page">the page name</param> protected void IsElementOnPage(IWebElement element, bool condition, String elementName, String page) { System.Drawing.Point location; try { location = element.Location; Assert.False(location.IsEmpty); Assert.True(condition, "The element " + elementName + " is not on the page " + page + " but it's expected to be."); WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), element, elementName, page); } catch (Exception) { if (!condition) { Assert.False(condition, "The element " + elementName + " is on the page " + page + " but it's not expected to be."); } else { Assert.False(condition, "The element " + elementName + " is not on the page " + page + " but it's expected to be."); } } }
/// <summary> /// Verifies if the element is not empty. /// </summary> /// <param name="element">the web element</param> /// <param name="elementName">the element name</param> /// <param name="page">the page name</param> protected void IsElementNotEmpty(IWebElement element, String elementName, String page) { //Highlight(element); WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), element, elementName, page); try { if ((element.TagName).Equals("input") || (element.TagName).Equals("textarea")) { Assert.AreNotEqual("", element.GetAttribute("value"), "The element " + elementName + " text is empty on " + page); LogHandler.Info("IsElementNotEmpty::The element " + elementName + " text is not empty on " + page); } else { Assert.AreNotEqual("", element.Text, "The element " + elementName + " text is empty on " + page); LogHandler.Info("IsElementNotEmpty::The element " + elementName + " text is not empty on " + page); } } catch (Exception e) { LogHandler.Error("IsElementNotEmpty::The element " + elementName + " text is empty on " + page); Assert.True(false, e.Message); } }
/// <summary> /// Gets web element as a Select. /// </summary> /// <param name="element">the web element</param> /// <returns>the <see cref="SelectElement"/></returns> protected SelectElement GetSelectElement(IWebElement element) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, "", ""); return(new SelectElement(element)); }
/// <summary> /// Finds a subelement from an element by By. /// </summary> /// <param name="element">the web element</param> /// <param name="by">the strategy for finding the element</param> /// <returns>the <see cref="IWebElement"/></returns> public IWebElement FindSubElement(IWebElement element, By by) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, "element", "page"); return(element.FindElement(by)); }
/// <summary> /// Finds a set of subelement from an element by By. /// </summary> /// <param name="element">the web element</param> /// <param name="by">the strategy for finding the element</param> /// <returns>a list of <see cref="IWebElement"/></returns> public ReadOnlyCollection <IWebElement> FindSubElements(IWebElement element, By by) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, element, "element", "page"); return(element.FindElements(by)); }
/// <summary> /// Finds a web element ny By. /// </summary> /// <param name="by">the strategy for finding the element</param> /// <returns>the <see cref="IWebElement"/></returns> public IWebElement FindElement(By by) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, by, "element", "page"); return(BaseDriver.FindElement(by)); }
/// <summary> /// Verifies if an element text content is contained inside the actual text. /// </summary> /// <param name="element">the actual text inside the web element</param> /// <param name="expectedText">the expected text part inside the web element</param> /// <param name="elementName">the element name</param> /// <param name="page">the element page name</param> protected void IsTextContained(IWebElement element, String expectedText, String elementName, String page) { WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), element, elementName, page); Assert.True(element.Text.ToLower().Contains(expectedText.ToLower()), "The element '" + elementName + "' actual text '" + element.Text + "' does not contain '" + expectedText + "' on " + page); LogHandler.Info("IsTextContained::The element " + elementName + "text contains in actual text -'" + element.Text + "'"); }
/// <summary> /// Verifies if an element is displayed on the page. /// Wrapper method to WaitForElementToBeVisible /// </summary> /// <param name="element">the web element</param> /// <param name="elementName">the element name</param> /// <param name="page">the element page name</param> protected void IsElementDisplayed(IWebElement element, String elementName, String page) { //Highlight(element); WaitsHandler.WaitForElementToBeVisible(DriverManager.GetDriver(), element, elementName, page); }