private static void RunTestInternal(IEnumerable<AutomationTest> automationTests, AutomationElement element, IWin32Window parentWindow, AutomationTestManager manager) { //create window RunningTestsWindow testWindow = new RunningTestsWindow(); if (manager._testChildren) { //// Determine if this is a control/pattern/Automation test //// Construct the PropertyCondition Condition condition = null; //// Add all the tests foreach (AutomationTest test in automationTests) { // The tests are within a class the defines what pattern type this in is StringBuilder buffer = new StringBuilder(((MainWindow)parentWindow)._automationTests._testsTreeView.SelectedNode.FullPath); switch (test.Type) { case TestTypes.AutomationElementTest: // Tests\Automation Element Tests\Priority 2 Tests\AutomationElement.PropertyChange.Enabled.1 condition = Condition.TrueCondition; break; case TestTypes.ControlTest: { // Tests\Control Tests\Slider\Priority 1 Tests\BulkAdd.1 buffer.Replace(@"Tests\Control Tests\", ""); int indexOf = buffer.ToString().IndexOf(@"\"); buffer.Remove(indexOf, buffer.Length - indexOf); condition = new PropertyCondition(AutomationElement.ControlTypeProperty, GetControlType(buffer.ToString())); } break; case TestTypes.PatternTest: { // Tests\Pattern Tests\Grid\Priority 1 Tests\GridPattern.S.1.1/2/3 buffer.Replace(@"Tests\Pattern Tests\", ""); int indexOf = buffer.ToString().IndexOf(@"\"); buffer.Remove(indexOf, buffer.Length - indexOf); condition = new PropertyCondition(GetProperty("Is" + buffer.ToString() + "PatternAvailableProperty"), true); } break; default: throw new ArgumentException("Cannot run " + test.Type + " tests"); } //// Find all elements AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, condition); foreach (AutomationElement temp in collection) testWindow.AddTest(test, temp); } } else { //add all tests foreach (AutomationTest test in automationTests) testWindow.AddTest(test, element); } //let them run testWindow.ShowAndRunTests(manager, parentWindow); }
/// <summary> /// this Method will run automationTests for automationElement /// </summary> public static void RunTest(IEnumerable<AutomationTest> automationTests, AutomationElement automationElement, bool TestEvents, IWin32Window parentWindow) { using (AutomationTestManager manager = new AutomationTestManager(TestEvents, false)) { RunTestInternal(automationTests, automationElement, parentWindow, manager); } }
/// <summary> /// this Method will run automationTests for automationElement /// </summary> public static void RunTest(IEnumerable <AutomationTest> automationTests, AutomationElement automationElement, bool TestEvents, IWin32Window parentWindow) { using (AutomationTestManager manager = new AutomationTestManager(TestEvents, false)) { RunTestInternal(automationTests, automationElement, parentWindow, manager); } }
/// <summary> /// This method will show window and run all tests previously added by Add Test method. /// </summary> internal void ShowAndRunTests(AutomationTestManager manager, IWin32Window parentWindow) { this._testManager = manager; RunTests(); this.ShowDialog(parentWindow); }
/// <summary> /// this method will run all automationTests on automationElement and all its children. /// </summary> public static void RunTestOnAllChildren(IEnumerable<AutomationTest> automationTests, AutomationElement automationElement, bool TestEvents, IWin32Window parentWindow) { using (AutomationTestManager manager = new AutomationTestManager(TestEvents, true)) { //((MainWindow)parentWindow). RunTestInternal(automationTests, automationElement, parentWindow, manager); } }
/// <summary> /// this method will run all automationTests on automationElement and all its children. /// </summary> public static void RunTestOnAllChildren(IEnumerable <AutomationTest> automationTests, AutomationElement automationElement, bool TestEvents, IWin32Window parentWindow) { using (AutomationTestManager manager = new AutomationTestManager(TestEvents, true)) { //((MainWindow)parentWindow). RunTestInternal(automationTests, automationElement, parentWindow, manager); } }
private static void RunTestInternal(IEnumerable <AutomationTest> automationTests, AutomationElement element, IWin32Window parentWindow, AutomationTestManager manager) { //create window RunningTestsWindow testWindow = new RunningTestsWindow(); if (manager._testChildren) { //// Determine if this is a control/pattern/Automation test //// Construct the PropertyCondition Condition condition = null; //// Add all the tests foreach (AutomationTest test in automationTests) { // The tests are within a class the defines what pattern type this in is StringBuilder buffer = new StringBuilder(((MainWindow)parentWindow)._automationTests._testsTreeView.SelectedNode.FullPath); switch (test.Type) { case TestTypes.AutomationElementTest: // Tests\Automation Element Tests\Priority 2 Tests\AutomationElement.PropertyChange.Enabled.1 condition = Condition.TrueCondition; break; case TestTypes.ControlTest: { // Tests\Control Tests\Slider\Priority 1 Tests\BulkAdd.1 buffer.Replace(@"Tests\Control Tests\", ""); int indexOf = buffer.ToString().IndexOf(@"\"); buffer.Remove(indexOf, buffer.Length - indexOf); condition = new PropertyCondition(AutomationElement.ControlTypeProperty, GetControlType(buffer.ToString())); } break; case TestTypes.PatternTest: { // Tests\Pattern Tests\Grid\Priority 1 Tests\GridPattern.S.1.1/2/3 buffer.Replace(@"Tests\Pattern Tests\", ""); int indexOf = buffer.ToString().IndexOf(@"\"); buffer.Remove(indexOf, buffer.Length - indexOf); condition = new PropertyCondition(GetProperty("Is" + buffer.ToString() + "PatternAvailableProperty"), true); } break; default: throw new ArgumentException("Cannot run " + test.Type + " tests"); } //// Find all elements AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, condition); foreach (AutomationElement temp in collection) { testWindow.AddTest(test, temp); } } } else { //add all tests foreach (AutomationTest test in automationTests) { testWindow.AddTest(test, element); } } //let them run testWindow.ShowAndRunTests(manager, parentWindow); }