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));
 }
 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");
 }
Пример #3
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");
        }
Пример #4
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"));
        }
Пример #5
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();
        }
Пример #6
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");
 }
Пример #7
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)");
            }
        }
Пример #8
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");
        }
Пример #9
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");
        }
Пример #10
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");
        }
        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();
            }
        }
Пример #12
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");
 }
Пример #13
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'");
 }
Пример #15
0
 public void SetUp()
 {
     Debug.Print("Test #" + ++_testCounter);
     UiAutomationFixture.SearchBy("Name");
 }
Пример #16
0
 public void FixtureTestInvalidSearchBy()
 {
     Assert.IsFalse(UiAutomationFixture.SearchBy(""), "Search by empty value fails");
     Assert.IsFalse(UiAutomationFixture.SearchBy("InvalidConditionType"), "Search by wrong value fails");
 }