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); } } }
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 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 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); } } }
public void Ensure_Session_Title_SessionView_IsCorrect(string SessionTitle, ElementValidation validation) { Ensure_ElementTxt_IsCorrect(lbl_SessionTitle, SessionTitle, "Session Title", validation); }
public void Assert_LastQueryCotainsCorrectCriteria(List <string> CriteriaList, ElementValidation validation) { for (int i = 0; i < CriteriaList.Count; i++) { Assert_Element_Contains_Text(lnk_LastQuery, CriteriaList[i], "Last Search Query", validation); } }
public void Assert_LocationRangeList_NotDisplayed(ElementValidation validation) { Assert_Element_NotFound(2, select_LocationRange, "Location Range List", validation, validation); }
public void Assert_ApartmentPriceMatchesSearchCriteria(string MinmumPrice, string MaximumPrice, OfferTypes Offer, ElementValidation validation) { int ResultInPrice = 0; if (Offer == OfferTypes.ForSale) { string ApartmentPriceText = ReturnElementText(span_ApartmentPrice).Trim(',', 'k', 'k', '.', '.', '€', ' ', ' '); ResultInPrice = int.Parse(ApartmentPriceText, NumberStyles.Currency); } else if (Offer == OfferTypes.ForRent) { ResultInPrice = int.Parse(ReturnElementText(span_ApartmentPrice).Trim('d', 'm', 'n', '/', '.', '€', ' ')); } int MinPrice = int.Parse(MinmumPrice.Trim('€', ','), NumberStyles.Currency); int MaxPrice = 0; if (MaximumPrice == "No limit") { Assert_Number_GreaterThanAnotherNumber(ResultInPrice, MinPrice, "Apartment Price", validation); } else { MaxPrice = int.Parse(MaximumPrice.Trim('€', ','), NumberStyles.Currency); Assert_Number_BetweenTwoNumbers(ResultInPrice, MinPrice, MaxPrice, "Apartment Price", validation); } }
protected void Assert_Number_BetweenTwoNumbers(int NumberToCheck, int Min, int Max, string Element_Tag, ElementValidation validation) { //Check if NumberToCheck is between Min and Max if (NumberToCheck >= Min && NumberToCheck <= Max) { } 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); } } }
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 + "'"; } } }
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); } } } }
public static string ReturnMessage(String ElementName, MessageType messageType, ElementValidation validation) { switch (messageType) { case MessageType.NotFoundMsg: return("Unable to locate element [" + ElementName + "] _ [" + validation + "]"); break; case MessageType.UnClickableMsg: return("Unable to click on element [" + ElementName + "] _ [" + validation + "]"); break; case MessageType.NotVisibleMsg: return("This Element isn't visible [" + ElementName + "] _ [" + validation + "]"); break; case MessageType.NotEnabledMsg: return("This Element is not enabled [ " + ElementName + " ] _ [ " + validation + " ]"); break; case MessageType.CantSendKeysMsg: return("Unable to enter text to element " + ElementName + "] _ [" + validation + "]"); break; case MessageType.CantClearMsg: return("Unable to clear element " + ElementName + "] _ [" + validation + "]"); break; case MessageType.NoSuchFrameMsg: return("Unable to find Frame " + ElementName + "] _ [" + validation + "]"); break; case MessageType.FoundInInvalidPlaceMsg: return("Element " + ElementName + "] is found in invalid place _ [" + validation + "]"); break; case MessageType.VisibleInInvalidPlaceMsg: return("Element " + ElementName + "] is visible in invalid place _ [" + validation + "]"); break; case MessageType.EnabledInInvalidPlaceMsg: return("Element " + ElementName + "] is enabled in invalid place _ [" + validation + "]"); break; case MessageType.CantSelectFromListMsg: return("Can't Select " + ElementName + "] From List _ [" + validation + "]"); break; case MessageType.NotSelectedMsg: return("Element " + ElementName + "] isn't selected [" + validation + "]"); break; case MessageType.NotCorrect: return("Element " + ElementName + "] text isn't correct [" + validation + "]"); break; case MessageType.WrongColor: return("Element " + ElementName + "] color isn't correct [" + validation + "]"); break; default: return("Invalid Operation with" + ElementName); break; } }
public void Ensure_Session_Time_SessionView_IsCorrect(string SessionTime, ElementValidation validation) { Ensure_Element_Contains_Text(lbl_sessionTime, SessionTime, "Session Time", validation); }
public void Ensure_Session_Duration_SessionView_IsCorrect(string SessionDuration, ElementValidation validation) { Ensure_Element_Contains_Text(lbl_sessionDuration, SessionDuration, "Session Duration", validation); }
public void Ensure_Session_Objectives_SessionView_IsCorrect(string SessionObjectives, ElementValidation validation) { Ensure_ElementTxt_IsCorrect(lbl_sessionObjectives, SessionObjectives, "Session Objectives", validation); }
protected void Assert_Number_GreaterThanAnotherNumber(int NumberToCheck, int Min, string Element_Tag, ElementValidation validation) { //Check if NumberToCheck is greater than Min if (NumberToCheck >= Min) { } 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); } } }
public void Assert_AddressContains_SearchAddress(string SearchAddress, ElementValidation validation) { Assert_Element_Contains_Text(span_ApartmentAddress, SearchAddress, SearchAddress, validation); }
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); } } }
public void Assert_NoResultMessage_Displayed(ElementValidation validation) { FindVisibleElement(20, lbl_NoResult, "No Search Result Message", validation); }
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); } } }
public void Assert_MaximumPriceList_NotDisplayed(ElementValidation validation) { Assert_Element_NotFound(2, select_MaxPrice, "Maximum Price List", validation, validation); }
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); }
public void Assert_MaxPrice_Color_IsCorrect(ElementValidation validation) { ColorObject MaxPriceColor = new ColorObject(240, 60, 48); ElementColor_IsCorrect(select_MaxPrice, MaxPriceColor.r, MaxPriceColor.g, MaxPriceColor.b, "Max Price Color", validation); }
public void Ensure_Session_IsDisplayed_CourseMap(string SessionTitle, ElementValidation validation) { AutomatedElement lbl_SessionInMap = new AutomatedElement(LocateBy.XPath, LocatorValue: "//*[@title='" + SessionTitle + "']"); ExplicitlyConfirm_ElementFound(20, lbl_SessionInMap, "Session with Title " + SessionTitle, validation); }