public void ThenThereIsATextboxToTheRightOf(ThatIs direction, string labelText) { FindTextBox(direction, labelText); Context.TextBox .Should() .NotBeNull(); }
public void WhenIUseTheTextboxNearLabel(ThatIs direction, string labelText) { FindTextBox(direction, labelText); Context.TextBox .Should() .NotBeNull(); }
protected TUiType LocateClosestElementOfType <TUiType>(string labelText, string widgetText, ThatIs direction) where TUiType : UIItem { return(RetryLocate(() => { var window = Context.Window; var label = window.Get <Label>(SearchCriteria.ByText(labelText)); var possibleItems = window.GetMultiple(SearchCriteria.ByText(widgetText)); return FindClosestTo <TUiType>(label, possibleItems, direction); })); }
protected TUiType LocateClosestElementOfType <TUiType>(string labelText, ThatIs direction = ThatIs.InAnyDirection) where TUiType : UIItem { return(RetryLocate(() => { var window = Context.Window; var label = window.Get <Label>(SearchCriteria.ByText(labelText)); var theType = typeof(TUiType); var possibleItems = window.GetMultiple(SearchCriteria.ByControlType(testControlType: theType, framework: WindowsFramework.Wpf)); return FindClosestTo <TUiType>(label, possibleItems, direction); })); }
private static void SetNames() { Thing.SetName("thing"); Link.SetName("link"); IsA.SetName("is a"); IsNotA.SetName("is not a"); Of.SetName("of"); And.SetName("and"); ThatConsistsOf.SetName("that consists of"); Has.SetName("has"); Contains.SetName("contains"); ContainedBy.SetName("contained by"); One.SetName("one"); Zero.SetName("zero"); Character.SetName("character"); Sum.SetName("sum"); String.SetName("string"); Name.SetName("name"); Set.SetName("set"); Group.SetName("group"); ParsedFrom.SetName("parsed from"); ThatIs.SetName("that is"); ThatIsBefore.SetName("that is before"); ThatIsAfter.SetName("that is after"); ThatIsBetween.SetName("that is between"); ThatIsRepresentedBy.SetName("that is represented by"); ThatHas.SetName("that has"); Text.SetName("text"); Path.SetName("path"); Content.SetName("content"); Empty.SetName("empty"); EmptyContent.SetName("empty content"); Alphabet.SetName("alphabet"); Letter.SetName("letter"); Case.SetName("case"); Upper.SetName("upper"); Lower.SetName("lower"); Code.SetName("code"); }
void FindTextBox(ThatIs direction, string labelText) { Context.TextBox = RetryLocate(() => LocateClosestElementOfType <TextBox>(labelText: labelText, direction: direction)); }
static TUiType FindClosestTo <TUiType>(IUIItem referencePoint, IEnumerable <IUIItem> possibleItems, ThatIs direction) where TUiType : UIItem { var labelPosition = referencePoint.Location; Func <IUIItem, IUIItem, bool> predicate; switch (direction) { case ThatIs.Underneath: predicate = (item, lbl) => item.Location.Y > lbl.Location.Y; break; case ThatIs.Above: predicate = (item, lbl) => item.Location.Y < lbl.Location.Y; break; case ThatIs.ToLeftOf: predicate = (item, lbl) => item.Location.X < lbl.Location.X; break; case ThatIs.InAnyDirection: predicate = (item, lbl) => true; // our orderby below takes care of this break; case ThatIs.ToRightOf: predicate = (item, lbl) => item.Location.X > lbl.Location.X; break; default: var error = string.Format( "Unmapped 'ThatIs' value '{0}'. Edit WpfBaseSteps to add a case statement for this value!", direction); throw new Exception(error); } var pair = (from item in possibleItems where predicate(item, referencePoint) // only below select new { widget = item, distance = (item.Location - labelPosition).Length } ).OrderBy(p => p.distance) .FirstOrDefault(); if (pair == null) { return(null); } var widget = pair.widget; Console.WriteLine(@"Located widget ID:{0} Name: {1} Location: {2}", widget.Id, widget.Name, widget.Location); return((TUiType)widget); }