public void ElementColor_IsCorrect(AutomatedElement Element, int r, int g, int b, string Element_Tag, ElementValidation validation) { string ElementColor = driver.driver.FindElement(Element.ByElement).GetCssValue("color"); ElementColor = ElementColor.Trim('r', 'g', 'b', 'a', '(', ')'); string[] a = ElementColor.Split(','); if (r == int.Parse(a[0]) && g == int.Parse(a[1]) && b == int.Parse(a[2])) { } else { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(Element_Tag, MessageType.NotCorrect, validation); testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(Element_Tag, MessageType.NotCorrect, validation); } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(Element_Tag, MessageType.NotCorrect, validation); } } }
private void ClearElement(AutomatedElement Element, String ElementName, ElementValidation Validation) { try { driver.driver.FindElement(Element.ByElement).Clear(); } catch { if (Validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.CantClearMsg, Validation); testMessages.End_Test(); } else if (Validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.CantClearMsg, Validation); } else if (Validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.CantClearMsg, Validation); } } }
protected void EnterText_UsingJS(AutomatedElement Element, string text, string ElementName, ElementValidation validation) { IWebElement elmnt = driver.driver.FindElement(Element.ByElement); IJavaScriptExecutor js = (IJavaScriptExecutor)driver.driver; try { js.ExecuteScript("arguments[0].value = '" + text + "';", elmnt); } catch { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.CantSendKeysMsg, validation); testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.CantSendKeysMsg, validation); } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.CantSendKeysMsg, validation); } } }
protected void SelectFromList_ByIndex(AutomatedElement Element, int Index, ElementValidation Validation) { //Find Element FindVisibleElement(20, Element, "Drop down Menu", ElementValidation.Mandatory); //Hover On Element HoverElement(Element); try { //Select from the list new SelectElement(driver.driver.FindElement(Element.ByElement)).SelectByIndex(Index); } catch { if (Validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage("Option " + Index, MessageType.CantSelectFromListMsg, Validation); testMessages.End_Test(); } else if (Validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage("Option " + Index, MessageType.CantSelectFromListMsg, Validation); } else if (Validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage("Option " + Index, MessageType.CantSelectFromListMsg, Validation); } } }
protected void HoverElement(AutomatedElement element) { Actions builder = new OpenQA.Selenium.Interactions.Actions(driver.driver); IWebElement _ELmentToHover = driver.driver.FindElement(element.ByElement); builder.MoveToElement(_ELmentToHover).Perform(); }
protected void EnterText_ToElement(AutomatedElement Element, string Key, String ElementName, ElementValidation validation) { //Clear Element ClearElement(Element, ElementName, validation); //Send Keys to element SendKeystoElement(Element, Key, ElementName, validation); }
protected bool IsElementPresent(AutomatedElement Element) { try { driver.driver.FindElement(Element.ByElement); return(true); } catch { return(false); } }
protected void FindVisibleElement(double Time, AutomatedElement Element, String ElementName, ElementValidation validation) { WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time)); try { wait.Until(ExpectedConditions.ElementExists(Element.ByElement)); } catch { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.NotFoundMsg, validation); testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.NotFoundMsg, validation); } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.NotFoundMsg, validation); } } //Ensure Element is visible try { wait.Until(ExpectedConditions.ElementIsVisible(Element.ByElement)); } catch { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.NotVisibleMsg, validation); testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.NotVisibleMsg, validation); } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.NotVisibleMsg, validation); } } }
protected void ClickElement(AutomatedElement Element, String ElementName, ElementValidation validation) { if (IsElementEnabled(Element)) { try { //Hover on the Element HoverElement(Element); driver.driver.FindElement(Element.ByElement).Click(); } catch { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.UnClickableMsg, validation); testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.UnClickableMsg, validation); } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.UnClickableMsg, validation); } } } else { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.NotEnabledMsg, validation); testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.NotEnabledMsg, validation); } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.NotEnabledMsg, validation); } } }
protected bool IsElementVisible(double Time, AutomatedElement Element) { WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time)); try { wait.Until(ExpectedConditions.ElementIsVisible(Element.ByElement)); return(true); } catch { return(false); } }
private bool IsElementEnabled(AutomatedElement Element) { IWebElement element = driver.driver.FindElement(Element.ByElement); if (element.Enabled) { if (element.GetAttribute("disabled") == "true") { return(false); } return(true); } else { return(false); } }
protected void Assert_Element_NotFound(double Time, AutomatedElement Element, String ElementName, ElementValidation ExistanceValidation, ElementValidation VisibilityValidation) { Thread.Sleep(TimeSpan.FromSeconds(Time)); if (IsElementPresent(Element)) { if (ExistanceValidation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.FoundInInvalidPlaceMsg, ExistanceValidation); testMessages.End_Test(); } else if (ExistanceValidation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.FoundInInvalidPlaceMsg, ExistanceValidation); } else if (ExistanceValidation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.FoundInInvalidPlaceMsg, ExistanceValidation); } if (IsElementVisible(Element)) { if (VisibilityValidation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(ElementName, MessageType.VisibleInInvalidPlaceMsg, VisibilityValidation); testMessages.End_Test(); } else if (VisibilityValidation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.VisibleInInvalidPlaceMsg, VisibilityValidation); } else if (VisibilityValidation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(ElementName, MessageType.VisibleInInvalidPlaceMsg, VisibilityValidation); } } } }
private bool IsElementVisible(AutomatedElement Element) { try { if (driver.driver.FindElement(Element.ByElement).Displayed) { return(true); } else { return(false); } } catch { return(false); } }
protected void Assert_Element_Contains_Text(AutomatedElement Element, string Expected_Text, string Element_Tag, ElementValidation validation) { //Find Element FindVisibleElement(30, Element, Element_Tag, validation); //Get Element Text string ElementInnerText = driver.driver.FindElement(Element.ByElement).Text; //Check if Element text contains Expected text if (driver.driver.FindElement(Element.ByElement).Text.ToLower().Contains(Expected_Text.ToLower())) { } else { if (validation == ElementValidation.Mandatory) { testMessages.Mandatory_Message = Messages.ReturnMessage(Element_Tag, MessageType.NotCorrect, validation); testMessages.Mandatory_Message += "\n The actual is '" + ElementInnerText + "' but expected '" + Expected_Text + "'"; testMessages.End_Test(); } else if (validation == ElementValidation.Non_Mandatory) { testMessages.Non_Mandatory_Message += "\n" + Messages.ReturnMessage(Element_Tag, MessageType.NotCorrect, validation); testMessages.Non_Mandatory_Message += "\n The actual is '" + ElementInnerText + "' but expected '" + Expected_Text + "'"; } else if (validation == ElementValidation.Non_Mandatory_Till_EOT) { testMessages.Non_Mandatory_Till_EOT_Message += "\n" + Messages.ReturnMessage(Element_Tag, MessageType.NotCorrect, validation); testMessages.Non_Mandatory_Till_EOT_Message += "\n The actual is '" + ElementInnerText + "' but expected '" + Expected_Text + "'"; } } }
public string ReturnElementText(AutomatedElement Element) { //Return its text return(driver.driver.FindElement(Element.ByElement).Text); }