Exemplo 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");
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
0
        public void FixtureRunWord()
        {
            // Word doesn't always start a new process, but will re-use an existing process if that was already running.
            // That's why we don't use the automatic switch to the process, but switch by its process name separately
            var fixture = new UiAutomationFixture();

            UiAutomationFixture.SearchBy("Name");
            fixture.NoAutomaticSwitchToStartedApplication();
            UiAutomationFixture.TimeoutSeconds = 10;
            Assert.IsTrue(fixture.StartApplicationWithArguments(WordPath, "/w /q"), "Started Word");
            UiAutomationFixture.WaitSeconds(3);
            // todo: this fails when Word is already active when the test runs. Make more resilient
            Assert.IsTrue(fixture.SwitchToProcess(@"name:winword"), "Switched to Word");

            fixture.PressKey(@"The Quick Brown Fox Jumps Over the Lazy Dog+{HOME}");
            Assert.IsTrue(fixture.ClickControl("ControlType:Button && Name:Bold"), "Click Bold");
            Assert.IsTrue(fixture.ControlExists("Name:Heading 1"), "Heading 1 found");
            Assert.IsTrue(fixture.ClickControl("Heading 1"), "Click Heading 1");
            Assert.IsTrue(fixture.ClickControl("ControlType:Button && Name:Underline"), "Click Underline");
            Assert.IsFalse(fixture.CloseApplication(), "Close application doesn't work due to dialog");

            // This is a tricky one, as it is a control on a modal dialog.
            // It works because click has a fallback to simulate a mouseclick in the center of the control's bounding rectangle

            Assert.IsTrue(fixture.ClickControl("Name:Don't Save"), "click Don't Save");
            // Normally exiting Word can take a very long time. 10 seconds is typically not enough
            UiAutomationFixture.TimeoutSeconds = 30;
            Assert.IsTrue(UiAutomationFixture.WaitUntilProcessEnds(@"winword"), "WinWord process ends");
            UiAutomationFixture.TimeoutSeconds = 3;
            fixture.SetAutomaticSwitchToStartedApplication();
        }
Exemplo n.º 4
0
        public void ListOfControlsTableTest()
        {
            var fixture = new UiAutomationFixture();

            fixture.StartApplication("notepad");
            var processId      = fixture.ApplicationProcessId;
            var listOfControls = new ListOfControls(processId, "ProcessId:" + processId);
            var result         = listOfControls.DoTable();
            var headerRow      = result[0] as Collection <string>;

            Assert.IsNotNull(headerRow);
            Assert.AreEqual("report:Name", headerRow[1]);
            var controls = result.Skip(1).ToList();

            Assert.IsTrue(controls.Any());
            foreach (Collection <string> row in controls)
            {
                foreach (var cell in row)
                {
                    Console.Write(cell + "; ");
                }
                Console.WriteLine();
            }

            var emptyList   = new ListOfControls(processId, "id:q");
            var emptyResult = emptyList.Query();

            Assert.IsNull(emptyResult);
            fixture.ForcedCloseApplication();
        }
Exemplo n.º 5
0
        public void WpfDemoCheckRadioButtons()
        {
            Assert.IsTrue(UiAutomationFixture.SearchBy("Caption"));
            Assert.IsTrue(_fixture.SelectItem("Usual Controls"), "Select 'Usual Controls' tab");
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton1"));
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton2"));
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton3"));

            Assert.IsTrue(_fixture.SelectItem("RadioButton1"), "Select RadioButton1");
            Assert.AreEqual("Selected", _fixture.ValueOfControl("RadioButton1"));
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton2"));
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton3"));
            Assert.AreEqual("Checked RadioButton1", _fixture.ValueOfControl("id:TextBlock1"));

            Assert.IsTrue(_fixture.SelectItem("RadioButton2"), "Select RadioButton2");
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton1"));
            Assert.AreEqual("Selected", _fixture.ValueOfControl("RadioButton2"));
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton3"));
            Assert.AreEqual("Checked RadioButton2", _fixture.ValueOfControl("id:TextBlock1"));

            Assert.IsTrue(_fixture.SelectItem("RadioButton3"), "Select RadioButton3");
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton1"));
            Assert.AreEqual(string.Empty, _fixture.ValueOfControl("RadioButton2"));
            Assert.AreEqual("Selected", _fixture.ValueOfControl("RadioButton3"));
            Assert.AreEqual("Checked RadioButton3", _fixture.ValueOfControl("id:TextBlock1"));
        }
 public void CalcCheckSimplifiedApi()
 {
     Assert.IsTrue(_fixture.ClickControl("Clear"), "Push Clear");
     Assert.IsTrue(_fixture.ClickControl("One"), "Push 1");
     Assert.IsTrue(UiAutomationFixture.SearchBy("ID"), "Search by ID");
     Assert.AreEqual("1", _fixture.ValueOfControl("CalculatorResults"), "Result is 1");
 }
