Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
200
Coded UI testing wingrid. Iterate rows past visible scroll region
posted

Hi,

I am trying to write a Coded UI project to get all the values in a column of an UltraGrid.

I have an UltraWinGrid with more rows than can be displayed on screen, so there are rows that have to be scrolled to be visible.

I have a Coded UI project that can iterate through all currently visible rows and get cell values.

I could send keystrokes to key down the grid, eg

1. Select Grid
2. Ctrl-Home to guarantee top row is top
3. Page Down so that top row is still top, but cursor is at bottom visible row
4. Read top row
5. Send down cursor keystroke. 
6. Go to 4 until we are at bottom
7. Iterate through remaining visible rows.

My question is how do I know that I am at the bottom of the grid (step 6)

I am using 2012 volume 2. .Net 4.0 application.
The test project is in Visual Studio 2012 .Net 4.5. 

Thanks

David 

  • 6158
    Offline posted in reply to David

    Great! I'm glad it helped. MSDN has a good high level overview of UI Automation, as well as, details about the different automation patterns.

    You can use Inspect to view the UIA hierarchy of a control, and see which automation patterns are implemented on each automation element.

    Let me know if you have any further questions.

    Chris

  • 6158
    Verified Answer
    Offline posted

    Hello David.

    It is much easier to iterate through all the rows by using the UIA patterns. The underlying UIA AutomationElement can be retrieved using the NativeElement property of the UITestControl.

    The following sample code will use UIA patterns to iterate through all the rows, and extract the cell value for the first column into a list.

    //==============================
    // This sample code will extract all the values for the first column and put them into a list.
    int rowIndex = 0;
    List<string> cellValues = new List<string>();
    System.Windows.Automation.AutomationElement containerAutomationElement = uIColScrollRegion0RowSTree.NativeElement as System.Windows.Automation.AutomationElement;
    System.Windows.Automation.AutomationElement rowAutomationElement = null;
    System.Windows.Automation.ItemContainerPattern containerPattern = containerAutomationElement.GetCurrentPattern(System.Windows.Automation.ItemContainerPattern.Pattern) as System.Windows.Automation.ItemContainerPattern;
    rowAutomationElement = containerPattern.FindItemByProperty( null, System.Windows.Automation.AutomationElement.AutomationIdProperty, rowIndex.ToString());
    while (rowAutomationElement != null)
    {
    // get the collection of cell automation elements
    System.Windows.Automation.AutomationElementCollection cellsAutomationElements = rowAutomationElement.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);

    // get the automation element for the first cell
    System.Windows.Automation.AutomationElement cellAutomationElement = cellsAutomationElements[0];

    // Scroll the cell into view. This is necessary due to an existing bug which should be addressed shortly.
    System.Windows.Automation.ScrollItemPattern scrollPattern = cellAutomationElement.GetCurrentPattern(System.Windows.Automation.ScrollItemPattern.Pattern) as System.Windows.Automation.ScrollItemPattern;
    scrollPattern.ScrollIntoView();

    // use the ValuePattern to get the Value.
    System.Windows.Automation.ValuePattern valuePattern = cellAutomationElement.GetCurrentPattern(System.Windows.Automation.ValuePattern.Pattern) as System.Windows.Automation.ValuePattern;
    cellValues.Add(valuePattern.Current.Value);

    // get the next row
    rowIndex++;
    rowAutomationElement = containerPattern.FindItemByProperty(null, System.Windows.Automation.AutomationElement.AutomationIdProperty, rowIndex.ToString());
    }

    // do something with the list of cell values.
    //==============================

    Let us know if you need further assistance.

    Chris