internal static string FormatComponentName(this TermMatch match, string[] values) { string format; switch (match) { case TermMatch.Contains: format = "Containing '{0}'"; break; case TermMatch.Equals: format = "{0}"; break; case TermMatch.StartsWith: format = "Starting with '{0}'"; break; case TermMatch.EndsWith: format = "Ending with '{0}'"; break; default: throw ExceptionFactory.CreateForUnsupportedEnumValue(match, nameof(match)); } string combinedValues = TermResolver.ToDisplayString(values); return(string.Format(format, combinedValues)); }
/// <summary> /// Converts the string to value of <typeparamref name="T"/> type for <see cref="GetValue"/> method. /// Can use format from <see cref="ValueGetFormatAttribute"/>, /// otherwise from <see cref="FormatAttribute"/>. /// Can use culture from <see cref="CultureAttribute"/>. /// </summary> /// <param name="value">The value as string.</param> /// <returns>The value converted to <typeparamref name="T"/> type.</returns> protected virtual T ConvertStringToValueUsingGetFormat(string value) { string getFormat = Metadata.Get <ValueGetFormatAttribute>()?.Value; return(getFormat != null ? TermResolver.FromString <T>(value, new TermOptions().MergeWith(ValueTermOptions).WithFormat(getFormat)) : ConvertStringToValue(value)); }
/// <summary> /// Converts the value to string for <see cref="SetValue(T)"/> method. /// Can use format from <see cref="ValueSetFormatAttribute"/>, /// otherwise from <see cref="FormatAttribute"/>. /// Can use culture from <see cref="CultureAttribute"/>. /// </summary> /// <param name="value">The value.</param> /// <returns>The value converted to string.</returns> protected virtual string ConvertValueToStringUsingSetFormat(T value) { string setFormat = Metadata.Get <ValueSetFormatAttribute>()?.Value; return(setFormat != null ? TermResolver.ToString(value, new TermOptions().MergeWith(ValueTermOptions).WithFormat(setFormat)) : ConvertValueToString(value)); }
protected IEnumerable <TData> SelectElementValues <TData>( string elementXPath, string elementValueJSPath, TermOptions valueTermOptions) { var elements = GetItemElements(extraXPath: elementXPath); return(GetElementTextValues(elements, elementValueJSPath). Select(x => TermResolver.FromString <TData>(x, valueTermOptions))); }
/// <summary> /// Gets the value of the specified control's scope element attribute. /// </summary> /// <typeparam name="TValue">The type of the attribute value.</typeparam> /// <param name="attributeName">The name of the attribute.</param> /// <returns>The attribute's current value. /// Returns <see langword="null"/> if the value is not set.</returns> public TValue GetValue <TValue>(string attributeName) { string valueAsString = Component.Scope.GetAttribute(attributeName); if (string.IsNullOrEmpty(valueAsString) && typeof(TValue) == typeof(bool)) { return(default(TValue)); } return(TermResolver.FromString <TValue>(valueAsString)); }
protected override By CreateScopeBy() { string scopeXPath = Metadata.ComponentDefinitionAttribute?.ScopeXPath ?? "body"; StringBuilder xPathBuilder = new StringBuilder($".//{scopeXPath}"); string titleElementXPath = Metadata.Get <WindowTitleElementDefinitionAttribute>()?.ScopeXPath; if (CanFindByWindowTitle && !string.IsNullOrWhiteSpace(titleElementXPath)) { xPathBuilder.Append( $"[.//{titleElementXPath}[{WindowTitleMatch.CreateXPathCondition(WindowTitleValues)}]]"); } return(By.XPath(xPathBuilder.ToString()).PopupWindow(TermResolver.ToDisplayString(WindowTitleValues))); }
protected internal string ConvertIndividualValuesToString(IEnumerable <T> values, bool wrapWithDoubleQuotes) { string[] stringValues = values.Select(x => TermResolver.ToString(x, ValueTermOptions)).ToArray(); if (stringValues.Length == 0) { return("<none>"); } else if (wrapWithDoubleQuotes) { return(stringValues.ToQuotedValuesListOfString(doubleQuotes: true)); } else { return(string.Join(", ", stringValues)); } }
public override string GetXPathCondition(object parameter, TermOptions termOptions) { IWebElement scope = component.ScopeSource.GetScopeElement(component, SearchOptions.SafelyAtOnce()); IWebElement label = scope.Get( By.XPath($".//label[{TermResolver.CreateXPathCondition(parameter, termOptions)}]"). SafelyAtOnce(). Label(TermResolver.ToDisplayString(parameter))); if (label != null) { string elementId = label.GetAttribute("for"); if (!string.IsNullOrEmpty(elementId)) { return($"[@id='{elementId}']"); } } return($"[ancestor::label[{TermResolver.CreateXPathCondition(parameter, termOptions)}]]"); }
/// <summary> /// Converts the string to value of <typeparamref name="T"/> type. /// Can use format from <see cref="FormatAttribute"/>. /// Can use culture from <see cref="CultureAttribute"/>. /// </summary> /// <param name="value">The value as string.</param> /// <returns>The value converted to <typeparamref name="T"/> type.</returns> protected internal virtual T ConvertStringToValue(string value) { return(TermResolver.FromString <T>(value, ValueTermOptions)); }
private TValue Convert <TValue>(string parameterValue) { return(typeof(TValue) == typeof(string) ? (TValue)(object)(parameterValue ?? string.Empty) : TermResolver.FromString <TValue>(parameterValue)); }
protected string CreateSimpleXPathCodition(string locatorXPathFormat, object parameter, TermOptions termOptions, string operand) { string xPathCondition = TermResolver.CreateXPathCondition(parameter, termOptions, operand); return(locatorXPathFormat.FormatWith(xPathCondition)); }
public T GetParameter <T>(IWebElement element, TermOptions termOptions) { string value = GetParameterAsString(element); return(TermResolver.FromString <T>(value, termOptions)); }
internal static string ConvertValueToString <TValue, TOwner>(this IDataProvider <TValue, TOwner> provider, TValue value) where TOwner : PageObject <TOwner> { return(TermResolver.ToString(value, provider.ValueTermOptions)); }
public override string GetXPathCondition(object parameter, TermOptions termOptions) { return($"[{RelativeElementXPath}[{TermResolver.CreateXPathCondition(parameter, termOptions)}]]"); }
public override string GetXPathCondition(object parameter, TermOptions termOptions) { return($"[{TermResolver.CreateXPathCondition(parameter, termOptions, "@value")}]"); }