Hi,
We have a WPF app using infragistics xampivotgrid. We are trying to do coded UI automation on them but we are running in to issues:
1) We are not able to identify the cells within the xampivotgrid. When going thru stackoverflow some posts mentioned that Infragistics does provide extension to identify the Xampivotgrid which can be used in coded Ui testing. Please provide us more information on this.
If you could provide us an example of accessing a cell with a value as well as accessing cell with row and column index.
Thanks.
Palak R.
Hello Palak,
I have been investigating into using Coded UI with the XamPivotGrid and the XamDataGrid, and I would like you to take a look at the sample project, as well as the following link about using Coded UI in WPF: https://msdn.microsoft.com/en-us/library/dd286726.aspx.
The XamDataGrid can play your tests back from the recording that you do directly, as the generated code will keep a reference back to the actual underlying data items in the XamDataGrid.
The XamPivotGrid on the other hand, does not reference the underlying data items due to the way that the 3-dimensional data is structured. Being that the actual cell elements are virtualized, this will require you to go through and get the underlying GridPattern like so:
AutomationElement ae = this.UIMainWindowWindow.UIPivotGridTable.NativeElement as AutomationElement; var patterns = ae.GetSupportedPatterns();GridPattern gridPattern = ae.GetCurrentPattern(patterns[1]) as GridPattern;
Doing this will allow you to get a particular AutomationElement from the row and column in your XamPivotGrid, like so:
AutomationElement element1 = gridPattern.GetItem(3, 0);AutomationElement element2 = gridPattern.GetItem(4, 0);
From these AutomationElements, you can then get the UITestControls from them by using the UITestControlFactory class and it’s FromNativeElement method, and then invoke a Mouse.Click on the controls returned, like so:
UITestControl control1 = UITestControlFactory.FromNativeElement(element1, "UIA");UITestControl control2 = UITestControlFactory.FromNativeElement(element2, "UIA");
Mouse.Click(control1, new Point(20, 10));Mouse.Click(control2, new Point(40, 10));
A very similar method can also be followed with the XamDataGrid. This method is currently commented out in the sample project, but it will work if you try against it as well.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew,
We tried running the sample code you provided for XamDataGrid and XamPivotGrid for our application and it did not work. The difference between your PivotGrid and DataGrid versus the grids we want to identify is that the CodedUI test builder identifies our grids as XamPivotGrid and XamDataGrid controls. We are not able to successfully convert our grids to Automation Elements because a “playback failed to find the control with the given search properties” error was thrown when trying to locate the XamDataGrid in order to convert it into an Automation Element.
The main difference is shown in the screenshot below. We need help in locating XamDataGrid/XamPivotGrid types versus DataGrid/PivotGrid types. Are there any other conversion of types that would identify our grids or additional suggestions that you have?
Below is our XamDataGrid control.
Below is the sample DataGrid that you sent.
From the most recent update to this forum thread, it sounds as if you are looking to identify the XamDataGrid and the XamPivotGrid directly using Coded UI, but I'm not entirely sure if this is exactly the case here. If this is the case, I do not personally believe there is a way to do this, as Infragistics support for Coded UI does everything through the AutomationElements, and to my knowledge cannot actually recognize the actual Infragistics types in testing.
There were a pair of screenshots that were supposedly attached to this forum thread as well, but I am unable to see them on my end. Would it be possible for you to please elaborate a bit further on the functionality that you are looking for on this matter and perhaps reattach the screenshots that were attached in a .zip file so that I may see them?
Please let me know if you have any other questions or concerns on this matter.
To clarify the functionality of our automation, the goal is to click check boxes in cells within the XamDataGrid and to identify the text in predetermined cells in the XamDataGrid. Similar functionalities are desired for the XamPivotGrid. I’ve also attached the images for our XamDataGrid in the UIMap (XamDataGridContro.jpg) and the image for the sample app’s DataGrid (UIDataGridCustom.jpg).
Attached is also an image of the error we receive when trying to identify the XamDataGrid via Automation Elements (XamDataGridIdentificationError.png). This code was created from a Coded UI recording and modified to use Automation Elements following the format of your code. This error continues when the grid itself (versus the RecordsTable) is casted to a Native Element (shown in XDGIdentificationError_Grid.png), demonstrating the grid identification is the most likely source of the issue. I’ve also attached an image of the XAML code of our the page under test (one of many) in our application and an image of the corresponding check box we are attempting to click (TopCheckBox.png) . The XAML code is very similar to the XAML of your XDG application, so we are unsure why our grid is not detectable.
In accordance with the most recent e-mail that you had sent me with your screenshots included, I am attaching the remainder of the screenshots to this post.
Regarding the errors that you are seeing, would it be possible for you to please provide some additional information on the following?
1. When running your tests, is your application running? If not, please ensure that your application is running when you try to run the tests.
2. As a continuation of #1, when you run your tests are your XamDataGrid/XamPivotGrid controls in view? If not, the Coded UI tests will fail to find these elements, and the tests will fail. If either of the answers to #1 or #2 are "no," this could explain the issue with the identification of your elements.
3. Were you able to run the tests in the sample project that I had provided you a few updates prior to this one?
When running your tests, is your application running? If not, please ensure that your application is running when you try to run the tests.
Answer: Yes. Installed version of the application running. Do you need to run it via locally?
As a continuation of #1, when you run your tests are your XamDataGrid/XamPivotGrid controls in view? If not, the Coded UI tests will fail to find these elements, and the tests will fail. If either of the answers to #1 or #2 are "no," this could explain the issue with the identification of your elements.
Answer: The Xamdatagrid is in the view. What should be done if this is how our app is designed?
Were you able to run the tests in the sample project that I had provided you a few updates prior to this one?
Answer: We were able to run the tests on the sample project. And, then tried to same conversion for our controls but would not work on our xamdatagrid.
Thanks a lot. Awaiting your reply. Palak
Unfortunately, if the application is running, the XamDataGrid is in view, and you were able to run the tests in the original sample project I had sent you, I am rather unsure as to why your CodedUI tests are failing with the "the playback failed to find the control..." messages. I have done a bit of research on this error, and the following articles could help you on this matter:
1. http://stackoverflow.com/questions/28220334/the-playback-failed-to-find-the-control-with-the-given-search-properties-in-code.
2. https://social.msdn.microsoft.com/Forums/en-US/dbf603f5-c07d-4542-a6d8-0cbdb8e59716/playback-failed-to-find-the-control-with-given-search-propertice?forum=vsautotest.
Regarding your additional questions on points 1 and 2, it is possible that you would need to run the application locally, but I am not entirely sure on this. Perhaps you should try running the .exe that gets pushed to the bin => Debug folder of your application to see if that helps to run your tests?
If your application is designed such that the XamDataGrid is not in view when you try to run the tests, I would likely have to recommend that you add some extra steps to those tests such that the grid is in view when the tests are run, otherwise I would imagine that the pieces of your tests that access your grid would fail.
If the suggestions above still yield the inability to run your CodedUI tests, then would it be possible for you to please provide a small, isolated sample project that reproduces this behavior that you are referring to so that I may be able to offer further guidance?