Exemple #1
0
        public static UIObject ByNameAndClassName(UIObject root, string name, string className, bool shouldWait)
        {
            UICondition condition = UICondition.CreateFromName(name).AndWith(UICondition.CreateFromClassName(className));
            UIObject    uiObject  = null;

            root.Descendants.TryFind(condition, out uiObject);

            if (shouldWait && !root.Descendants.TryFind(condition, out uiObject))
            {
                Log.Comment("Object name = '{0}' className = '{1}' didn't exist, waiting...", name, className);
                try
                {
                    TestEnvironment.WaitUntilElementLoadedByName(name);
                    TestEnvironment.WaitUntilElementLoadedByClassName(className);
                }
                catch (WaiterTimedOutException)
                {
                    Log.Error("Could not find object with condition '{0}'!", condition.ToString());
                    DumpHelper.DumpFullContext();

                    throw;
                }

                root.Descendants.TryFind(condition, out uiObject);

                Log.Comment("...Found");
            }

            return(uiObject);
        }
        static void Main(string[] args)
        {
            UICondition        uIcondition = UICondition.Create("@Name='Puzzle'", new Object[0]);
            WindowOpenedWaiter wait        = new WindowOpenedWaiter(uIcondition);
            var ipy_proc = Process.Start(System.Environment.GetEnvironmentVariable("DLR_BIN") + "\\ipy.exe", " .\\puzzle.py");

            wait.Wait(30000);
            UIObject ui       = UIObject.Root.Children.Find(uIcondition);
            WinClass winClass = new WinClass(ui);

            try {
                winClass.Test_about();
                winClass.Test_options();
                winClass.Test_load();

                //http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=25404
                // winClass.Test_play();
                //exit verification
                winClass.Test_create();
                //http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=25404
                //winClass.Test_play();
                winClass.Test_exit();
            } catch (Exception e) {
                Console.WriteLine(e);
            } finally {
                //http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=19693
                if (!ipy_proc.HasExited)
                {
                    ipy_proc.Kill();
                }
            }
        }
        static void Main(string[] args)
        {
            UICondition        uIcondition = UICondition.Create("@Name='Frequency Modulation Synthesizer'", new Object[0]);
            WindowOpenedWaiter wait1       = new WindowOpenedWaiter(uIcondition);

            //Process.Start(args[0], ".\\fmsynth.py");

            Process.Start(args[0], ".\\fmsynth.py");
            wait1.Wait(60000);
            UIObject ui = UIObject.Root.Children.Find(uIcondition);

            try
            {
                WinClass winClass = new WinClass(ui);
                winClass.Test_ADDCarrierModulator();
                winClass.Test_RemoveSource();
                winClass.Test_Button_rightpane();
                winClass.Test_ComboBox();
                winClass.Test_Scrollbar();
                winClass.Test_Piano(MouseButtons.PhysicalLeft);
                winClass.Test_Stop();
                winClass.Test_Piano(MouseButtons.PhysicalRight);
                winClass.Test_StopAll();
                winClass.Test_Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #4
0
        public Application(string packageName, string packageFamilyName, string appName, string testAppMainWindowTitle, string testAppProcessName, string testAppInstallerName, string certSerialNumber, string baseAppxDir, bool isUWPApp, string unpackagedExePath, bool isPackaged)
        {
            _packageName       = packageName;
            _packageFamilyName = packageFamilyName;
            _appName           = appName;
            _isUWPApp          = isUWPApp;
            _isPackaged        = isPackaged;
            _unpackagedExePath = unpackagedExePath;
            _certSerialNumber  = certSerialNumber;
            _baseAppxDir       = baseAppxDir;

            _appWindowTitle   = testAppMainWindowTitle;
            _appProcessName   = testAppProcessName;
            _appInstallerName = testAppInstallerName;

            if (_isUWPApp && _isPackaged)
            {
                _windowCondition         = UICondition.Create("@ClassName='Windows.UI.Core.CoreWindow' AND @Name={0}", _appWindowTitle);
                _appFrameWindowCondition = UICondition.Create("@ClassName='ApplicationFrameWindow' AND @Name={0}", _appWindowTitle);
            }
            else
            {
                _windowCondition         = UICondition.Create("@ClassName='Window' AND @Name={0}", _appWindowTitle);
                _appFrameWindowCondition = UICondition.Create("@ClassName='Window' AND @Name={0}", _appWindowTitle);
            }
        }
 public ToolTipOpenedWaiter(UIObject rootElement, Scope scope, UICondition condition)
     : base(eventSource : new AutomationEventSource(eventId : AutomationElement.ToolTipOpenedEvent, root : rootElement, scope : scope))
 {
     Validate.ArgumentNotNull(parameter : condition, parameterName : nameof(condition));
     this._condition = condition;
     Start();
 }
Exemple #6
0
 public FocusAcquiredWaiter(UICondition condition)
     : base(eventSource : new FocusChangedEventSource())
 {
     Validate.ArgumentNotNull(parameter : condition, parameterName : nameof(condition));
     this._condition = condition;
     Start();
 }
Exemple #7
0
    public void play_puzzle()
    {
        int i;
        UICollection <UIObject> UICoPane;

        UICondition uIpane  = UICondition.Create("@ControlType=Pane", new Object[0]);
        UIObject    uIopane = this.Children.Find(uIpane);

        //UICondition uIpane = UICondition.Create("@ControlType=ControlType.Pane", new Object[0]);
        UICoPane = uIopane.Children.FindMultiple(uIpane);
        int Dim = UICoPane.Count;

        //foreach (UIObject i in UICoPane)
        //{
        //    Window objpuzzle = new Window(i);
        //    objpuzzle.Click();
        //}
        for (int aa = 0; aa < 40; aa++)
        {
            Random rand = new Random(Environment.TickCount);
            i = rand.Next(Dim);
            //Console.Write(i.ToString()+" : ");
            //Console.WriteLine(UICoPane.Count.ToString()+" : "+aa.ToString());
            Window objpuzzle = new Window(UICoPane[i]);
            objpuzzle.Click();
            Thread.Sleep(200);
        }
    }
 public ElementAddedWaiter(UIObject root, Scope scope, UICondition condition)
     : base(eventSource : new StructureChangedEventSource(root : root, scope : scope))
 {
     Validate.ArgumentNotNull(parameter : condition, parameterName : nameof(condition));
     this._condition = condition;
     Start();
 }
Exemple #9
0
        private static UICondition[] ParseConditions(List <ConditionElement> conditionList, GameObject go,
                                                     IReadOnlyLayoutContext context)
        {
            var conditions = new UICondition[conditionList.Count];

            for (int i = 0; i < conditionList.Count; ++i)
            {
                UICondition uiCondition = null;
                var         condition   = conditionList[i];

                if (condition is ConditionPointerOverElement)
                {
                    uiCondition = go.AddComponent <PointerIsOverCondition>();
                }
                else if (condition is ConditionNotElement notElement)
                {
                    var not = go.AddComponent <InverseCondition>();
                    not.originals = ParseConditions(notElement.Conditions, go, context);
                    Debug.Assert(not.originals.Length == 1);
                    uiCondition = not;
                }

                conditions[i] = uiCondition;
            }

            return(conditions);
        }
Exemple #10
0
        private bool CloseAppWindowWithCloseButton()
        {
            var topWindowCondition = _windowCondition.OrWith(_appFrameWindowCondition);

            UIObject topWindowObj  = null;
            bool     didFindWindow = UIObject.Root.Children.TryFind(topWindowCondition, out topWindowObj);

            if (!didFindWindow)
            {
                Log.Comment("Application.CloseAppWindowWithCloseButton: Cound not find app window.");
                return(false);
            }

            Log.Comment("Closing application: {0}", topWindowObj);
            UIObject closeAppInvoker;

            if (!topWindowObj.Descendants.TryFind(UICondition.Create("@AutomationId='__CloseAppInvoker'"), out closeAppInvoker))
            {
                Log.Comment("Application.CloseAppWindowWithCloseButton: Failed to find close app invoker.");
                return(false);
            }

            Log.Comment("Invoking CloseAppInvoker {0}", closeAppInvoker);
            (new Button(closeAppInvoker)).Invoke();

            bool didWindowClose = WaitForWindowToClose(topWindowCondition);

            if (!didWindowClose)
            {
                Log.Comment("Application.CloseAppWindowWithCloseButton: Window did not close");
                return(false);
            }

            return(true);
        }
Exemple #11
0
 void Initialize(AutomationElement root, UICondition treeCondition)
 {
     Validate.ArgumentNotNull(parameter: root, parameterName: nameof(root));
     Validate.ArgumentNotNull(parameter: treeCondition, parameterName: nameof(treeCondition));
     this._root       = root;
     this._treeWalker = new TreeWalker(condition: treeCondition.Condition);
 }
Exemple #12
0
        public void Test_ADDCarrierModulator()
        {
            UICondition uIconAddCa = UICondition.Create("@Name='Add Carrier'", new Object[0]);
            UICondition uIconAddMo = UICondition.Create("@Name='Add Modulator'", new Object[0]);
            Random      rand       = new Random(System.Environment.TickCount);
            UIObject    uIOAddCa   = this.uImain.Children.Find(uIconAddCa);
            UIObject    uIOAddMo   = this.uImain.Children.Find(uIconAddMo);

            uIOAddCa.Click();
            for (int i = 0; i < 25; i++)
            {
                int a = rand.Next(2);
                switch (a)
                {
                case 0:
                    uIOAddCa.Click();
                    CarNum++;
                    break;

                case 1:
                    uIOAddMo.Click();
                    break;
                }
            }
        }
Exemple #13
0
        public void Test_Piano(MouseButtons key)
        {
            UICondition uICoPiano = UICondition.Create("@Name='Volume'and @ControlType=Pane", new Object[0]);
            UIObject    uIPiano   = this.uImain.Children.Find(uICoPiano);

            for (int i = 10; i < 60; i = i + 20)
            {
                Mouse.Instance.Click(key, uIPiano, i, 50, ModifierKeys.None);
                Thread.Sleep(2000);
                switch (i)
                {
                case 70:
                    Mouse.Instance.Click(key, uIPiano, i + 10, 20, ModifierKeys.None);
                    Thread.Sleep(2000);
                    break;

                case 130:
                    Mouse.Instance.Click(key, uIPiano, i + 10, 20, ModifierKeys.None);
                    Thread.Sleep(2000);
                    break;

                case 190:
                    Mouse.Instance.Click(key, uIPiano, i + 10, 20, ModifierKeys.None);
                    Thread.Sleep(2000);
                    break;

                case 250:
                    Mouse.Instance.Click(key, uIPiano, i + 10, 20, ModifierKeys.None);
                    Thread.Sleep(2000);
                    break;
                }
            }
        }
Exemple #14
0
 internal UIItemContainerChildren(
     AutomationElement root,
     UICondition treeCondition,
     IFactory <I> factory)
     : base(navigator: new ItemContainerChildrenNavigator(root: root, treeCondition: treeCondition), factory: factory)
 {
 }
 internal UIBreadthFirstDescendants(
     AutomationElement root,
     UICondition treeCondition,
     IFactory <T> factory)
     : base(navigator: new BreadthFirstDescendantsNavigator(root: root, treeCondition: treeCondition), factory: factory)
 {
 }
Exemple #16
0
        public void Test_StopAll()
        {
            UICondition uICoStopAll = UICondition.Create("@Name='Stop All'", new Object[0]);
            UIObject    uIStopAll   = this.uImain.Children.Find(uICoStopAll);
            Button      button      = new Button(uIStopAll);

            button.Click();
        }
 public AppLaunchWaiter(UICondition topLevelWindowCondition)
 {
     this.topLevelWindowCondition = topLevelWindowCondition;
     this.waiters = new UIEventWaiter[2] {
         new WindowOpenedWaiter(condition: topLevelWindowCondition),
         new FocusAcquiredWaiter(condition: topLevelWindowCondition)
     };
 }
        private UIObject LaunchUWPApp(string packageName)
        {
            Debug.Assert(_isUWPApp);
            var nameCondition           = UICondition.CreateFromName(packageName);
            var topLevelWindowCondition = CreateTopLevelWindowCondition().AndWith(nameCondition);

            return(UAPApp.Launch(_appName, topLevelWindowCondition));
        }
 public static IEnumerable <UIObject> GetTopLevelWindowsClassicApp(
     int processId)
 {
     UICollection.Timeout = TimeSpan.Zero;
     foreach (var uiObject in UIObject.Root.Children.FindMultiple(condition: UICondition.Create(property: UIProperty.Get(name: "ProcessId"), value: processId).AndWith(newCondition: UICondition.Create(property: UIProperty.Get(name: "ControlType"), value: ControlType.Window))))
     {
         yield return(uiObject);
     }
 }
Exemple #20
0
        public void Test_Button_rightpane()
        {
            UICondition uICoUseRatio = UICondition.Create("@Name='Use ratio'", new Object[0]);
            UIObject    uIOUseRatio  = this.uImain.Children.Find(uICoUseRatio);
            CheckBox    cbox         = new CheckBox(uIOUseRatio);

            Thread.Sleep(400);
            cbox.Click();
        }
 public static IEnumerable <UIObject> GetTopLevelWindowsModernApp(int processId)
 {
     UICollection.Timeout = TimeSpan.Zero;
     foreach (var uiObject in UIObject.Root.Children.FindMultiple(condition: UICondition.CreateFromClassName(className: "ApplicationFrameWindow")))
     {
         if (uiObject.Children.Contains(uiProperty: UIProperty.Get(name: "ProcessId"), value: processId))
         {
             yield return(uiObject);
         }
     }
 }
Exemple #22
0
    public void Test_about()
    {
        UICondition uICondition  = UICondition.Create("@Name='about'", new Object[0]);
        UIObject    uIObject     = this.Descendants.Find(uICondition);
        Window      obj          = new Window(uIObject);
        UICondition uICondition2 = UICondition.Create("@Name='Tile Size'", new Object[0]);

        obj.Click();
        Thread.Sleep(300);
        UIObject result = this.Children.Find(uICondition2);
    }
 public AutomationEventWaiter(
     AutomationEvent eventId,
     UIObject uiObject,
     Scope scope,
     UICondition condition)
     : base(eventSource : new AutomationEventSource(eventId : eventId, root : uiObject, scope : scope))
 {
     Validate.ArgumentNotNull(parameter : condition, parameterName : nameof(condition));
     this._condition = condition;
     Start();
 }
Exemple #24
0
        public void Test_RemoveSource()
        {
            UICondition uICoRem = UICondition.Create("@Name='Remove Source'", new Object[0]);
            UIObject    uIRem   = this.uImain.Children.Find(uICoRem);
            Button      button  = new Button(uIRem);

            while (this.CarNum > 2)
            {
                button.Click();
                this.CarNum--;
            }
        }
Exemple #25
0
        public void Test_Scrollbar()
        {
            UICondition uICoScro  = UICondition.Create("@Name='Amplitude'and @ControlType=ScrollBar", new Object[0]);
            UIObject    uIScor    = this.uImain.Children.Find(uICoScro);
            ScrollBar   scrollBar = new ScrollBar(uIScor);
            Button      button    = new Button(scrollBar.Children.Find(UICondition.Create("@Name='Page left'", new Object[0])));

            for (int i = 1; i < 7; i++)
            {
                button.Click();
            }
        }
        public void Close()
        {
            if (Process != null)
            {
                Process.Dispose();
                Process = null;
            }

            var topWindowCondition = _windowCondition.OrWith(_appFrameWindowCondition);

            UIObject topWindowObj  = null;
            bool     didFindWindow = UIObject.Root.Children.TryFind(topWindowCondition, out topWindowObj);

            if (didFindWindow)
            {
                Log.Comment("Closing application: {0}", topWindowObj);
                UIObject closeAppInvoker;
                if (topWindowObj.Descendants.TryFind(UICondition.Create("@AutomationId='__CloseAppInvoker'"), out closeAppInvoker))
                {
                    (new Button(closeAppInvoker)).Invoke();
                }
                else
                {
                    Log.Comment("Application.Close: Failed to find close app invoker: {0}", closeAppInvoker);
                    TestEnvironment.LogDumpTree(UIObject.Root);
                }

                // We'll wait until the window closes.  For some reason, ProcessClosedWaiter
                // doesn't seem to actually work, so we'll instead just check for the window
                // until the check fails.
                int triesLeft = 20;

                do
                {
                    if (triesLeft == 0)
                    {
                        throw new Exception("Application won't close!");
                    }

                    Wait.ForMilliseconds(100);
                    didFindWindow = UIObject.Root.Children.TryFind(topWindowCondition, out topWindowObj);
                    triesLeft--;
                } while (didFindWindow);
            }
            else
            {
                Log.Comment("Could not find application CoreWindow.  Has it already closed?");
            }
        }
        private UICondition CreateTopLevelWindowCondition()
        {
            string deviceFamily = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;

            if (deviceFamily.Equals("Windows.Desktop", StringComparison.OrdinalIgnoreCase) ||
                deviceFamily.Equals("Windows.Server", StringComparison.OrdinalIgnoreCase) ||
                deviceFamily.Equals("Windows.Team", StringComparison.OrdinalIgnoreCase))
            {
                return(UICondition.CreateFromClassName("ApplicationFrameWindow"));
            }
            else
            {
                return(UICondition.CreateFromClassName("Windows.UI.Core.CoreWindow"));
            }
        }
        public void Test_Tutorial()
        {
            //checkpoint1
            UICondition        uIcondition = UICondition.Create("@ControlType=Window and @Name='IronPython Direct3D'", new object[0]);
            WindowOpenedWaiter wait1       = new WindowOpenedWaiter(uIcondition);

            Process.Start(CMD, ".\\tutorial.py");
            wait1.Wait(20000);
            UIObject ui          = UIObject.Root.Children.Find(uIcondition);
            UIObject uiClose     = ui.FirstChild.Children.Find("Close");
            Button   buttonClose = new Button(uiClose);

            Thread.Sleep(5000);
            buttonClose.Click();
        }
        public static void SetFocus(UIObject control)
        {
            if (!control.HasKeyboardFocus)
            {
                var uiCondition =
                    string.IsNullOrEmpty(control.AutomationId) ?
                    UICondition.CreateFromName(control.Name) :
                    UICondition.CreateFromId(control.AutomationId);

                using (var focusChangedWaiter = new FocusAcquiredWaiter(uiCondition))
                {
                    control.SetFocus();
                    focusChangedWaiter.Wait();
                }
            }
        }
Exemple #30
0
        public void Test_ComboBox()
        {
            UICondition uICoComboBox = UICondition.Create("@ControlType=ComboBox and @Name=':1'", new Object[0]);
            UIObject    uIComboBox   = this.uImain.Children.Find(uICoComboBox);
            ComboBox    combox       = new ComboBox(uIComboBox);

            Thread.Sleep(400);
            ListBox lbox = new ListBox(combox.FirstChild);

            for (int i = 1; i < 3; i++)
            {
                combox.Expand();
                lbox.Children[i].Click();
                Thread.Sleep(400);
            }
        }