/// <summary> /// Wait generic method which will be called by every wait operation. /// The method will determine the condition and parameters and returns accordingly /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="process">the process that will be used to satisfy the condition. For example, () => element.Text().HasValue() </param> /// <param name="reasonForFailedCondition"></param> /// <param name="whenConditionFailed"></param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> internal static bool WaitGeneric(this IWebElement element, IWebDriver driver, int waitTimeSec, bool throwExceptionWhenNotFound, string errorMessage, Func <bool> process, string reasonForFailedCondition, bool whenConditionFailed = false, IBaseControl baseControl = null) { waitTimeSec = waitTimeSec == 0 ? SeAppConfig.DefaultTimeoutWaitPeriodInSeconds : waitTimeSec; var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitTimeSec)); var conditionSatisfied = false; var messageOnFail = errorMessage.HasValue() ? errorMessage : $"Waiting for element failed with reason: {reasonForFailedCondition}"; try { conditionSatisfied = wait.Until(d => { try { return(process()); } catch (Exception) { return(whenConditionFailed); } }); } catch (Exception ex) { if (throwExceptionWhenNotFound) { if (baseControl == null) { throw new WebControlException(driver, ex, messageOnFail, uiControl: element); } else { throw new WebControlException(driver, ex, messageOnFail, uiControl: baseControl); } } } if (!conditionSatisfied && throwExceptionWhenNotFound) { if (baseControl == null) { throw new ElementUnavailableException(driver, messageOnFail, element); } else { throw new ElementUnavailableException(driver, messageOnFail, baseControl); } } return(conditionSatisfied); }
protected static string CreateGenericDetailsMessage(IWebDriver driver, IBaseControl uiControl, string message = null) { try { return($"{message}: UI element of type {uiControl?.ToString()} on page: {driver?.Url}"); } catch (Exception) { return(message); } }
/// <summary> /// Wait until the element has any text on it /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementHasSomeText( this IWebElement element, IWebDriver driver, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element.Exists() && element.Text.HasValue(), $"Wait until the element contains any text value", baseControl: baseControl);
/// <summary> /// Wait until the element is clickable /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementIsClickable( this IWebElement element, IWebDriver driver, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element.Exists() && element.Displayed && element.IsCssDisplayed() && element.Enabled, "Wait until element is clickable", baseControl: baseControl);
/// <summary> /// Wait until the element is Css Displayed (display: none not applied) /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementCssDisplayed( this IWebElement element, IWebDriver driver, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element.IsCssDisplayed(), "Wait until displayed (not have display-none)", baseControl: baseControl);
/// <summary> /// Wait until the element exists /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementExists( this IWebElement element, IWebDriver driver, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element.Exists(), "Wait until exists", baseControl: baseControl);
/// <summary> /// Wait until the element is not visible /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementInvisible( this IWebElement element, IWebDriver driver, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => !element?.Displayed ?? true, "Wait until element is invisible", baseControl: baseControl);
/// <summary> /// Wait until the text on the element contains one of the element in the collection of text passed for match /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="textsToMatch">text collection that will be used for the match</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementTextContains( this IWebElement element, IWebDriver driver, string[] textsToMatch, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element.Exists() && textsToMatch.Any(text => element.Text.Contains(text)), $"Wait till either one of the Text contains '{string.Join(",", textsToMatch)}'", baseControl: baseControl);
/// <summary> /// Wait until the text on the element contains the text passed for match /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="textToMatch">text that will be used for the match</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementTextContains( this IWebElement element, IWebDriver driver, string textToMatch, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element.Exists() && element.Text.Contains(textToMatch), $"Wait till Text contains '{textToMatch}'", baseControl: baseControl);
/// <summary> /// Wait until the text on the element after trim is starts with the text passed for match /// </summary> /// <param name="element">element (IWebElement) for which the operation is performed</param> /// <param name="driver">driver (IWebDriver) associated with the element</param> /// <param name="textToMatch">text that will be used for the match</param> /// <param name="waitTimeSec">total amount of time to wait (in seconds) to meet the condition</param> /// <param name="throwExceptionWhenNotFound">throw an exception when the condition is not met</param> /// <param name="errorMessage">message for the exception when condition is not met</param> /// <param name="baseControl">the custom control associated with this IWebElement (element). The custom control can be passed as null if it is not associated</param> /// <returns>true when the condition is met or else returns false</returns> public static bool WaitUntilElementTextStartsWith( this IWebElement element, IWebDriver driver, string textToMatch, int waitTimeSec, bool throwExceptionWhenNotFound = true, string errorMessage = null, IBaseControl baseControl = null) => element.WaitGeneric(driver, waitTimeSec, throwExceptionWhenNotFound, errorMessage, () => element != null ? (element.Exists() && element.Text.Trim().StartsWith(textToMatch)) : false, $"Wait till Text starts with '{textToMatch}'", baseControl: baseControl);
public bool SubmitPressed() { bool retval = true; foreach (var x in SubContPanel.Children) { IBaseControl ibc = x as IBaseControl; if (ibc != null) { if (!ibc.SubmitPressed()) { retval = false; } } } return(retval); }
private IBaseControl Base() { IBaseControl obj = null; Cookie Cookie = new Cookie(); Enumerations.PageType CookiePageType = (Enumerations.PageType)(int.Parse(Cookie.Read(EnumUtil.Cookies.PageType))); if (CookiePageType == Enumerations.PageType.Company) { obj = new BaseCompany(); } else if (CookiePageType == Enumerations.PageType.Employee) { obj = new BaseEmployee(); } else { Util.GoToEntryPage(this.Response); } return(obj); }
/// <summary> /// Create a control based on the type /// </summary> /// <typeparam name="T">Type of control, for example WebControl or Button</typeparam> /// <param name="driver">WebDriver related to area where the control is going be created</param> /// <param name="selector">How to map the control in the UI</param> /// <param name="parentControl">If the control is to be search with in a parent control</param> /// <returns></returns> public static T CreateNew <T>(IWebDriver driver, By selector, IBaseControl parentControl = null) where T : BaseControl { var type = typeof(T).Name; if (typeof(T) == typeof(WebControl)) { return(new WebControl(driver, selector, parentControl as BaseControl) as T); } else if (typeof(T) == typeof(ButtonControl)) { return(new ButtonControl(driver, selector, parentControl as BaseControl) as T); } else if (typeof(T) == typeof(CheckboxControl)) { return(new CheckboxControl(driver, selector, parentControl as BaseControl) as T); } else if (typeof(T) == typeof(LinkControl)) { return(new LinkControl(driver, selector, parentControl as BaseControl) as T); } else if (typeof(T) == typeof(TextboxControl)) { return(new TextboxControl(driver, selector, parentControl as BaseControl) as T); } else if (typeof(T) == typeof(SelectControl)) { return(new SelectControl(driver, selector, parentControl as BaseControl) as T); } else if (typeof(T) == typeof(FileUploadControl)) { return(new FileUploadControl(driver, selector, parentControl as BaseControl) as T); } else { return(new WebControl(driver, selector, parentControl as BaseControl) as T); } }
public WebControlException(IWebDriver driver, Exception innerException, string message = null, IBaseControl uiControl = null) : base(message.HasValue() ? message : innerException.Message, innerException) { WebDriver = driver; BaseControl = uiControl; }
public WebControlException(IWebDriver driver, Exception innerException, IBaseControl uiControl) : this(driver, innerException, message : null, uiControl : uiControl) { }
public WebControlException(IWebDriver driver, string message, IBaseControl uiControl) : base(message) { WebDriver = driver; BaseControl = uiControl; }
private void IsLogin(IBaseControl BaseType) { BaseType.IsLogin(); }
private void GoToLogonPage(IBaseControl BaseType) { BaseType.GoToLogonPage(); }
private bool LoginControl(IBaseControl BaseType, string Email, string Password) { return(BaseType.LoginControl(Email, Password)); }
private void GoToDefaultPage(IBaseControl BaseType) { BaseType.GoToDefaultPage(); }
/// <summary> /// Seta todos os DataBind do formulário. /// </summary> /// <param name="controle">Nome do controle para o bind</param> /// <param name="tp_Status">Status do formulário</param> internal void setarReadOnly_FormStatus(Control.ControlCollection controle, CompSoft.TipoFormStatus tp_Status) { foreach (Control ctrl in controle) { //-- Caso o controle possua mais controles internos. if (ctrl.Controls.Count > 0) { //-- Chama o mesmo método para obter os controles. //-- Este processo utiliza recurcividade. setarReadOnly_FormStatus(ctrl.Controls, tp_Status); } if (ctrl.GetType().GetInterface("IBaseControl", true) != null) { //-- Atualiza estado do controle IBaseControl cc = ctrl as IBaseControl; IBaseControl_DB cc_DB = null; if (ctrl.GetType().GetInterface("IBaseControl_DB", true) != null) { cc_DB = cc as IBaseControl_DB; } switch (tp_Status) { case CompSoft.TipoFormStatus.Pesquisar: cc.ReadOnly = true; break; case CompSoft.TipoFormStatus.Limpar: cc.ReadOnly = false; if (cc_DB != null && string.IsNullOrEmpty(cc_DB.ControlSource) && ctrl.GetType() == typeof(cf_TextBox)) { ctrl.Text = string.Empty; } break; case CompSoft.TipoFormStatus.Modificando: //-- Verifica se o controle é identity if (cc_DB != null && Control_IsIdentity(ref cc_DB)) { cc.ReadOnly = true; } else { cc.ReadOnly = false; } break; case CompSoft.TipoFormStatus.Nenhum: cc.ReadOnly = true; break; case CompSoft.TipoFormStatus.Novo: if (ctrl.GetType() == typeof(cf_TreeView)) { ((cf_Bases.cf_TreeView)ctrl).Clear(); } //-- Verifica se o controle é identity if (cc_DB != null && this.Control_IsIdentity(ref cc_DB)) { cc.ReadOnly = true; } else { cc.ReadOnly = false; } break; } } } }
private string Show(IBaseControl BaseType) { return(BaseType.Show()); }
public ElementUnavailableException(IWebDriver driver, IBaseControl uiControl) : base(driver, CreateGenericDetailsMessage(driver, uiControl, "Element unavailable"), uiControl) { }