Exemplo n.º 7
0
        public void WpfDemoCheckCheckBox()
        {
            Assert.IsTrue(_fixture.SelectItem("Caption:Usual Controls"), "Select 'Usual Controls' tab");
            UiAutomationFixture.SearchBy("id");
            Assert.AreEqual("Off", _fixture.ValueOfControl("CheckBox1"), "Default value of CheckBox1");

            Assert.IsTrue(_fixture.ToggleControl("CheckBox1"), "First toggle on CheckBox1");
            Assert.AreEqual("On", _fixture.ValueOfControl("CheckBox1"), "Value of CheckBox1 after first toggle");
            Assert.AreEqual("Checked CheckBox1", _fixture.ValueOfControl("TextBlock1"));

            Assert.IsTrue(_fixture.ToggleControl("CheckBox1"), "Second toggle on CheckBox1");
            Assert.AreEqual("Off", _fixture.ValueOfControl("CheckBox1"), "Value of CheckBox1 after second toggle");
            Assert.AreEqual("Unchecked CheckBox1", _fixture.ValueOfControl("TextBlock1"));

            Assert.AreEqual("Off", _fixture.ValueOfControl("ThreeStateCheckBox"), "Default Value of ThreeStateCheckBox");

            Assert.IsTrue(_fixture.ToggleControl("ThreeStateCheckBox"), "First toggle on ThreeStateCheckBox");
            Assert.AreEqual("On", _fixture.ValueOfControl("ThreeStateCheckBox"),
                            "Value of ThreeStateCheckBox after first toggle");
            Assert.AreEqual("Checked ThreeStateCheckBox", _fixture.ValueOfControl("TextBlock1"));

            Assert.IsTrue(_fixture.ToggleControl("ThreeStateCheckBox"), "Second toggle on ThreeStateCheckBox");
            Assert.AreEqual("Indeterminate", _fixture.ValueOfControl("ThreeStateCheckBox"),
                            "Value of ThreeStateCheckBox after second toggle");

            Assert.IsTrue(_fixture.ToggleControl("ThreeStateCheckBox"), "Third toggle on ThreeStateCheckBox");
            Assert.AreEqual("Off", _fixture.ValueOfControl("ThreeStateCheckBox"),
                            "Value of ThreeStateCheckBox after third toggle");
            Assert.AreEqual("Unchecked ThreeStateCheckBox", _fixture.ValueOfControl("TextBlock1"));

            Assert.IsFalse(_fixture.ToggleControl("DisabledCheckBox"), "Toggle on DisabledCheckBox");
        }
 public void Win10SetUpTest()
 {
     Debug.Print("Test #" + ++_testCounter);
     Assert.IsTrue(UiAutomationFixture.SearchBy("name"));
     Assert.IsTrue(_fixture.PressKey(Win10AppKeys.StandardMode), "Switch to standard mode");
     Assert.IsTrue(_fixture.PressKey(Win10AppKeys.ClearAllInput));
 }
Exemplo n.º 9
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");
 }
 public static void Win10SetupCalc(TestContext testContext)
 {
     _fixture = new UiAutomationFixture();
     UiAutomationFixture.TimeoutSeconds = 5;
     Assert.IsFalse(_fixture.SwitchToProcess("name:Calculator"), "Check there is no calculator running already");
     _fixture.NoAutomaticSwitchToStartedApplication();
     _fixture.StartApplication("calc.exe");
     Assert.IsTrue(UiAutomationFixture.WaitForProcess("name:Calculator"), "Wait for process Calculator");
     Assert.IsTrue(_fixture.SwitchToProcess("name:Calculator"), "Switch to calc app");
 }
