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 Grid2. Ctrl-Home to guarantee top row is top3. Page Down so that top row is still top, but cursor is at bottom visible row4. Read top row5. Send down cursor keystroke. 6. Go to 4 until we are at bottom7. 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
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
Cheers, will give this ago first thing Monday.
I'll let you know how I get on.
Thanks Chris
I already found that when i do GetChildren[0] on ultraCell it returns the control that is clickable, so i will continue that way.
For the rows i will then do Click on a point... I will let you know if there is any other way.
Best
Almir Tucakovic
Hi Chris
Is it possible to get NativeElement row value if i have UITestControl that represents one row in the grid.
Hi Chris (me again :))
I managed to find the way for previous problem, now there is another one.
Is it possible to find the actions UltraGrid row. The one that is used to add new row to the grid when i double click on it?
Hey Almir,
I'm not aware of any grid functionality that adds a new row on a double-click. Is this some functionality that you've built into your application? Can you post a screenshot so I can determine what UI item you are referring to?
Thanks,
Hm.. maybe that is our implementation, currently i don't have access to the code i will check it latter.
However i managed to find how to doubleclick on that row, it was pretty simple, last row in the list is actually that row so...
Thanks Almir
Hello Almir,
I'm not exactly sure what is going on here.
Most of the properties available off of the UltraUia TestControls are inherited from the base Wpf TestControls. In cases where they utilizes UIA behind the scenes, it should work. However, in some instances, the Coded UI Test Framework utilizes code-specific to the WPF control which will not work for our Windows Forms control. In some instances we can override the behavior; in others we have to work around it. The primary focus of our Coded UI Test support implementation was to make sure record-playback was successful utilizing the CodedUITestBuilder.
Possible workarounds:
If you want to discuss this UltraUiaComboBox further, please create new thread in this forum. I'd prefer not to piggyback this older Grid-CodedUI thread for a ComboEditor related issue.
Chriss
I know that this is not place to talk about UltraUiaComboBox, but, could you help me or transfer me to appropriate thread.
I am having issues with UltraUiaComboBox. Simply i want to select item from dropdown and i do this:
Combobox.SelectedItem = "Item"... After this I see that it clicks on dropdown icon and it is moving from top to bottom of dropdown list and at the end if fails.
What is going on ?