private void GridPatternTestInternal(GridPattern pattern) { Assert.AreEqual(3, pattern.Current.ColumnCount, "ColumnCount"); //Besides the 2 data rows, there is an additional new data row. Assert.AreEqual(3, pattern.Current.RowCount, "RowCount"); var child = pattern.GetItem(0, 1); Assert.AreEqual("Alice", child.Current.Name, "Item [1,1].Name"); child = pattern.GetItem(1, 0); Assert.AreEqual(ControlType.CheckBox, child.Current.ControlType, "Item [0,0].ControlType"); var toggle = (TogglePattern )child.GetCurrentPattern(TogglePattern.Pattern); Assert.AreEqual(ToggleState.On, toggle.Current.ToggleState, "Item [0,0].ToggleState"); }
public void GridPatternCachedTest() { CacheRequest req = new CacheRequest(); req.Add(GridItemPattern.Pattern); req.Add(GridPattern.Pattern); req.Add(GridPattern.RowCountProperty); req.Add(GridPattern.ColumnCountProperty); req.Add(GridItemPattern.RowProperty); req.Add(GridItemPattern.ColumnProperty); req.Add(GridItemPattern.ContainingGridProperty); using (req.Activate()) { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); // Try out the Grid Pattern GridPattern grid = (GridPattern)itemsView.GetCachedPattern(GridPattern.Pattern); Assert.IsTrue(grid.Cached.ColumnCount > 0); Assert.IsTrue(grid.Cached.RowCount > 0); // GridItem AutomationElement gridItemElement = grid.GetItem(0, 0); Assert.IsNotNull(gridItemElement); GridItemPattern gridItem = (GridItemPattern)gridItemElement.GetCachedPattern(GridItemPattern.Pattern); Assert.AreEqual(gridItem.Cached.Row, 0); Assert.AreEqual(gridItem.Cached.Column, 0); Assert.AreEqual(gridItem.Cached.ContainingGrid, itemsView); } }
public AutomationElement this[int row, int column] { get { return(_pattern.GetItem(row, column)); } }
public GridRow GetRowByIndex(int rowIndex) { PreCheckRow(rowIndex); var gridCell = GridPattern.GetItem(rowIndex, 0).AsGridCell(); return(gridCell.ContainingRow); }
internal AutomationElement pattern_GetItem(int row, int column, bool expectedException, CheckType checkType) { AutomationElement element = null; string call = "GetItem(" + row + ", " + column + ")"; try { element = m_pattern.GetItem(row, column); } catch (InvalidOperationException e) { if (!expectedException) { ThrowMe(checkType, call + " threw an expection unexpectedly : " + e.Message); } Comment("Successfully called " + call + " with exception thrown as expected"); return(null); } if (expectedException) { ThrowMe(checkType, call + " did not throw an expection as expected"); } Comment("Successfully called " + call + " without an exception thrown"); return(element); }
public void GridItemPatternTest() { AutomationElement item = gridPattern.GetItem(1, 2); var pattern = (GridItemPattern)item. GetCurrentPattern(GridItemPattern.Pattern); Assert.AreEqual(2, pattern.Current.Column, "Column"); Assert.AreEqual(1, pattern.Current.Row, "Row"); Assert.AreEqual(1, pattern.Current.ColumnSpan, "ColumnSpan"); Assert.AreEqual(1, pattern.Current.RowSpan, "RowSpan"); Assert.AreEqual(table1Element, pattern.Current.ContainingGrid, "ContainingGrid"); var parent = TreeWalker.RawViewWalker.GetParent(item); pattern = (GridItemPattern)parent. GetCurrentPattern(GridItemPattern.Pattern); Assert.IsNotNull(pattern, "DataItem should implement GridItem"); Assert.AreEqual(0, pattern.Current.Column, "Column"); Assert.AreEqual(1, pattern.Current.Row, "Row"); // Should this really be 3? Assert.AreEqual(1, pattern.Current.ColumnSpan, "ColumnSpan"); Assert.AreEqual(1, pattern.Current.RowSpan, "RowSpan"); Assert.AreEqual(table1Element, pattern.Current.ContainingGrid, "ContainingGrid"); }
public static AutomationElement OpenAppributeFromList(AutomationElement ae, string name) { var datagrid = ae.FindByTypeExt(ControlType.DataGrid)[0]; GridPattern gridPattern = datagrid.GetCurrentPattern(GridPattern.Pattern) as GridPattern; int rowCount = gridPattern.Current.RowCount; List <string> names = new List <string>(); foreach (int i in Enumerable.Range(0, rowCount)) { var item = gridPattern.GetItem(i, 1); if (Regex.IsMatch(item.Current.Name, name)) { AutomationElement row = datagrid.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, (i + 1).ToString())); SelectionItemPattern itemPattern = row.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; itemPattern.Select(); } } ae.FindByNameExt("Modify").PressButtonExt(); var handle = WinApi.Window.FindWindowFromCaptationRegex($".*GD&T.*{name}.*"); AutomationElement newDialog = AutomationElement.FromHandle(handle); return(newDialog); }
/// <summary> /// Get grid cell element /// </summary> /// <param name="element">AutomationElement instance</param> /// <param name="row">Grid row index</param> /// <param name="column">Grid column index</param> /// <returns>Target grid cell element</returns> public AutomationElement GetGridItem(AutomationElement element, int row, int column) { GridPattern pattern = GetGridPattern(element); if (pattern != null) { return(pattern.GetItem(row, column)); } return(null); }
public AutomationElement GetItem(int row, int column, bool log) { if (log) { procedureLogger.Action(string.Format("Get element from row {0}, col {1} from {2}.", row, column, this.NameAndType)); } GridPattern gp = (GridPattern)element.GetCurrentPattern(GridPattern.Pattern); return(gp.GetItem(row, column)); }
public static List <string> GetAppributeList(AutomationElement ae) { var datagrids = ae.FindByTypeExt(ControlType.DataGrid); GridPattern gridPattern = datagrids[0].GetCurrentPattern(GridPattern.Pattern) as GridPattern; int rowCount = gridPattern.Current.RowCount; List <string> names = new List <string>(); foreach (int i in Enumerable.Range(0, rowCount)) { var item = gridPattern.GetItem(i, 1); string name = item.Current.Name.Split(' ').First(); names.Add(name); } return(names); }
public void GridPatternTest() { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); // Try out the Grid Pattern GridPattern grid = (GridPattern)itemsView.GetCurrentPattern(GridPattern.Pattern); Assert.IsTrue(grid.Current.ColumnCount > 0); Assert.IsTrue(grid.Current.RowCount > 0); // GridItem AutomationElement gridItemElement = grid.GetItem(0, 0); Assert.IsNotNull(gridItemElement); GridItemPattern gridItem = (GridItemPattern)gridItemElement.GetCurrentPattern(GridItemPattern.Pattern); Assert.AreEqual(gridItem.Current.Row, 0); Assert.AreEqual(gridItem.Current.Column, 0); Assert.AreEqual(gridItem.Current.ContainingGrid, itemsView); }
public static void AssertPositionSummaryValuesForSymbol() { //For each row, get the column values and test it the new value GridPattern gridPattern = GetGridPattern(); string share; string lastPrice; string marketPrice; string gainLoss; string costBasis; string symbol; //Test for the number of rows displayed in the Position summary table in the UI for (int rowCountIndex = 0; rowCountIndex < gridPattern.Current.RowCount; rowCountIndex++) { // Get the Stock name symbol = gridPattern.GetItem(rowCountIndex, 0).Current.Name; // Column 0 is for Stock //input columns share = double.Parse(gridPattern.GetItem(rowCountIndex, 1).Current.Name, NumberStyles.Currency).ToString(); // Column 1 is for number of share lastPrice = double.Parse(gridPattern.GetItem(rowCountIndex, 2).Current.Name, NumberStyles.Currency).ToString(); // Column 2 is for last price costBasis = double.Parse(gridPattern.GetItem(rowCountIndex, 3).Current.Name, NumberStyles.Currency).ToString(); // Column 3 is for cost //computed columns marketPrice = double.Parse(gridPattern.GetItem(rowCountIndex, 4).Current.Name, NumberStyles.Currency).ToString(); // Column 3 is for cost //marketPrice = gridPattern.GetItem(rowCountIndex, 4).Current.Name.Replace('$', '0'); // Column 4 is for market price for symbol gainLoss = gridPattern.GetItem(rowCountIndex, 5).Current.Name; // Column 5 is for Gain Loss % for symbol gainLoss = gainLoss.Remove(gainLoss.Length - 1); double tempValue; Assert.IsTrue(Double.TryParse(share, out tempValue), String.Format(CultureInfo.CurrentCulture, "Number of shares {0} is not numeric", symbol)); Assert.IsTrue(Double.TryParse(lastPrice, out tempValue), String.Format(CultureInfo.CurrentCulture, "Lastprice for {0} is not numeric", symbol)); Assert.IsTrue(Double.TryParse(costBasis, out tempValue), String.Format(CultureInfo.CurrentCulture, "Cost basis Value for {0} is not numeric", symbol)); Assert.IsTrue(Double.TryParse(marketPrice, out tempValue), String.Format(CultureInfo.CurrentCulture, "Market price for {0} is not numeric", symbol)); Assert.IsTrue(Double.TryParse(gainLoss, out tempValue), String.Format(CultureInfo.CurrentCulture, "Gainloss % Value for {0} is not numeric", symbol)); } }
// </Snippet102> // <Snippet103> ///-------------------------------------------------------------------- /// <summary> /// Event handler for grid item focus change. /// Can be used to track traversal of individual grid items /// within a grid. /// </summary> /// <param name="src">Object that raised the event.</param> /// <param name="e">Event arguments.</param> ///-------------------------------------------------------------------- private void OnGridItemFocusChange( object src, AutomationFocusChangedEventArgs e) { // Make sure the element still exists. Elements such as tooltips // can disappear before the event is processed. AutomationElement sourceElement; try { sourceElement = src as AutomationElement; } catch (ElementNotAvailableException) { return; } // Gets a GridItemPattern from the source of the event. GridItemPattern gridItemPattern = GetGridItemPattern(sourceElement); if (gridItemPattern == null) { return; } // Gets a GridPattern from the grid container. GridPattern gridPattern = GetGridPattern(gridItemPattern.Current.ContainingGrid); if (gridPattern == null) { return; } AutomationElement gridItem = null; try { gridItem = gridPattern.GetItem( gridItemPattern.Current.Row, gridItemPattern.Current.Column); } catch (ArgumentOutOfRangeException) { // If the requested row coordinate is larger than the RowCount // or the column coordinate is larger than the ColumnCount. // -- OR -- // If either of the requested row or column coordinates // are less than zero. // TO DO: error handling. } // Further event processing can be done at this point. // For the purposes of this sample we just report item properties. StringBuilder gridItemReport = new StringBuilder(); gridItemReport.AppendLine( gridItemPattern.Current.Row.ToString()).AppendLine( gridItemPattern.Current.Column.ToString()).AppendLine( gridItemPattern.Current.RowSpan.ToString()).AppendLine( gridItemPattern.Current.ColumnSpan.ToString()).AppendLine( gridItem.Current.AutomationId.ToString()); Console.WriteLine(gridItemReport.ToString()); }
/// <summary> /// Retrieves the UI Automation provider for the specified cell /// </summary> /// <param name="control">The UI Automation element</param> /// <param name="row">The ordinal number of the row of interest</param> /// <param name="column">The ordinal number of the column of interest.</param> /// <returns> /// An object representing the item at the specified location /// </returns> internal static AutomationElement GetItem(AutomationElement control, int row, int column) { GridPattern pat = (GridPattern)CommonUIAPatternHelpers.CheckPatternSupport(GridPattern.Pattern, control); return(pat.GetItem(row, column)); }
public AutomationElement this[int row, int column] => _pattern.GetItem(row, column);