Exemplo n.º 11
0
        public void FixtureImmediatelyClosingCmdTest()
        {
            _fixture.NoAutomaticSwitchToStartedApplication();
            // the command should almost immediately stop, but still slow enough to need a wait.
            Assert.IsTrue(_fixture.StartApplicationWithArguments("test.cmd", "wait 0"), @"Immediately closing Cmd");
            var processId = _fixture.ApplicationProcessId;

            Assert.IsNotNull(processId);
            Assert.IsTrue(_fixture.ApplicationIsActive);
            Assert.IsTrue(UiAutomationFixture.WaitUntilProcessEnds("ProcessId:" + processId.Value));
        }
Exemplo n.º 12
0
        public void FixtureDelayedClosingCmdTest()
        {
            _fixture.NoAutomaticSwitchToStartedApplication();
            UiAutomationFixture.TimeoutSeconds = 2;
            // Another way of starting via cmd /c should work as well. Also letting it wait a second.
            Assert.IsTrue(_fixture.StartApplicationWithArguments(@"cmd.exe", "/c \"test.cmd wait 1\""), @"delayed closing Cmd");
            var processId = _fixture.ApplicationProcessId;

            Assert.IsNotNull(processId);
            Assert.IsTrue(_fixture.ApplicationIsActive);
            Assert.IsTrue(UiAutomationFixture.WaitUntilProcessEnds("ProcessId:" + processId.Value));
        }
Exemplo n.º 13
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.º 14
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");
        }
Exemplo n.º 15
0
        public void WpfDemoControlSearchOnBooleanCriteriaTest()
        {
            UiAutomationFixture.SearchBy("Tooltip");
            Assert.IsTrue(_fixture.SelectItem("Caption:Usual Controls"), "Select 'Usual Controls' tab");
            var control1 = _fixture.GetControl("ControlType:CheckBox && IsEnabled:false");

            Assert.IsNotNull(control1.AutomationElement, "Found a disabled checkbox");
            Assert.AreEqual("Disabled CheckBox", _fixture.NameOfControl("ControlType:CheckBox && IsEnabled:false"),
                            "Found right (only) disabled control");
            Assert.AreEqual("DisabledCheckBox", control1.AutomationElement.CurrentAutomationId, "Found right (only) disabled control");
            Assert.IsTrue(_fixture.SelectItem("Caption:More Controls"), "Select 'More Controls' tab");
            var control2 = _fixture.GetControl("IsPassword:true");

            Assert.IsNotNull(control2.AutomationElement, "Found a password control");
            Assert.AreEqual("PasswordBox1", control2.AutomationElement.CurrentAutomationId, "Found right (only) password control");
        }
Exemplo n.º 16
0
        public void WpfDemoControlSearchOnHelpTextTest()
        {
            Assert.IsTrue(_fixture.SelectItem("caption:Usual Controls"), "Select 'Usual Controls' tab");
            UiAutomationFixture.SearchBy("Tooltip");
            var control1 = _fixture.GetControl("HelpText:Checkbox with two states");

            Assert.IsNotNull(control1, "Found a control with two states");
            Assert.AreEqual("CheckBox1", control1.AutomationElement.CurrentAutomationId, "Found right two state checkbox");
            var control2 = _fixture.GetControl("HelpText:CheckBox with three states");

            Assert.IsNotNull(control2, "Found a control with three states");
            Assert.AreEqual("ThreeStateCheckBox", control2.AutomationElement.CurrentAutomationId, "Found right three state checkbox");
            var control3 = _fixture.GetControl("HelpText:");

            Assert.IsNotNull(control3.AutomationElement, "Found a control without helptext");
            Assert.IsFalse(string.IsNullOrEmpty(control3.AutomationElement.CurrentClassName), "ClassName is not null or empty");
        }
