Exemplo n.º 1
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)");
            }
        }
Exemplo n.º 2
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");
        }