// Tests should scroll to their bottom most element to ensure the entire // test UI is onscreen otherwise the fake input injection will fail. // // Potentially has side effects depending on if a scroll item implementation can be retrieved public static void ScrollToElement(UIObject uiObject) { Log.Comment("ScrollToElement: " + uiObject.ToString()); bool successfullyScrolled = false; ScrollItemImplementation scrollItem = new ScrollItemImplementation(uiObject); if (scrollItem.IsAvailable) { Log.Comment("Using ScrollItemImplementation to scroll"); scrollItem.ScrollIntoView(); successfullyScrolled = true; } if (!successfullyScrolled) { Log.Comment("Using ScrollItem UIA pattern to scroll"); var previouslyFocusedElement = AutomationElement.FocusedElement; uiObject.SetFocus(); Wait.ForIdle(); var newFocusedElement = AutomationElement.FocusedElement; object scrollItemPatternAsObject; newFocusedElement.TryGetCurrentPattern(ScrollItemPattern.Pattern, out scrollItemPatternAsObject); if (scrollItemPatternAsObject != null) { var scrollItemPattern = (ScrollItemPattern)scrollItemPatternAsObject; scrollItemPattern.ScrollIntoView(); } if (previouslyFocusedElement != null) { previouslyFocusedElement.SetFocus(); } } Wait.ForIdle(); }
private static RetStructure OperationProcess(CmdStructure cmdobj) { RetStructure res = new RetStructure("S"); string qstr = ""; string pqstr = ""; string cidx = ""; if (cmdobj.ObjectID != null) qstr = GetQueryStr(cmdobj.ObjectID); if (cmdobj.PObjectID != null) pqstr = GetQueryStr(cmdobj.PObjectID); if (cmdobj.CollectIndex != null) cidx = cmdobj.CollectIndex; switch (cmdobj.OperName) { case "click": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyClickObj = GetMyObj(qstr, pqstr, cidx); MyClickObj.Highlight(); MyClickObj.Tap(); break; case "press": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyPressObj = GetMyObj(qstr, pqstr, cidx); MyPressObj.Highlight(); MyPressObj.TapAndHold(); break; case "tap": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); MyGlobalObj.Highlight(); MyGlobalObj.Tap(Convert.ToInt32(cmdobj.Pos[0]), Convert.ToInt32(cmdobj.Pos[1])); break; case "taphold": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); MyGlobalObj.Highlight(); MyGlobalObj.TapAndHold(Convert.ToInt32(cmdobj.Pos[0]), Convert.ToInt32(cmdobj.Pos[1])); break; case "flick": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); MyGlobalObj.Highlight(); MyGlobalObj.Flick(new Point(Convert.ToInt32(cmdobj.Pos[0]), Convert.ToInt32(cmdobj.Pos[1])), new Point(Convert.ToInt32(cmdobj.PosDest[0]), Convert.ToInt32(cmdobj.PosDest[1]))); break; case "get": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); if (cidx == "-1") { UICondition MyGetCondi = UICondition.Create(qstr); UICollection<UIObject> MyGetCol; if (pqstr == "") { MyGetCol = UIObject.Root.Descendants.FindMultiple(MyGetCondi); } else { UICondition MyPGetCondi = UICondition.Create(pqstr); UIObject MyPGetObj = UIObject.Root.Descendants.Find(MyPGetCondi); MyGetCol = MyPGetObj.Descendants.FindMultiple(MyGetCondi); } int i = 0; IEnumerator<UIObject> enumerator = MyGetCol.GetEnumerator(); res.PropertyDict = new Dictionary<int, string>(); while (enumerator.MoveNext()) { res.PropertyDict.Add(i, enumerator.Current.GetProperty(UIProperty.Get(cmdobj.PropName)).ToString()); i++; } } else { UIObject MyGetObj = GetMyObj(qstr, pqstr, cidx); MyGetObj.Highlight(); res.Property = MyGetObj.GetProperty(UIProperty.Get(cmdobj.PropName)).ToString(); } break; case "check": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UICondition MyFindCondi = UICondition.Create(qstr); UIObject MyFindObj; if (pqstr == "") { if (UIObject.Root.Descendants.TryFind(MyFindCondi, out MyFindObj)) { res.Found = true; MyFindObj.Highlight(); } else { res.Found = false; } } else { UICondition MyPCondi = UICondition.Create(pqstr); UIObject MyPObj = UIObject.Root.Descendants.Find(MyPCondi); if (MyPObj.Descendants.TryFind(MyFindCondi, out MyFindObj)) { res.Found = true; MyFindObj.Highlight(); } else { res.Found = false; } } break; case "hard": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); switch (cmdobj.HardButton) { case "start": ButtonInput.DoTap(HardwareButton.HardwareButtonTypes.Start); break; case "back": ButtonInput.DoTap(HardwareButton.HardwareButtonTypes.Back); break; case "search": ButtonInput.DoTap(HardwareButton.HardwareButtonTypes.Search); break; case "power": ButtonInput.DoTap(HardwareButton.HardwareButtonTypes.Power); break; case "volup": ButtonInput.DoTap(HardwareButton.HardwareButtonTypes.VolumeUp); break; case "voldown": ButtonInput.DoTap(HardwareButton.HardwareButtonTypes.VolumeDown); break; case "lock": if (ls.DisplayOn) lm.Lock(); break; case "unlock": if (lm.IsLocked) ls.StartUnlock(); break; default: Console.WriteLine(" CmdProcess: Unhandled Argument: {0}", cmdobj.HardButton); break; } break; case "capture": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); ScreenCapture.SaveImage(cmdobj.SaveImagePath); break; case "ping": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); break; case "invoke": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyInvokeObjT = GetMyObj(qstr, pqstr, cidx); MyInvokeObjT.Highlight(); InvokeImplementation MyInvokeObj = new InvokeImplementation(MyInvokeObjT); using (UIEventWaiter MyInvokeWaiter = MyInvokeObj.GetInvokedWaiter()) { MyInvokeObj.Invoke(); MyInvokeWaiter.Wait(); } break; case "text": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyTextObjT = GetMyObj(qstr, pqstr, cidx); MyTextObjT.Highlight(); ValueImplementation MyTextObj = new ValueImplementation(MyTextObjT); MyTextObj.SetValue(cmdobj.TextMsg); break; case "scrollh": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyScrollhObjT = GetMyObj(qstr, pqstr, cidx); MyScrollhObjT.Highlight(); ScrollImplementation MyScrollhObj = new ScrollImplementation(MyScrollhObjT); MyScrollhObj.SetScrollPercent(Convert.ToDouble(cmdobj.ScrollPercent), MyScrollhObj.VerticalScrollPercent); break; case "scrollv": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyScrollvObjT = GetMyObj(qstr, pqstr, cidx); MyScrollvObjT.Highlight(); ScrollImplementation MyScrollvObj = new ScrollImplementation(MyScrollvObjT); MyScrollvObj.SetScrollPercent(MyScrollvObj.HorizontalScrollPercent, Convert.ToDouble(cmdobj.ScrollPercent)); break; case "switch": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MySwitchObjT = GetMyObj(qstr, pqstr, cidx); MySwitchObjT.Highlight(); ScrollItemImplementation MySwitchObj = new ScrollItemImplementation(MySwitchObjT); MySwitchObj.ScrollIntoView(); break; case "list": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyListObjT = GetMyObj(qstr, pqstr, cidx).Children[Convert.ToInt32(cmdobj.ListIndex)]; MyListObjT.Highlight(); InvokeImplementation MyListObj = new InvokeImplementation(MyListObjT); MyListObj.Invoke(); break; case "convert": Console.WriteLine(" CmdProcess: Process {0}", cmdobj.OperName); UIObject MyConvertObj = UIObject.FromPoint(new Point(Convert.ToInt32(cmdobj.Pos[0]), Convert.ToInt32(cmdobj.Pos[1]))); res.ObjectID = new Dictionary<string, string>(); string tmp; tmp = MyConvertObj.GetProperty(UIProperty.Get("AutomationId")).ToString(); if (tmp != "") res.ObjectID.Add("AutomationId", @"'" + tmp + @"'"); tmp = MyConvertObj.GetProperty(UIProperty.Get("ClassName")).ToString(); if (tmp != "") res.ObjectID.Add("ClassName", @"'" + tmp + @"'"); tmp = MyConvertObj.GetProperty(UIProperty.Get("ControlType")).ToString(); if (tmp != "") res.ObjectID.Add("ControlType", tmp.Substring(12, tmp.Length - 12)); tmp = MyConvertObj.GetProperty(UIProperty.Get("Name")).ToString(); if (tmp != "") res.ObjectID.Add("Name", @"'" + tmp + @"'"); break; default: Console.WriteLine(" CmdProcess: Unhandled Operation: {0}", cmdobj.OperName); break; } return res; }
void Initialize(IFactory <C> containerFactory) { SelectionItemProvider = new SelectionItemImplementation <C>(uiObject: this, containerFactory: containerFactory); ScrollItemProvider = new ScrollItemImplementation(uiObject: this); VirtualizedItemProvider = new VirtualizedItemImplementation(uiObject: this); }