Exemplo n.º 17
0
        public void WpfDemoCheckGrid()
        {
            const string dataGrid = "DataGrid1";

            Assert.IsTrue(UiAutomationFixture.SearchBy("id"), "Default search is by ID");
            Assert.IsTrue(_fixture.SelectItem("Caption:Data Grid"), "Select 'Data Grid' tab");
            Assert.AreEqual(5, _fixture.RowCountOfControl(dataGrid), "Get Row Count");
            Assert.AreEqual(3, _fixture.ColumnCountOfControl(dataGrid), "Get Column Count");
#pragma warning disable 618
            Assert.AreEqual("1", _fixture.RowNumberOfControlContaining(dataGrid, "100"), "Get row with cell '100'");
#pragma warning restore 618
            Assert.AreEqual("row 2, column 3",
                            _fixture.CellInControlContaining(dataGrid, "Create demo UI Automation application").ToString(), "Get row with cell 'Demo UI...'");
            Assert.AreEqual("row 3, column 2", _fixture.CellInControlContaining("DataGrid1", "Approved").ToString(), "Get row with cell 'Approved'");
            Assert.IsNull(_fixture.CellInControlContaining(dataGrid, "Non-existing value"), "Search non-existent cell");
            Assert.IsNull(_fixture.CellInControlContaining("NoGrid", "Non-existing value"), "Search non-existing grid");

            var item = _fixture.CellInControlContaining(dataGrid, "101");
            Assert.AreEqual(2, item.Row, "Row OK");
            Assert.AreEqual(1, item.Column, "Column OK");
            var locator = $"{dataGrid}[{item}]";
            Assert.AreEqual("101", _fixture.ValueOfControl(locator), "Contains 101");
            Assert.AreNotEqual("101", _fixture.ValueOfControl("GridTextbox"), "Initial value of GridBox != 101");
            Assert.IsTrue(_fixture.DoubleClickControl(locator), "DoubleClick 101");
            Assert.AreEqual("101", _fixture.ValueOfControl("GridTextbox"), "GridBox contains 101");
            Assert.IsTrue(_fixture.DoubleClickControl($"{dataGrid}[row 3, col 2]"), "DoubleClick row 3 column 2");
            Assert.IsTrue(_fixture.ClickControl($"{dataGrid} [4,3]"), "Click row 4 column 3");
            Assert.AreEqual("row 4, column 3", _fixture.SelectedCellInControl(dataGrid).ToString(), "selected cell is 4,3");
            Assert.AreEqual("Approved", _fixture.ValueOfControl("GridTextbox"), "GridBTextBox contains Approved");
            Assert.IsTrue(_fixture.ClickControl($"{dataGrid}[row 2]"), "Click Row 2");
            Assert.AreEqual("row 2, column 1", _fixture.SelectedCellInControl("DataGrid1").ToString(), "Selected cell returns value of first column");
            Assert.IsTrue(_fixture.ClickControl($"{dataGrid}[col 2]"), "Click Header 2");
            Assert.AreEqual("Active", _fixture.ValueOfControl($"{dataGrid}[1,2]"), "Clicking header sorts column");

            Assert.IsTrue(_fixture.ClickControl($"{dataGrid}[column 1]"));
            Assert.AreEqual("100", _fixture.ValueOfControl($"{dataGrid}[row 1, column 1]"));

            Assert.IsTrue(_fixture.SelectItem("Caption:Usual Controls"), "Select 'Usual Controls' tab");
            Assert.AreEqual(0, _fixture.RowCountOfControl("Button1"), "Buttons don't have rows");
            Assert.AreEqual(0, _fixture.ColumnCountOfControl("MultiValueListBox"), "ListBoxes don't have rows");
            Assert.IsNull(_fixture.CellInControlContaining("TreeView1", "Core Product 1"), "TreeViews don't have cells");
        }
Exemplo n.º 18
0
        public void FixtureStartAndSwitchTestOnWord2016()
        {
            UiAutomationFixture.TimeoutSeconds = 3;
            Assert.IsFalse(_fixture.SwitchToProcess(@"name:winword"), "Word not running already");
            _fixture.NoAutomaticSwitchToStartedApplication();
            UiAutomationFixture.TimeoutSeconds = 10;
            // command line switch /w opens Word with a blank page.
            Assert.IsTrue(_fixture.StartApplicationWithArguments(WordPath, "/w /q"), @"first start of Winword succeeds (no autoswitch)");
            var processId = _fixture.ApplicationProcessId;

            Assert.IsTrue(UiAutomationFixture.WaitForProcess("ProcessId:" + processId), "Wait for Word process");
            Assert.IsTrue(_fixture.SwitchToProcess("ProcessId:" + processId), "Now Word is running");
            _fixture.SetAutomaticSwitchToStartedApplication();
            Assert.IsTrue(_fixture.StartApplicationWithArguments(WordPath, "/w /q"), @"second start of Winword succeeds too (autoswitch)");
            Assert.AreNotEqual(processId, _fixture.ApplicationProcessId, "Process IDs are not equal");
            Assert.IsTrue(_fixture.ForcedCloseApplication(), "Forced close of 2nd instance succeeds");
            Assert.IsTrue(_fixture.SwitchToProcess("ProcessId:" + processId), "Can switch to first Word instance");
            Assert.IsTrue(_fixture.ForcedCloseApplication(), "Forced close 1st instance succeeds");
            Assert.IsTrue(UiAutomationFixture.WaitUntilProcessEnds(@"name:winword"), "WinWord process ends");
        }
        public void PatternTest1()
        {
            var fixture = new UiAutomationFixture();

            try
            {
                UiAutomationFixture.TimeoutSeconds = 1;
                UiAutomationFixture.SearchBy("Name");
                Assert.IsTrue(fixture.StartApplication("notepad.exe"), "Notepad started");
                var control = fixture.GetControl("classname:edit");
                var pattern = new LegacyIAccessiblePattern(control.AutomationElement);
                Assert.AreEqual(SetResult.Success, pattern.TrySet("hello"));
                Assert.IsTrue(pattern.TryGet(out var content));
                Assert.AreEqual("hello", content);
            }
            finally
            {
                fixture.ForcedCloseApplication();
            }
        }
