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.
I couldn't wait.
That's amazing. It also goes way over my head right now.
Your example code worked perfectly. I'll need to sit down and figure out these Automation UI patterns.Are there any recommended resources for finding out more?
Thanks for your help.
Is it possible to select, click etc. on desired (cell or row) while looping through them.
Let's say I want to find some row which have cell with desired value and Double Click on it (row or cell) to open next form...
Best
Almir
Hey Almir.
To perform a click at this point, you have two options.
Using UIA only : Get a clickable point from the AutomationElement() and call Mouse.Click() on that point.
http://stackoverflow.com/questions/10105396/given-an-automation-element-how-do-i-simulate-a-single-left-click-on-it
Using the CodedUI framework: Create a UITestControl for cell's editor, and call Mouse.Click() on the UITestControl. Note that in order to create a TestControl, you'd work your way down the hierarchy finding all the appropriate intermediate objects.
if (valuePattern.Current.Value == "KK") { UITestControl rowTestControl = new UITestControl(uIColScrollRegion0RowSTree); rowTestControl.SearchProperties.Add(UltraUiaControl.PropertyNames.AutomationId, rowAutomationElement.Current.AutomationId); rowTestControl.Find();
UITestControl cellTestControl = new UITestControl(rowTestControl); cellTestControl.SearchProperties.Add(UltraUiaControl.PropertyNames.AutomationId, cellAutomationElement.Current.AutomationId); cellTestControl.Find();
UITestControl dataAreaControl = new UITestControl(cellTestControl); dataAreaControl.SearchProperties.Add(new PropertyBLOCKED EXPRESSION;
break; }
Let me know how this turns out.
Just saw that part of my previous post was blocked. It should be:
dataAreaControl.SearchProperties.Add( new PropertyExpression ( UltraUiaControl.PropertyNames.AutomationId, "[Editor]", PropertyExpressionOperator.Contains ) ); dataAreaControl.Find();
Mouse.DoubleClick(dataAreaControl);
break;
Hi
Could you help me with something Chris.
First it finds the control (Row or cell) really fast and when i do DrawHighLight() it finds and rounds the control in milliseconds which is great, however.
In this case (and i other cases like text box, combo box) i am having issue with Mouse.Click , adding text actions.
After I find the control i try to do mouse click or enter text and it focuses ultra control but it is not clicking or entering text (if it is textbox...).
after some time it shows exception like some other control is blocking.. or something else.
Same case is here with Row or cell when i try to click on it.
For textboxes
It is not problem to get the data from it but to enter the data is something else ...
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.
Thanks,
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 ?
Hi Chris
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
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?
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?