[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void ThreeCriteria_ThreeElements_NoMatch_NameAutomaitonIdClassName() { // Arrange var hashtable = new Hashtable(); hashtable.Add("NAME", "*aaa*"); hashtable.Add("AUTOMATIONID", "*id*"); hashtable.Add("CLASS", "cl*ss"); // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { hashtable }, AutomationFactory.GetUiEltCollection( new[] { FakeFactory.GetAutomationElementExpected(ControlType.Button, "aa1aa", "auId", "clas", string.Empty), FakeFactory.GetAutomationElementExpected(ControlType.Button, "aa2aa3aa", "Id", "cl____s", string.Empty), FakeFactory.GetAutomationElementExpected(ControlType.Button, "a4a5abbb", "iDrweqrqw", @"/ss", string.Empty) }) ); // Assert MbUnit.Framework.Assert.AreEqual(false, result); Assert.Equal(false, result); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void NoneCriteria_NoneElements() { // Arrange // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { null }, AutomationFactory.GetUiEltCollection(new IUiElement[] { null }) ); // Assert MbUnit.Framework.Assert.AreEqual(false, result); Assert.Equal(false, result); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void NoneCriteria_OneElement() { // Arrange var element = FakeFactory.GetAutomationElementExpected(ControlType.Button, "aaaa", string.Empty, string.Empty, string.Empty); // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { null }, AutomationFactory.GetUiEltCollection(new[] { element }) ); // Assert MbUnit.Framework.Assert.AreEqual(false, result); Assert.Equal(false, result); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void OneCriterion_NoneElements() { // Arrange var hashtable = new Hashtable(); hashtable.Add("NAME", "*aaa*"); // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { hashtable }, AutomationFactory.GetUiEltCollection(new IUiElement[] { null }) ); // Assert MbUnit.Framework.Assert.AreEqual(false, result); Assert.Equal(false, result); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void OneCriterion_OneElement_NoMatch_ClassName() { // Arrange var hashtable = new Hashtable(); hashtable.Add("class", "*aaa*"); var element = FakeFactory.GetAutomationElementExpected(ControlType.Button, string.Empty, string.Empty, "bbbb", string.Empty); // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { hashtable }, AutomationFactory.GetUiEltCollection(new[] { element }) ); // Assert MbUnit.Framework.Assert.AreEqual(false, result); Assert.Equal(false, result); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void ThreeCriteria_OneElement_Match_NameAutomationIdClassName() { // Arrange var hashtable = new Hashtable(); hashtable.Add("NAME", "*aaa*"); hashtable.Add("AUTOMATIONID", "*id*"); hashtable.Add("CLASS", "cl*ss"); var element = FakeFactory.GetAutomationElementExpected(ControlType.Button, "aaaa", "auId", "class", string.Empty); // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { hashtable }, AutomationFactory.GetUiEltCollection(new[] { element }) ); // Assert MbUnit.Framework.Assert.AreEqual(true, result); Assert.Equal(true, result); }
[NUnit.Framework.Test] // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] public void OneCriterion_ThreeElements_NoMatch_Name() { // Arrange var hashtable = new Hashtable(); hashtable.Add("NAME", "*aaa*"); // Act bool result = RealCodeCaller.GetResult_IsStepActive( new Hashtable[] { hashtable }, AutomationFactory.GetUiEltCollection(new[] { FakeFactory.GetAutomationElementExpected(ControlType.Button, "bbbb", string.Empty, string.Empty, string.Empty), FakeFactory.GetAutomationElementExpected(ControlType.Edit, "bbbb", string.Empty, string.Empty, string.Empty), FakeFactory.GetAutomationElementExpected(ControlType.TreeItem, "bbbb", string.Empty, string.Empty, string.Empty) }) ); // Assert MbUnit.Framework.Assert.AreEqual(false, result); Assert.Equal(false, result); }
/// <summary> /// Processes the pipeline. /// </summary> protected override void ProcessRecord() { if (!CheckAndPrepareInput(this)) { return; } // 20120823 // 20131109 //foreach (AutomationElement inputObject in this.InputObject) { foreach (IUiElement inputObject in InputObject) { string strData = String.Empty; // 20131109 //System.Windows.Automation.AutomationElement _control = IUiElement currentControl = // 20120823 //this.InputObject; inputObject; // 20131208 // TablePattern tblPattern = null; ITablePattern tblPattern = null; try { tblPattern = // 20120823 //this.InputObject.GetCurrentPattern(classic.TablePattern.Pattern) // 20131208 // inputObject.GetCurrentPattern(classic.TablePattern.Pattern) // inputObject.GetCurrentPattern<ITablePattern, TablePattern>(classic.TablePattern.Pattern) // as TablePattern; inputObject.GetCurrentPattern <ITablePattern>(classic.TablePattern.Pattern); bool res1 = UiaHelper.GetHeaderItems(ref currentControl, out strData, Delimiter); if (res1) { WriteObject(strData); } else { WriteVerbose(this, strData); } // temporary!!! // Selection // 20131109 //System.Windows.Automation.AutomationElement[] selectedItems = null; IUiElement[] selectedItems = null; if (SelectedOnly) { // if there's a selection, get items in the selection try { // 20131208 // SelectionPattern selPattern = inputObject.GetCurrentPattern( // SelectionPattern selPattern = inputObject.GetCurrentPattern<ISelectionPattern, SelectionPattern>( // SelectionPattern.Pattern) // as SelectionPattern; // SelectionPattern selPattern = inputObject.GetCurrentPattern<ISelectionPattern>(classic.SelectionPattern.Pattern); ISelectionPattern selPattern = inputObject.GetCurrentPattern <ISelectionPattern>(classic.SelectionPattern.Pattern); /* * System.Windows.Automation.SelectionPattern selPattern; * selPattern = * // 20120823 * //this.InputObject.GetCurrentPattern( * inputObject.GetCurrentPattern( * System.Windows.Automation.SelectionPattern.Pattern) * as System.Windows.Automation.SelectionPattern; */ selectedItems = // 20131109 //selPattern.Current.GetSelection(); // 20131119 //new UiEltCollection(selPattern.Current.GetSelection()).Cast<UiElement>().ToArray(); AutomationFactory.GetUiEltCollection(selPattern.Current.GetSelection()).Cast <UiElement>().ToArray(); } catch (Exception eSelection) { WriteDebug(this, eSelection.Message); WriteVerbose(this, "there wasn't a selection"); } } // temporary!!! // get rows if (tblPattern != null && tblPattern.Current.RowCount <= 0) { continue; } /* * if (tblPattern.Current.RowCount <= 0) continue; */ // 20130318 //RunOnSuccessScriptBlocks(this); RunOnSuccessScriptBlocks(this, null); for (int rowsCounter = 0; rowsCounter < tblPattern.Current.RowCount; rowsCounter++) { if (SelectedOnly && selectedItems.Length > 0) { } else { // without a selection string outString = // 20131208 // UiaHelper.GetOutputStringUsingTableGridPattern<TablePattern>( UiaHelper.GetOutputStringUsingTableGridPattern <ITablePattern>( tblPattern, tblPattern.Current.ColumnCount, rowsCounter, Delimiter); // getOutputString(ref tblPattern, // rowsCounter); // output a row WriteObject(outString); } } //} /* * if (tblPattern.Current.RowCount > 0) { * // 20130318 * //RunOnSuccessScriptBlocks(this); * RunOnSuccessScriptBlocks(this, null); * for (int rowsCounter = 0; * rowsCounter<tblPattern.Current.RowCount; * rowsCounter++) { * if (this.SelectedOnly && selectedItems.Length > 0) { * } else { * // without a selection * string outString = * UiaHelper.GetOutputStringUsingTableGridPattern<System.Windows.Automation.TablePattern>( * tblPattern, * tblPattern.Current.ColumnCount, * rowsCounter, * this.Delimiter); * // getOutputString(ref tblPattern, * // rowsCounter); * // output a row * this.WriteObject(outString); * } * } * //} * } */ } catch { if (tblPattern != null) { continue; } WriteVerbose(this, "couldn't get TablePattern"); WriteVerbose(this, "trying to enumerate columns and rows"); bool res2 = UiaHelper.GetHeaders(ref currentControl, out strData, Delimiter); if (res2) { WriteObject(strData); } else { WriteVerbose(this, strData); } List <string> rows = // 20120823 //UiaHelper.GetOutputStringUsingItemsValuePattern(this.InputObject, UiaHelper.GetOutputStringUsingItemsValuePattern(inputObject, Delimiter); if (rows.Count <= 0) { continue; } // 20130318 //RunOnSuccessScriptBlocks(this); RunOnSuccessScriptBlocks(this, null); foreach (string row in rows) { WriteObject(row); } // 20131119 // disposal rows = null; /* * if (rows.Count > 0) { * // 20130318 * //RunOnSuccessScriptBlocks(this); * RunOnSuccessScriptBlocks(this, null); * foreach (string row in rows) { * this.WriteObject(row); * } * } */ // WriteObject(this, false); // return; /* * if (tblPattern == null) * { * this.WriteVerbose(this, "couldn't get TablePattern"); * this.WriteVerbose(this, "trying to enumerate columns and rows"); * * * bool res2 = * UiaHelper.GetHeaders(ref _control, out strData, this.Delimiter); * if (res2) { * this.WriteObject(strData); * } else { * this.WriteVerbose(this, strData); * } * * System.Collections.Generic.List<string> rows = * // 20120823 * //UiaHelper.GetOutputStringUsingItemsValuePattern(this.InputObject, * UiaHelper.GetOutputStringUsingItemsValuePattern(inputObject, * this.Delimiter); * if (rows.Count > 0) { * // 20130318 * //RunOnSuccessScriptBlocks(this); * RunOnSuccessScriptBlocks(this, null); * foreach (string row in rows) { * this.WriteObject(row); * } * } * // WriteObject(this, false); * // return; * } */ } } // 20120823 }
public static IUiElement GetElement_ForFindAll(IEnumerable <IUiElement> elements, Condition conditions) { var elementBeforeProxy = GetAutomationElement(ControlType.Pane, string.Empty, string.Empty, string.Empty, new IBasePattern[] {}, false); var element = AutomationFactory.GetUiElement( elementBeforeProxy as IUiElement); Condition[] condCollection = null; if (null != conditions as AndCondition) { condCollection = (conditions as AndCondition).GetConditions(); } if (null != conditions as OrCondition) { condCollection = (conditions as OrCondition).GetConditions(); } IUiEltCollection descendants = AutomationFactory.GetUiEltCollection(); descendants.SourceCollection.AddRange( AutomationFactory.GetUiEltCollection(elements) .ToArray().Where(elt => "expected" == elt.GetTag())); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Button)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Button)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Calendar)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Calendar)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.CheckBox)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.CheckBox)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.ComboBox)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.ComboBox)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Custom)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Custom)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.DataItem)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.DataItem)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Document)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Document)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Image)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Image)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.TreeItem)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.TreeItem)); // element.FindAll(TreeScope.Descendants, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Window)).Returns<IEnumerable<IUiElement>>(descendants.ToArray().Select(elt => elt.Current.ControlType == ControlType.Window)); element.FindAll(TreeScope.Descendants, Arg.Any <Condition>()).Returns(descendants); IUiEltCollection children = AutomationFactory.GetUiEltCollection(); children.SourceCollection.AddRange( AutomationFactory.GetUiEltCollection(elements) .ToArray().Where(elt => "expected" == elt.GetTag())); // element.FindAll( // TreeScope.Children, // new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)).Returns<IEnumerable>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Button)); // element.FindAll( // TreeScope.Children, // new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)).Returns<IEnumerable>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Document)); // element.FindAll( // TreeScope.Children, // new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Image)).Returns<IEnumerable>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Image)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Button)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Button)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Calendar)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Calendar)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.CheckBox)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.CheckBox)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.ComboBox)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.ComboBox)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Custom)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Custom)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.DataItem)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.DataItem)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Document)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Document)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Image)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Image)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.TreeItem)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.TreeItem)); // element.FindAll(TreeScope.Children, Arg.Is<PropertyCondition>(x => (x as PropertyCondition).Value == ControlType.Window)).Returns<IEnumerable<IUiElement>>(children.ToArray().Select(elt => elt.Current.ControlType == ControlType.Window)); element.FindAll(TreeScope.Children, Arg.Any <Condition>()).Returns(children); return(element); }