Beispiel #1
0
        public static string GetText(this UIObject textControl, bool shouldTrim = true)
        {
            string              textControlContents = null;
            TextImplementation  textImplementation  = new TextImplementation(textControl);
            ValueImplementation valueImplementation = new ValueImplementation(textControl);

            if (textImplementation.IsAvailable)
            {
                textControlContents = textImplementation.DocumentRange.GetText(-1);
            }
            else if (valueImplementation.IsAvailable)
            {
                textControlContents = valueImplementation.Value;
            }
            else
            {
                Verify.Fail(string.Format("Expected the text control to implement either IValue or IText. {0} is {1}", string.IsNullOrEmpty(textControl.AutomationId) ? textControl.Name : textControl.AutomationId, textControl.GetDescription()));
            }

            // On phone, copying or pasting text causes a space to be added at the end.
            // Unless we explicitly care about that space, we'll remove it from the return value.
            if (shouldTrim)
            {
                textControlContents = textControlContents.Trim();
            }

            return(textControlContents);
        }
Beispiel #2
0
        private void CanUndoAndRedoIn(string textControlName)
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Warning("Test is disabled pre-RS5 because programmatically undoing and redoing in text controls is not supported pre-RS5");
                return;
            }

            using (var setup = new TextCommandBarFlyoutTestSetupHelper())
            {
                UIObject            textControl        = FindElement.ById(textControlName);
                ValueImplementation textControlAsValue = new ValueImplementation(textControl);

                string initialString = textControl.GetText();
                Log.Comment("Initial contents of {0} are '{1}'", textControlName, initialString);

                Log.Comment("Selecting all text in the {0}.", textControlName);
                FindElement.ById <Button>(string.Format("{0}SelectAllButton", textControlName)).InvokeAndWait();

                Log.Comment("Giving the {0} focus.", textControlName);
                FocusHelper.SetFocus(textControl);

                Log.Comment("Typing 'hello' into the {0}.", textControlName);
                TextInput.SendText("hello");
                Wait.ForIdle();

                string finalString = textControl.GetText();
                Log.Comment("Contents of {0} are now '{1}'", textControlName, finalString);

                Log.Comment("Opening TextCommandBarFlyout.");
                OpenFlyoutOn(textControlName, asTransient: false);

                using (ValueChangedEventWaiter waiter = textControlAsValue.IsAvailable ? new ValueChangedEventWaiter(new Edit(textControl), initialString) : null)
                {
                    Log.Comment("Undoing text entry.");
                    FindElement.ByName <Button>("Undo").InvokeAndWait();
                }

                Log.Comment("Contents of {0} are now '{1}'", textControlName, textControl.GetText());
                Verify.AreEqual(initialString, textControl.GetText());

                Log.Comment("Reopening TextCommandBarFlyout.");
                OpenFlyoutOn(textControlName, asTransient: false);

                using (ValueChangedEventWaiter waiter = textControlAsValue.IsAvailable ? new ValueChangedEventWaiter(new Edit(textControl), finalString) : null)
                {
                    Log.Comment("Redoing text entry.");
                    FindElement.ByName <Button>("Redo").InvokeAndWait();
                }

                Log.Comment("Contents of {0} are now '{1}'", textControlName, textControl.GetText());
                Verify.AreEqual(finalString, textControl.GetText());
            }
        }
        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;
        }
