Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
 public void FixtureTestCloseDuringModalDialog()
 {
     UiAutomationFixture.SearchBy("Name");
     Assert.IsTrue(_fixture.StartApplication("notepad.exe"), "Notepad started");
     Assert.IsTrue(_fixture.ClickControl("File"), "Click File Menu");
     Assert.IsTrue(_fixture.WaitForControlAndClick("Page Setup..."), "Click Page Setup menu");
     Assert.IsTrue(_fixture.WaitForControl("Page Setup"), "Wait for Page Setup dialog");
     Assert.IsFalse(_fixture.CloseApplication(), "Closing application with a modal dialog open should fail");
     Assert.IsTrue(_fixture.ForcedCloseApplication(), "Forced closing application with a modal dialog open should succeed");
 }