Beispiel #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");
        }
Beispiel #2
0
        public void FixtureNotePadCheckSetValueResizeMoveAndScreenshot()
        {
            try
            {
                UiAutomationFixture.TimeoutSeconds = 1;
                UiAutomationFixture.SearchBy("Name");
                Assert.IsTrue(_fixture.CloseApplication(), "Stopping an app before it started should succeed");
                Assert.IsTrue(_fixture.ForcedCloseApplication(), "Forced stopping an app before it started should succeed");
                Assert.IsTrue(_fixture.StartApplication("notepad.exe"), "Notepad started");
                Assert.IsTrue(_fixture.SetValueOfControlTo("classname:edit",
                                                           "The quick brown fox jumps over the lazy dog."), "Set Text");
                Assert.IsTrue(_fixture.PressKey("^{END}{ENTER}Hello{ENTER}there"));
                Assert.AreEqual("The quick brown fox jumps over the lazy dog.\r\nHello\r\nthere",
                                _fixture.ValueOfControl(@"controltype:edit"));

                var desiredSize = new Coordinate(400, 140);
#pragma warning disable 618
                Assert.IsTrue(_fixture.ResizeWindow(desiredSize), "Resize succeeds");
#pragma warning restore 618
                Assert.AreEqual(desiredSize, _fixture.WindowSize);
                Assert.IsTrue(_fixture.MaximizeWindow());
                Assert.AreNotEqual(desiredSize, _fixture.WindowSize);
                Assert.IsTrue(_fixture.MinimizeWindow());
                Assert.IsTrue(_fixture.NormalWindow());
                Assert.AreEqual(desiredSize, _fixture.WindowSize);
                var desiredLocation = new Coordinate(200, 250);
#pragma warning disable 618
                Assert.IsTrue(_fixture.MoveWindow(desiredLocation), "Move succeeds");
#pragma warning restore 618
                Assert.AreEqual(desiredLocation, _fixture.WindowTopLeft);
                var snapshot  = _fixture.WindowSnapshot(8);
                var expected1 = File.ReadAllText("NotepadScreenshotNoCursor.txt");
                var expected2 = File.ReadAllText("NotepadScreenshotWithCursor.txt");
                var expected3 = File.ReadAllText("NotepadScreenshotWithCursorAndScrollbar.txt");
                var expected4 = File.ReadAllText("NotepadScreenshotNoCursorWithScrollbar.txt");

                Console.WriteLine(snapshot);
                Assert.IsTrue(snapshot.Equals(expected1, StringComparison.Ordinal) || snapshot.Equals(expected2, StringComparison.Ordinal) ||
                              snapshot.Equals(expected3, StringComparison.Ordinal) || snapshot.Equals(expected4, StringComparison.Ordinal),
                              "Snapshot matches");
                UiAutomationFixture.WaitSeconds(1);
                Assert.IsTrue(_fixture.ClickControl("Close"));
                Assert.IsTrue(_fixture.WaitForControl("Save"), "Wait for Save");
                Assert.IsTrue(_fixture.ClickControl("Don't Save"), "Push Don't Save");
                Thread.Sleep(500);
            }
            finally
            {
                Assert.IsTrue(_fixture.ForcedCloseApplication(), "Stopping Notepad a second time should succeed (already stopped)");
            }
        }
Beispiel #3
0
        public static void PrepareTestSuite(TestContext testContext)
        {
            UiAutomationFixture.TimeoutSeconds = 10;
            _fixture = new UiAutomationFixture();
            _fixture.SetAutomaticSwitchToStartedApplication();
            Assert.IsTrue(_fixture.StartApplicationWithWorkingFolder(WpfDemoAppPath, TempFolder), "WpfDemoApp started with working folder");
            _fixture.WaitForControl("id:workingFolder");
            var actualWorkFolder = _fixture.ValueOfControl("id:WorkingFolder");

            Assert.AreEqual(TempFolder, actualWorkFolder, "Working folder is OK");
            Assert.IsTrue(_fixture.CloseApplication(), "WPF Demo App stopped");
            Assert.IsTrue(_fixture.StartApplicationWithWorkingFolder(WpfDemoAppPath, ""), "WpfDemoApp started with empty working folder");
            Assert.AreNotEqual(TempFolder, _fixture.ValueOfControl("id:WorkingFolder"), "Working folder is OK 2");
        }
        public void ScreenCaptureTakeTest()
        {
            var image = Snapshot.CaptureScreen(new Rectangle(0, 0, 2, 1));

            Assert.IsTrue(image.ToString().StartsWith("Image", StringComparison.Ordinal));
            Assert.IsTrue(image.ToString().EndsWith("(2 x 1)", StringComparison.Ordinal));
            Assert.AreEqual("image/jpeg", image.MimeType);

            _fixture.SetValueOfControlTo(@"controltype:edit",
                                         "The quick brown fox jumps over the lazy dog.\r\nShe sells sea shells on the sea shore");
            _fixture.ClickControl("Name:Help");
            _fixture.WaitForControl("Name:About Notepad");
            var screenshot = _fixture.SnapshotObjectOfControl("Name:Help");

            Assert.IsTrue(screenshot.ToString().StartsWith("Image", StringComparison.Ordinal), "Starts With Image");
            Assert.IsTrue(Regex.IsMatch(screenshot.ToString(), @".+\(\d+ x \d+\)$"), "Ends With (n x m)");
            var screenshotRendering = _fixture.SnapshotOfControl("Name:Help");

            Assert.IsTrue(screenshotRendering.StartsWith("<img src='data:image/jpeg;base64,", StringComparison.Ordinal));
        }
 public void Init()
 {
     _fixture = new UiAutomationFixture();
     Assert.IsTrue(_fixture.StartApplication("notepad.exe"), "notepad started");
     _fixture.WaitForControl(@"controltype:edit");
 }