Beispiel #4
0
        public static string GetDescription(this UIObject obj)
        {
            List <string> patternsSupported       = new List <string>();
            StringBuilder extraInformationBuilder = new StringBuilder();

            DockImplementation           dockImplementation           = new DockImplementation(obj);
            ExpandCollapseImplementation expandCollapseImplementation = new ExpandCollapseImplementation(obj);
            InvokeImplementation         invokeImplementation         = new InvokeImplementation(obj);
            RangeValueImplementation     rangeValueImplementation     = new RangeValueImplementation(obj);
            ScrollImplementation         scrollImplementation         = new ScrollImplementation(obj);
            TextImplementation           textImplementation           = new TextImplementation(obj);
            ToggleImplementation         toggleImplementation         = new ToggleImplementation(obj);
            ValueImplementation          valueImplementation          = new ValueImplementation(obj);
            WindowImplementation         windowImplementation         = new WindowImplementation(obj);

            if (dockImplementation.IsAvailable)
            {
                patternsSupported.Add("Dock");
                extraInformationBuilder.AppendFormat(", Dock.DockPosition={0}", dockImplementation.DockPosition);
            }

            if (expandCollapseImplementation.IsAvailable)
            {
                patternsSupported.Add("ExpandCollapse");
                extraInformationBuilder.AppendFormat(", ExpandCollapse.ExpandCollapseState={0}", expandCollapseImplementation.ExpandCollapseState);
            }

            if (invokeImplementation.IsAvailable)
            {
                patternsSupported.Add("Invoke");
            }

            if (rangeValueImplementation.IsAvailable)
            {
                patternsSupported.Add("RangeValue");
                extraInformationBuilder.AppendFormat(", RangeValue.Minimum={0}, RangeValue.Maximum={1}, RangeValue.LargeChange={2}, RangeValue.SmallChange={3}, RangeValue.Value={4}, RangeValue.IsReadOnly={5}",
                                                     rangeValueImplementation.Minimum, rangeValueImplementation.Maximum,
                                                     rangeValueImplementation.LargeChange, rangeValueImplementation.SmallChange,
                                                     rangeValueImplementation.Value,
                                                     rangeValueImplementation.IsReadOnly);
            }

            if (scrollImplementation.IsAvailable)
            {
                patternsSupported.Add("Scroll");
                extraInformationBuilder.AppendFormat(", Scroll.HorizontallyScrollable={0}, Scroll.VerticallyScrollable={1}, Scroll.HorizontalScrollPercent={2}, Scroll.VerticalScrollPercent={3}, Scroll.HorizontalViewSize={4}, Scroll.VerticalViewSize={5}",
                                                     scrollImplementation.HorizontallyScrollable, scrollImplementation.VerticallyScrollable,
                                                     scrollImplementation.HorizontalScrollPercent, scrollImplementation.VerticalScrollPercent,
                                                     scrollImplementation.HorizontalViewSize, scrollImplementation.VerticalViewSize);
            }

            if (textImplementation.IsAvailable)
            {
                patternsSupported.Add("Text");
                string textContent = textImplementation.DocumentRange.GetText(-1);
                extraInformationBuilder.AppendFormat(", Text.Text=\"{0}\", Text.SupportsTextSelection={1}", textContent.Substring(0, Math.Min(100, textContent.Length)), textImplementation.SupportsTextSelection);
            }

            if (toggleImplementation.IsAvailable)
            {
                patternsSupported.Add("Toggle");
                extraInformationBuilder.AppendFormat(", Toggle.ToggleState={0}", toggleImplementation.ToggleState);
            }

            if (valueImplementation.IsAvailable)
            {
                patternsSupported.Add("Value");
                extraInformationBuilder.AppendFormat(", Value.Value=\"{0}\", Value.IsReadOnly={1}", valueImplementation.Value, valueImplementation.IsReadOnly);
            }

            if (windowImplementation.IsAvailable)
            {
                patternsSupported.Add("Window");
                extraInformationBuilder.AppendFormat(", Window.CanMaximize={0}, Window.CanMinimize={1}, Window.IsModal={2}, Window.WindowVisualState={3}, Window.WindowInteractionState={4}, Window.IsTopmost={5}",
                                                     windowImplementation.CanMaximize, windowImplementation.CanMinimize, windowImplementation.IsModal,
                                                     windowImplementation.WindowVisualState, windowImplementation.WindowInteractionState, windowImplementation.IsTopmost);
            }

            string patternsSupportedString = string.Empty;

            if (patternsSupported.Count > 0)
            {
                patternsSupportedString = string.Format(", PatternsSupported={0}", string.Join(";", patternsSupported));
            }

            return(string.Format("{0} [Aid={1}, Class={2}, Type={3}{4}{5}]", obj.Name, obj.AutomationId, obj.ClassName, obj.ControlType, patternsSupportedString, extraInformationBuilder.ToString()));
        }
Beispiel #5
0
 void Initialize(IFactory <I> itemFactory)
 {
     GridProvider      = new GridImplementation <I>(uiObject: this, itemFactory: itemFactory);
     SelectionProvider = new SelectionImplementation <I>(uiObject: this, itemFactory: itemFactory);
     ValueProvider     = new ValueImplementation(uiObject: this);
 }