/// <summary> /// Close the active tab /// </summary> public void CloseActiveTab() { try { string path = "//*[@id='tabsContainer']/li[@class='active']/span"; Driver.DriverManager.GetDriver().FindElement(By.XPath(path)).Click(); WaitsHandler.WaitForAjaxToComplete(baseDriver); } catch (Exception) { } }
/// <summary> /// Moves the mouse over the element. /// </summary> /// <param name="Element">the target element</param> public void MouseOver(IWebElement element) { WaitsHandler.WaitForElementToBeSelected(BaseDriver, element, "", ""); try { new Actions(BaseDriver).MoveToElement(element).Perform(); } catch (Exception e) { LogHandler.Error("MouseOver::NoSuchElementException - " + e.Message); throw new NoSuchElementException("MouseOver::" + e.Message); } }
/// <summary> /// /// </summary> /// <returns></returns> public IAlert SwitchToAlert() { try { WaitsHandler.WaitForAlert(baseDriver, ""); return(baseDriver.SwitchTo().Alert()); } catch (Exception e) { LogHandler.Error("SwitchToAlert::Exception - " + e.Message); throw new NoSuchElementException("SwitchToAlert::" + e.Message); } }
/// <summary> /// Verifies if an element is not enabled on the page. /// It uses WaitForElementUntilCondition /// </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 IsElementNotEnabled(IWebElement element, String elementName, String page) { Assert.NotNull(element, "NPE::The element " + elementName + " on the page " + page + " is not populated."); try { Func <IWebDriver, Boolean> function = delegate(IWebDriver d) { return(element.Enabled == false); }; WaitsHandler.WaitForElementUntilCondition(DriverManager.GetDriver(), function, page); } catch (Exception) { Assert.Fail("The expected element " + elementName + "to be not enable IS enable on the page " + page); } }
/// <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> /// Performs a Double Click operation on the specified element. /// </summary> /// <param name="eLocator"> String for element to locate </param> /// <param name="eType">Option for selection such as id / Xpath /..etc </param> public void DoubleClick(IWebElement element) { WaitsHandler.WaitForElementClickeable(BaseDriver, element, "", ""); try { new Actions(BaseDriver).DoubleClick(element).Perform(); LogHandler.Info("DoubleClick::The element has been double clicked"); } catch (Exception e) { LogHandler.Error("DoubleClick::Exception - " + e.Message); throw new NoSuchElementException("DoubleClick::Exception - " + e.Message); } WaitsHandler.WaitForAjaxToComplete(BaseDriver); }
/// <summary> /// This function perform Click operation on the specified element. /// </summary> /// <param name="element">IWebElement</param> public void Click(IWebElement element) { //Highlight(element); WaitsHandler.WaitForElementClickeable(BaseDriver, element, "", ""); try { element.Click(); LogHandler.Info("Click::The element has been clicked"); } catch (Exception e) { LogHandler.Error("Click::Exception - " + e.Message); throw new NoSuchElementException("Click::Exception - " + e.Message); } WaitsHandler.WaitForAjaxToComplete(BaseDriver); }
/// <summary> /// This function perform Click operation on the specified element after waiting for other element to be invisiable. /// </summary> /// <param name="element">IWebElement</param> public void ClickWait(IWebElement element, String locatorName, String locator) { //Highlight(element); WaitsHandler.WaitForElememntTobeInvisiable(BaseDriver, locatorName, locator, "", ""); try { element.Click(); LogHandler.Info("ClickWait::The element has been clicked"); } catch (Exception e) { LogHandler.Error("ClickWait::Exception - " + e.Message); throw new NoSuchElementException("Click::Exception - " + e.Message); } WaitsHandler.WaitForAjaxToComplete(BaseDriver); }
/// <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> /// 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> /// 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> /// 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 not displayed on the page. /// It uses WaitForElementUntilCondition /// </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 IsElementNotDisplayed(IWebElement element, String elementName, String page) { Assert.NotNull(element, "NPE::The element " + elementName + " on the page " + page + " is not populated."); try { if (element.TagName.Equals("i")) { Func <IWebDriver, Boolean> function = delegate(IWebDriver d) { return(element.GetAttribute("style").Equals("display: none;")); }; WaitsHandler.WaitForElementUntilCondition(DriverManager.GetDriver(), function, page); } else { Func <IWebDriver, Boolean> function = delegate(IWebDriver d) { return(element.Displayed == false); }; WaitsHandler.WaitForElementUntilCondition(DriverManager.GetDriver(), function, page); } } catch (Exception) { Assert.Fail("The expected element " + elementName + "to be not visible IS visible on the page " + page); } }
/// <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> /// Verifies if an element is displayed on the page. /// It uses WaitForElementUntilCondition /// </summary> /// <param name="element">the web element</param> /// <param name="element">the display condition</param> /// <param name="elementName">the element name</param> /// <param name="page">the element page name</param> protected void IsElementDisplayed(IWebElement element, bool condition, String elementName, String page) { // Highlight(element); Assert.NotNull(element, "NPE::The element " + elementName + " on the page " + page + " is not populated."); try { Func <IWebDriver, Boolean> function = delegate(IWebDriver d) { return(element.Displayed == condition); }; WaitsHandler.WaitForElementUntilCondition(DriverManager.GetDriver(), function, page); } catch (Exception) { if (condition) { LogHandler.Error("IsElementDisplayed::The expected element " + elementName + "to be visible IS NOT visible on the page " + page); Assert.Fail("The expected element " + elementName + "to be visible IS NOT visible on the page " + page); } else { LogHandler.Error("IsElementDisplayed::The expected element " + elementName + "to be not visible IS visible on the page " + page); Assert.Fail("The expected element " + elementName + "to be not visible IS visible on the page " + page); } } }
/// <summary> /// Verifies the current page title. /// </summary> /// <param name="title"> String to check with page title</param> /// <returns> True if value is same else false</returns> public Boolean VerifyCurrentPageTitle(String title) { WaitsHandler.WaitForAjaxToComplete(DriverManager.GetDriver()); string value = null; string path = "//*[@id='tabsContainer']/li"; string active = "active"; //SleepHelper.Sleep(5); 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')]/a"; value = DriverManager.GetDriver().FindElement(By.XPath(actual_path)).Text; if (value.ToUpper().Contains(title.ToUpper())) { return(true); } } } return(false); }
/// <summary> /// Check if Tab is present /// </summary> /// <param name="tabtitle">BTN number</param> /// <returns>true=if ihdcase tab is present; false=if it is not present</returns> public bool IsWindowPresent(string windowtitle) { WaitsHandler.WaitForAjaxToComplete(baseDriver); IWebDriver currentWindowHandle = null; try { ReadOnlyCollection <string> windowHandles = baseDriver.WindowHandles; foreach (string handle in windowHandles) { currentWindowHandle = baseDriver.SwitchTo().Window(handle); if (currentWindowHandle.Url.ToLower().Contains(windowtitle.ToLower()) || currentWindowHandle.Title.ToLower().Contains(windowtitle.ToLower())) { return(true); } } } catch (Exception) { //logger } return(false); }
/// <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> /// Accept Alert message /// </summary> /// <returns></returns> public void AcceptAlert() { SwitchToAlert().Accept(); WaitsHandler.WaitForAjaxToComplete(baseDriver); }
/// <summary> /// Verifies if an element is clickable. /// Wrapper method to WaitForElementClickeable /// </summary> /// <param name="element">the element</param> /// <param name="elementName">the element name</param> /// <param name="page">the page name</param> protected void IsElementClickable(IWebElement element, String elementName, String page) { WaitsHandler.WaitForElementClickeable(DriverManager.GetDriver(), element, elementName, page); }
/// <summary> /// Verifies if an element value attribute content is equals to the expected text. /// Wrapper method to WaitForTextToBePresentInValue /// </summary> /// <param name="expectedText">the expected text inside the web element</param> /// <param name="element">the web element</param> /// <param name="elementName">the element name</param> /// <param name="page">the element page name</param> protected void IsValuePresent(IWebElement element, String expectedValue, String elementName, String page) { WaitsHandler.WaitForTextToBePresentInValue(DriverManager.GetDriver(), element, expectedValue, elementName, page); }
/// <summary> /// Default constructor. /// Use PageFactory to initialize web elements. /// </summary> /// <param name="Driver">the <see cref="IWebDriver"/></param> public BasePage(IWebDriver Driver) { BaseDriver = Driver; PageFactory.InitElements(BaseDriver, this); WaitsHandler.WaitForAjaxToComplete(BaseDriver); }
/// <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 + "'"); }