Пример #1
0
        public void FixtureIsUwpTest()
        {
            var fixture = new UiAutomationFixture();

            fixture.StartApplication("notepad");
            Assert.IsNotNull(fixture.ApplicationProcessId);
            var process = Process.GetProcessById(fixture.ApplicationProcessId.Value);

            Assert.IsFalse(AppLauncher.IsUwpApp(process.Handle), "Notepad is not UWP");
            Assert.IsTrue(fixture.CloseApplication(), "Close notepad");
            fixture.StartApplicationWithArguments(@"windows.immersivecontrolpanel_cw5n1h2txyewy", null);
            Assert.IsNotNull(fixture.ApplicationProcessId);
            var pid = fixture.ApplicationProcessId.Value;

            process = Process.GetProcessById(pid);
            Assert.IsTrue(AppLauncher.IsUwpApp(process.Handle), "App is UWP");
            Assert.AreEqual(IntPtr.Zero, process.MainWindowHandle, "Main window handle for Uwp window is 0");
            Assert.IsTrue(fixture.SwitchToParentWindow(), "Switch to parent");
            Assert.AreNotEqual(pid, fixture.ApplicationProcessId, @"Pids are not equal");
            Assert.IsTrue(AppLauncher.IsUwpApp(process.Handle), "Parent is UWP");
            Assert.IsNotNull(fixture.ApplicationProcessId);
            process = Process.GetProcessById(fixture.ApplicationProcessId.Value);
            Assert.AreNotEqual(IntPtr.Zero, process.MainWindowHandle, "Main window handle for Uwp parent window is not 0");
            Assert.IsTrue(fixture.SwitchToProcess("ProcessId:" + pid), "Switch to child");
            Assert.IsTrue(fixture.CloseApplication(), "Close UWP app");
        }
Пример #2
0
        public void AppLauncherUwpAppTest()
        {
            var fixture = new UiAutomationFixture();

            UiAutomationFixture.TimeoutSeconds = 2;
            Assert.IsTrue(
                fixture.StartApplicationWithArguments(@"windows.immersivecontrolpanel_cw5n1h2txyewy", null));
            Assert.IsTrue(fixture.IsUwpApp(), "Is UWP App");
            // Switch to parent as that contains the close button. Elements on child windows are found too.
            // UWP apps have a container called Application Frame Host.
            // So they are not direct children of the desktop, unlike "normal" applications.
            // That means that you need to use "descendants" rather than "children" in findfirst,
            // which is slow especially if a control is not found

            // TODO: You need to be very careful here. Sometimes the wrong close button gets pushed.
            // e.g. once I had an existing Calculator instance running, and the process closed
            // Edge instead of the new calculator window. Still need to find out how to prevent that.
            // For now the workaround is ensuring that there are no other instances of your app running.

            Assert.IsTrue(fixture.SwitchToParentWindow(), "Switch to parent.");

            Assert.IsTrue(fixture.ClickControl("ControlType:ListItem && name:System"));
            Assert.IsTrue(fixture.WaitForControl("id:PagesListView"));
            Assert.IsTrue(fixture.WaitForControlAndClick("Name:About"));
            // This is needed. If you don't do it, the process gets into a locked state.
            Assert.IsTrue(fixture.WaitForControl("ControlType:Text && name:About"), "Wait for About text");
            // The About title comes earlier than the rest of the page, so wait for the control we want to examine
            Assert.IsTrue(fixture.WaitForControl("id:SystemSettings_PCSystem_VersionString_ValueTextBlock"));
            var version = fixture.ValueOfControl("id:SystemSettings_PCSystem_VersionString_ValueTextBlock");

            Debug.Print("Version from settings: " + version);
            Assert.IsTrue(int.TryParse(version, out _), "Version is numerical");
            Assert.IsTrue(fixture.ClickControl("name:Close Settings"), "Press Close Settings");
        }
Пример #3
0
        public void FixtureAppUsageFailures()
        {
            var fixture = new UiAutomationFixture();

            UiAutomationFixture.SearchBy("Name");
            Assert.IsFalse(fixture.SwitchToAppWindow(), "Cannot switch to app window if not started");
            Assert.IsFalse(fixture.SwitchToParentWindow(), "cannot switch to parent if no app launched");
            Assert.IsFalse(fixture.IsUwpApp(), "IsUwpApp returns false if no app started");
#pragma warning disable 618
            Assert.IsFalse(fixture.SwitchToWindow("irrelevant"), @"Can't switch to nonexisting window");
#pragma warning restore 618
            Assert.IsFalse(fixture.SwitchToProcess("irrelevant"));
            Assert.IsFalse(fixture.MaximizeWindow(), "Can't maximize nonexisting window");
            Assert.IsFalse(fixture.MinimizeWindow(), "Can't minimize nonexisting window");
            Assert.IsFalse(fixture.MoveWindowTo(new Coordinate(10, 10)), "Can't move nonexisting window");
            Assert.IsFalse(fixture.NormalWindow(), "Can't restore nonexisting window");
            Assert.IsFalse(fixture.ResizeWindowTo(new Coordinate(100, 100)), "Can't resize nonexisting window");
            var topleft = fixture.WindowTopLeft;
            var size    = fixture.WindowSize;
            Assert.AreEqual(0, size.X, "Width of nonexisting window is 0");
            Assert.AreEqual(0, size.Y, "height of nonexisting window is 0");
            Assert.AreEqual(0, topleft.X, "Row of nonexisting window is 0");
            Assert.AreEqual(0, topleft.Y, "Column of nonexisting window is 0");
        }