/// <summary> /// create subtree for currentRootNode according to the testType and testFilter /// </summary> private void CreatePrioritySubtreesForTestType(TreeNode node, AutomationTestsFilter testFilter, TestTypes testType) { //go thru all test priorities and create subtree for each foreach (TestPriorities priority in Enum.GetValues(typeof(TestPriorities))) { if (priority != TestPriorities.None && (this._priorities & priority) == priority) { CreateTestPrioritySubtree(priority, testType, node, testFilter); } } }
/// <summary> /// create subtree for parentNode according to the testPriority, testType and testFilter /// </summary> private void CreateTestPrioritySubtree(TestPriorities testPriority, TestTypes testType, TreeNode parentNode, AutomationTestsFilter testFilter) { //create node for the priority TreeNode priorityNode = new TreeNode(GetPriorityName(testPriority)); parentNode.Nodes.Add(priorityNode); TreeNode currentRootNode = priorityNode; //create filter for the priority AndFilter priorityFilter = new AndFilter(new TestFilterPriority(testPriority), testFilter); //for all filtered available automation tests lets create tree node foreach (AutomationTest test in AutomationTestCollection.Filter(priorityFilter)) { //lets make copy ot the test with only TestType and TestPriority belonging to this //branch AutomationTest testClone = new AutomationTest(test, testPriority, testType); TreeNode testNode = new TreeNode(testClone.Name); testNode.Tag = testClone; currentRootNode.Nodes.Add(testNode); } //if no child currentTestTypeRootNode was added then remove priority currentTestTypeRootNode if (currentRootNode.Nodes.Count == 0) { currentRootNode.Remove(); } }
/// <summary> /// this method creates automation tests subtree for particular test type /// </summary> /// <param name="testType"></param> /// <param name="testFilter">filter to be applied on all available automation tests collection</param> private void CreateTestTypeNodeSubtree(TestTypes testType, AutomationTestsFilter testFilter) { //create root currentTestTypeRootNode for the currentTestTypeRootNode type TreeNode currentTestTypeRootNode = new TreeNode(GetTestTypeName(testType)); _testsTreeView.Nodes[0].Nodes.Add(currentTestTypeRootNode); if (testType == TestTypes.ControlTest) { //if ControlTest test type is required then let's get automation ControlType //for the selected automation element. If we are showing all tests, not only for selected //elements then let's get all automation element ControlTypes. //for all grabbed ControlTypes let's create subtree with tests ControlType[] controlTypes; if (this._scope == TestsScope.SelectedElementTests) { try { //get control type if selected automation element controlTypes = new ControlType[] { this._selectedElement.Current.ControlType }; } catch (ElementNotAvailableException) { //if there are problems with the elements then ignore it controlTypes = new ControlType[] { }; } } else { // let's get all automation technology ControlTypes controlTypes = AutomationHelper.GetAllAutomationControlTypes(); } //fore each control type, let's create subtree foreach (ControlType controlType in controlTypes) { //create automation tests filter for the controlType FilterControlTypeTests controlTypeFilter = new FilterControlTypeTests(controlType); //create tree currentTestTypeRootNode for the control type TreeNode controlTypeNode = new TreeNode(controlTypeFilter.ControlTypeName); currentTestTypeRootNode.Nodes.Add(controlTypeNode); //create priority subtree for the controlType CreatePrioritySubtreesForTestType(controlTypeNode, new AndFilter(testFilter, controlTypeFilter), testType); //if the currentRootNode has no children nodes then remove it if (controlTypeNode.Nodes.Count == 0) { controlTypeNode.Remove(); } } } else { if (testType == TestTypes.PatternTest) { //if PatternTest test type is required then let's get all supported patterns //for the selected automation element. If we are showing all tests, not only for selected //elements then let's get all automation element Patterns. //for all grabbed Patterns let's create subtree with tests IEnumerable <AutomationPattern> supportedPatterns; if (this._scope == TestsScope.SelectedElementTests) { try { //get all supported patterns supportedPatterns = this._selectedElement.GetSupportedPatterns(); } catch (ElementNotAvailableException) { //is there is problem with the element then ignore his patterns supportedPatterns = new AutomationPattern[0]; } } else { //let's get all automation technology patterns supportedPatterns = AutomationHelper.GetAllAutomationPatterns(); } //for each pattern let's create subtree foreach (AutomationPattern pattern in supportedPatterns) { //create filter filtering automation tests testing this pattern FilterPatternTests patternFilter = new FilterPatternTests(pattern); //create tree currentRootNode for the pattern TreeNode patternNode = new TreeNode(patternFilter.PatternName); currentTestTypeRootNode.Nodes.Add(patternNode); //create priority subtree for the pattern CreatePrioritySubtreesForTestType(patternNode, new AndFilter(testFilter, patternFilter), testType); //if the currentRootNode has no children nodes then remove it if (patternNode.Nodes.Count == 0) { patternNode.Remove(); } } } else { //if other TestType than ControlTests or PatternTests is required then //create subtree for it CreatePrioritySubtreesForTestType(currentTestTypeRootNode, testFilter, testType); } } //if there are no children then remove the currentTestTypeRootNode if (currentTestTypeRootNode.Nodes.Count == 0) { currentTestTypeRootNode.Remove(); } }