コード例 #1
0
        private Collection <Collection <string> > CreateBaseResult()
        {
            List <Control> list;

            if (_processId != null)
            {
                var app = ApplicationFactory.AttachToProcess(_processId.Value);
                app.WaitForInputIdle();
                var control = app.WindowControl;
                // This is not only necessary to potentially wait, but also to populate the parent property in the control.
                control.WaitTillFound();
                list = control.DescendantControls(_searchCriterion).ToList();
            }
            else
            {
                list = Control.RootChildControls(_searchCriterion).ToList();
            }

            var rows = new Collection <Collection <string> > {
                new Collection <string> {
                    "Automation Id", "Name", "Value", "Location"
                }
            };

            foreach (var entry in list)
            {
                var position = Mouse.AbsolutePosition(entry.AutomationElement);
                var row      = new Collection <string> {
                    entry.AutomationId, entry.Name, entry.Value, Invariant($"x:{position.X}, y:{position.Y}")
                };
                rows.Add(row);
            }
            return(rows);
        }
コード例 #2
0
        public void ApplicationFactoryStartClassicTest()
        {
            var app = ApplicationFactory.Start("notepad.exe", null);

            app.WaitForInputIdle();
            Assert.IsInstanceOfType(app, typeof(ClassicApplication));
            var app1 = ApplicationFactory.AttachToProcess(app.ProcessId);

            Assert.IsInstanceOfType(app1, typeof(ClassicApplication));
            Assert.AreEqual(app.ProcessId, app1.ProcessId);
            ExtensionFunctions.TimeoutInMilliseconds = 1000;
            Assert.IsTrue(app.Exit(false));
            Assert.IsFalse(app.IsActive, "App is not active");
            Assert.IsFalse(app1.IsActive, "App1 is not active");
        }
コード例 #3
0
        public void ApplicationFactoryStartUwpTest()
        {
            var app = ApplicationFactory.Start(@"windows.immersivecontrolpanel_cw5n1h2txyewy", null);

            app.WaitForInputIdle();
            Assert.IsInstanceOfType(app, typeof(UwpApplication));
            var app1 = ApplicationFactory.AttachToProcess(app.ProcessId);

            Debug.WriteLine(app1.ProcessId);
            Assert.IsInstanceOfType(app1, typeof(UwpApplication));
            Assert.AreEqual(app.ProcessId, app1.ProcessId);
            ExtensionFunctions.TimeoutInMilliseconds = 3000;
            Assert.IsTrue(app.Exit(false));
            Assert.IsFalse(app.IsActive, "App is not active");
            Assert.IsFalse(app1.IsActive, "App1 is not active");
            Assert.IsNull(app1.WindowControl, "WindowControl for exited app is null");
            ExtensionFunctions.TimeoutInMilliseconds = 1000;
            Assert.IsTrue(app1.Exit(false), "Exiting a second time should work");
        }