public static string CreateXPathCondition(this TermMatch match, string value, string operand = ".") { if (match != TermMatch.Equals) { value.CheckNotNullOrEmpty(nameof(value)); } operand.CheckNotNullOrEmpty(nameof(operand)); string valueString = XPathString.ConvertTo(value); switch (match) { case TermMatch.Contains: return($"contains({operand}, {valueString})"); case TermMatch.Equals: return(value is null && operand != "." ? $"not({operand})" : $"normalize-space({operand}) = {valueString}"); case TermMatch.StartsWith: return($"starts-with(normalize-space({operand}), {valueString})"); case TermMatch.EndsWith: return($"substring(normalize-space({operand}), string-length(normalize-space({operand})) - {value.Length - 1}) = {valueString}"); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(match, nameof(match)); } }
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)); }
public static Type ResolveFindAttributeType(this FindTermBy by) { switch (by) { case FindTermBy.Id: return(typeof(FindByIdAttribute)); case FindTermBy.Name: return(typeof(FindByNameAttribute)); case FindTermBy.Class: return(typeof(FindByClassAttribute)); case FindTermBy.Label: return(typeof(FindByLabelAttribute)); case FindTermBy.Content: return(typeof(FindByContentAttribute)); case FindTermBy.Value: return(typeof(FindByValueAttribute)); case FindTermBy.ContentOrValue: return(typeof(FindByContentOrValueAttribute)); case FindTermBy.ColumnHeader: return(typeof(FindByColumnHeaderAttribute)); case FindTermBy.Title: return(typeof(FindByTitleAttribute)); case FindTermBy.FieldSet: return(typeof(FindByFieldSetAttribute)); case FindTermBy.Placeholder: return(typeof(FindByPlaceholderAttribute)); case FindTermBy.DescriptionTerm: return(typeof(FindByDescriptionTermAttribute)); case FindTermBy.ChildContent: return(typeof(FindByChildContentAttribute)); case FindTermBy.Alt: return(typeof(FindByAltAttribute)); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(by, nameof(by)); } }
public static Actions MoveToElement( this Actions actions, IWebElement toElement, int offsetX, int offsetY, UIComponentOffsetKind offsetKind) { if (offsetX == 0 && offsetY == 0 && (offsetKind == UIComponentOffsetKind.FromCenterInPercents || offsetKind == UIComponentOffsetKind.FromCenterInPixels)) { return(actions.MoveToElement(toElement)); } Size elementSize = toElement.Size; switch (offsetKind) { case UIComponentOffsetKind.FromCenterInPercents: return(actions.MoveToElement( toElement, (int)(elementSize.Width * ((float)offsetX / 100)), (int)(elementSize.Height * ((float)offsetY / 100)), MoveToElementOffsetOrigin.Center)); case UIComponentOffsetKind.FromCenterInPixels: return(actions.MoveToElement( toElement, offsetX, offsetY, MoveToElementOffsetOrigin.Center)); case UIComponentOffsetKind.FromTopLeftInPercents: return(actions.MoveToElement( toElement, (int)(elementSize.Width * ((float)offsetX / 100)) - (elementSize.Width / 2), (int)(elementSize.Height * ((float)offsetY / 100)) - (elementSize.Height / 2), MoveToElementOffsetOrigin.Center)); case UIComponentOffsetKind.FromTopLeftInPixels: return(actions.MoveToElement( toElement, offsetX - (elementSize.Width / 2), offsetY - (elementSize.Height / 2), MoveToElementOffsetOrigin.Center)); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(offsetKind, nameof(offsetKind)); } }
private static Func <IWebElement, bool> CreateVisibilityPredicate(Visibility visibility) { switch (visibility) { case Visibility.Visible: return(x => x.Displayed); case Visibility.Hidden: return(x => !x.Displayed); case Visibility.Any: return(x => true); default: throw ExceptionFactory.CreateForUnsupportedEnumValue <Visibility>(visibility, nameof(visibility)); } }
internal static string GetShouldText(this TermMatch match) { switch (match) { case TermMatch.Contains: return("contain"); case TermMatch.Equals: return("equal"); case TermMatch.StartsWith: return("start with"); case TermMatch.EndsWith: return("end with"); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(match, nameof(match)); } }
public static Func <string, string, bool> GetPredicate(this TermMatch match) { switch (match) { case TermMatch.Contains: return((text, term) => text.Contains(term)); case TermMatch.Equals: return((text, term) => text.Trim() == term); case TermMatch.StartsWith: return((text, term) => text.Trim().StartsWith(term)); case TermMatch.EndsWith: return((text, term) => text.Trim().EndsWith(term)); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(match, nameof(match)); } }
public static string GetXPathOperationFormat(this TermMatch match) { switch (match) { case TermMatch.Contains: return("contains({0}, '{1}')"); case TermMatch.Equals: return("normalize-space({0}) = '{1}'"); case TermMatch.StartsWith: return("starts-with(normalize-space({0}), '{1}')"); case TermMatch.EndsWith: return("substring(normalize-space({0}), string-length(normalize-space({0})) - string-length('{1}') + 1) = '{1}'"); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(match, nameof(match)); } }
private Func <IWebElement, string> CreateGetContentDelegate(ContentSource source) { switch (source) { case ContentSource.Text: return(element => element.Text); case ContentSource.TextContent: return(element => element.GetAttribute("textContent").Trim()); case ContentSource.InnerHtml: return(element => element.GetAttribute("innerHTML").Trim()); case ContentSource.Value: return(element => element.GetAttribute("value")); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(source, nameof(source)); } }
public static IWebElement GetScopeElement(this ScopeSource scopeSource, UIComponent component) { switch (scopeSource) { case ScopeSource.Parent: return(component.Parent.Scope); case ScopeSource.Grandparent: return(component.Parent.Parent.Scope); case ScopeSource.PageObject: return(component.Owner.Scope); case ScopeSource.Page: return(component.Driver.Get(By.TagName("body"))); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(scopeSource, nameof(scopeSource)); } }
private static string ResolveResultPrefix(AssertionStatus status) { switch (status) { case AssertionStatus.Passed: return(null); case AssertionStatus.Warning: return(WarningResultPrefix); case AssertionStatus.Failed: return(FailedResultPrefix); case AssertionStatus.Exception: return(ExceptionResultPrefix); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(status, nameof(status)); } }
public static ISearchContext GetScopeContextUsingParent <TOwner>(this ScopeSource scopeSource, IUIComponent <TOwner> parentComponent) where TOwner : PageObject <TOwner> { switch (scopeSource) { case ScopeSource.Parent: return(parentComponent.ScopeContext); case ScopeSource.Grandparent: return((parentComponent.Parent ?? throw UIComponentNotFoundException.ForParentOf(parentComponent.ComponentFullName)).ScopeContext); case ScopeSource.PageObject: return(parentComponent.Owner.ScopeContext); case ScopeSource.Page: return((parentComponent?.Context ?? AtataContext.Current).Driver); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(scopeSource, nameof(scopeSource)); } }
public static IWebElement GetScopeElementUsingParent <TOwner>(this ScopeSource scopeSource, IUIComponent <TOwner> parentComponent) where TOwner : PageObject <TOwner> { switch (scopeSource) { case ScopeSource.Parent: return(parentComponent.Scope); case ScopeSource.Grandparent: return(parentComponent.Parent.Scope); case ScopeSource.PageObject: return(parentComponent.Owner.Scope); case ScopeSource.Page: return(AtataContext.Current.Driver.Get(By.TagName("body"))); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(scopeSource, nameof(scopeSource)); } }
public static ISearchContext GetScopeContext(this ScopeSource scopeSource, UIComponent component, SearchOptions options = null) { options = options ?? new SearchOptions(); switch (scopeSource) { case ScopeSource.Parent: return(component.Parent.GetScopeContext(options)); case ScopeSource.Grandparent: return(component.Parent.Parent.GetScopeContext(options)); case ScopeSource.PageObject: return(component.Owner.GetScopeContext(options)); case ScopeSource.Page: return(component.Driver); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(scopeSource, nameof(scopeSource)); } }
[Obsolete("Use GetScopeContext(...) instead.")] // Obsolete since v1.5.0. public static IWebElement GetScopeElement(this ScopeSource scopeSource, UIComponent component, SearchOptions options = null) { options = options ?? new SearchOptions(); switch (scopeSource) { case ScopeSource.Parent: return(component.Parent.GetScope(options)); case ScopeSource.Grandparent: return(component.Parent.Parent.GetScope(options)); case ScopeSource.PageObject: return(component.Owner.GetScope(options)); case ScopeSource.Page: return(component.Driver.GetWithLogging(By.TagName("body").With(options))); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(scopeSource, nameof(scopeSource)); } }
public static By GetBy(this WaitBy waitBy, string selector) { switch (waitBy) { case WaitBy.Id: return(By.Id(selector)); case WaitBy.Name: return(By.Name(selector)); case WaitBy.Class: return(By.ClassName(selector)); case WaitBy.Css: return(By.CssSelector(selector)); case WaitBy.XPath: return(By.XPath(selector)); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(waitBy, nameof(waitBy)); } }
protected WaitUnit[] GetWaitUnits(WaitUntil until) { switch (until) { case WaitUntil.Missing: return(new[] { CreateAbsenceUnit(Visibility.Any) }); case WaitUntil.Hidden: return(new[] { CreatePresenceUnit(Visibility.Hidden) }); case WaitUntil.MissingOrHidden: return(new[] { CreateAbsenceUnit(Visibility.Visible) }); case WaitUntil.Visible: return(new[] { CreatePresenceUnit(Visibility.Visible) }); case WaitUntil.VisibleOrHidden: return(new[] { CreatePresenceUnit(Visibility.Any) }); case WaitUntil.VisibleThenHidden: return(new[] { CreatePresenceUnit(Visibility.Visible), CreatePresenceUnit(Visibility.Hidden) }); case WaitUntil.VisibleThenMissing: return(new[] { CreatePresenceUnit(Visibility.Visible), CreateAbsenceUnit(Visibility.Any) }); case WaitUntil.VisibleThenMissingOrHidden: return(new[] { CreatePresenceUnit(Visibility.Visible), CreateAbsenceUnit(Visibility.Visible) }); case WaitUntil.MissingThenVisible: return(new[] { CreateAbsenceUnit(Visibility.Any), CreatePresenceUnit(Visibility.Visible) }); case WaitUntil.HiddenThenVisible: return(new[] { CreatePresenceUnit(Visibility.Hidden), CreatePresenceUnit(Visibility.Visible) }); case WaitUntil.MissingOrHiddenThenVisible: return(new[] { CreateAbsenceUnit(Visibility.Visible), CreatePresenceUnit(Visibility.Visible) }); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(until, nameof(until)); } }
public static WaitUnit[] GetWaitUnits(this Until until, WaitOptions options = null) { if (options == null) { options = new WaitOptions(); } switch (until) { case Until.Missing: return(new[] { CreateAbsenceUnit(Visibility.Any, until, options) }); case Until.Hidden: return(new[] { CreatePresenceUnit(Visibility.Hidden, until, options) }); case Until.MissingOrHidden: return(new[] { CreateAbsenceUnit(Visibility.Visible, until, options) }); case Until.Visible: return(new[] { CreatePresenceUnit(Visibility.Visible, until, options) }); case Until.VisibleOrHidden: return(new[] { CreatePresenceUnit(Visibility.Any, until, options) }); case Until.VisibleThenHidden: return(new[] { CreatePresenceUnit(Visibility.Visible, until, options), CreatePresenceUnit(Visibility.Hidden, until, options) }); case Until.VisibleThenMissing: return(new[] { CreatePresenceUnit(Visibility.Visible, until, options), CreateAbsenceUnit(Visibility.Any, until, options) }); case Until.VisibleThenMissingOrHidden: return(new[] { CreatePresenceUnit(Visibility.Visible, until, options), CreateAbsenceUnit(Visibility.Visible, until, options) }); case Until.MissingThenVisible: return(new[] { CreateAbsenceUnit(Visibility.Any, until, options), CreatePresenceUnit(Visibility.Visible, until, options) }); case Until.HiddenThenVisible: return(new[] { CreatePresenceUnit(Visibility.Hidden, until, options), CreatePresenceUnit(Visibility.Visible, until, options) }); case Until.MissingOrHiddenThenVisible: return(new[] { CreateAbsenceUnit(Visibility.Visible, until, options), CreatePresenceUnit(Visibility.Visible, until, options) }); default: throw ExceptionFactory.CreateForUnsupportedEnumValue(until, nameof(until)); } }