Exemplo n.º 20
0
 public void WpfDemoCheckExpandCollapse()
 {
     Assert.IsTrue(_fixture.SelectItem("Caption:Usual Controls"), "Select 'Usual Controls' tab");
     Assert.IsTrue(UiAutomationFixture.SearchBy("Caption"), "Default search is by Caption");
     Assert.IsTrue(_fixture.SelectItem("Tree View"), "Select 'Tree View' tab");
     Assert.IsFalse(_fixture.ControlExists("Step 2"), "Step 2 tree item does not exist yet");
     Assert.IsTrue(_fixture.ExpandControl("ID:TreeView1"), "Expanding TreeView1 succeeds");
     Assert.IsTrue(_fixture.ExpandControl("Processes"), "Expand Processes");
     Assert.IsTrue(_fixture.SetFocusToControl("Main Process 1"));
     Assert.IsTrue(_fixture.ExpandControl("Main Process 1"), "Expand Main Process 1");
     Assert.IsTrue(_fixture.SetFocusToControl("Sub Process 1"));
     Assert.IsTrue(_fixture.ExpandControl("Sub Process 1"), "Expand Sub Process 1");
     Assert.IsTrue(_fixture.SetFocusToControl("Step 2"));
     Assert.IsTrue(_fixture.ControlExists("Step 2"), "Step 2 tree item now exists");
     Assert.IsTrue(_fixture.ControlIsVisible("Step 2"), "Step 2 tree item is visible");
     Assert.IsTrue(_fixture.ExpandControl("Products"), "Expanding already expanded control is OK");
     Assert.IsTrue(_fixture.ControlIsVisible("Core Product 1"), "Core Product 1 tree item is still visible");
     Assert.IsTrue(_fixture.CollapseControl("Processes"), "Collapsing Processes tree item");
     Assert.IsTrue(_fixture.ControlExists("Step 2"), "Step 2 tree item still exists");
     Assert.IsFalse(_fixture.ControlIsVisible("Step 2"), "Ste p2 tree item is now invisible");
     Assert.IsTrue(_fixture.CollapseControl("ID:TreeView1"), "Collapsing TreeView1");
     Assert.IsFalse(_fixture.ControlIsVisible("Core Product 1"), "Core Product 1 tree item is now invisible");
 }
Exemplo n.º 21
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");
        }
 public void CalcCheckWindowValue()
 {
     UiAutomationFixture.SearchBy("ControlType");
     // also test legacy pattern get since we don't use the Window pattern yet.
     Assert.AreEqual("Calculator", _fixture.ValueOfControl("Window"), "value of Window is 'Calculator'");
 }
Exemplo n.º 23
0
 public void FixtureTestInvalidSearchBy()
 {
     Assert.IsFalse(UiAutomationFixture.SearchBy(""), "Search by empty value fails");
     Assert.IsFalse(UiAutomationFixture.SearchBy("InvalidConditionType"), "Search by wrong value fails");
 }
Exemplo n.º 24
0
 public void SetUp()
 {
     Debug.Print("Test #" + ++_testCounter);
     UiAutomationFixture.SearchBy("Name");
 }
Exemplo n.º 25
0
 public void SetUp()
 {
     UiAutomationFixture.TimeoutSeconds = 3;
     _fixture = new UiAutomationFixture();
 }
 public void Init()
 {
     _fixture = new UiAutomationFixture();
     Assert.IsTrue(_fixture.StartApplication("notepad.exe"), "notepad started");
     _fixture.WaitForControl(@"controltype:edit");
 }