Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Recently I came to know from the article –

http://blogs.msdn.com/b/patrickdanino/archive/2009/11/11/custom-controls-and-ui-automation.aspx

- that controls in WPF are responsible for exposing their UIA items themselves, and any newly added fuctionalities of a custom control aren’t available to the UIA until they are exposed through the implementation of the corresponding AutomationPeer class. At my work I have been assigned to the automation of UI testing of a WPF application that employs a large number of ToolBars. The problem is, through Microsoft UI Automation Library I can access the ToolBars (apparently which are developed as custome control) as AutomationElements, but I cannot access the Buttons inside them – Count of Children/Descendant Collection always return 0. When using Coded UI Test, the tests always fail and shows the following Error Message:

Test method CAM2QDummyTest.CodedUITest2.CodedUITestMethod1 threw exception:

Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnBlockedControlException: Another control is blocking the control. Please make the blocked control visible and retry the action.

Additional Details:

TechnologyName: 'MSAA'

Name: 'Standard'

ControlType: 'ToolBar'

---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xF004F003


Apparently they didn’t implement the corresponding AutomationPeer classes. Now, I only have the application, not the source code. So I cannot solve the problem in the way described in the article I mentioned above. Can anyone HELP with any clue how can I get access to the inner Buttons of the ToolBars? Any suggestion will be greatfully appreciated. Thanks to all.
Posted
Updated 9-Feb-11 2:38am
v2

I am not sure I fully understood your question, but perhaps you can use VisualTreeHelper?

Link: http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx[^]

On the other hand, if these controls implement the pseudo-inner controls purely via custom rendering/painting (without using any elements at all), then you may be out of luck.

[Update based on our discussion via comments]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Alright, I understand your problem better. My previous assumption was that you were accessing this from a normal application, but that assumption was wrong.

Considering you don't have access to the source code I don't really see how you can work around this. Perhaps you can pass this information back to the developers and ask them to implement this properly so you can get it working your end?

Another idea worth trying is to derive a class from this control, and handle the automation event there, and then test this derived class. The only purpose of the derived class would be to add the missing automation stuff. May not work, but worth a shot.
 
Share this answer
 
v3
Comments
Nero theZero 9-Feb-11 10:00am    
Thanks Nishant for your response. Please take a look at the following article-

http://blogs.msdn.com/b/patrickdanino/archive/2009/11/11/custom-controls-and-ui-automation.aspx

It's a good one, i'm sure you'll like it. It describes my problem scenario & it's solution both very neatly, except for the fact that the solution involves having the source code which is not my case. :-(
Nish Nishant 9-Feb-11 10:06am    
Alright, I understand your problem better. My previous assumption was that you were accessing this from a normal application, but that assumption was wrong.

Considering you don't have access to the source code I don't really see how you can work around this. Perhaps you can pass this information back to the developers and ask them to implement this properly so you can get it working your end?

Another idea worth trying is to derive a class from this control, and handle the automation event there, and then test this derived class. The only purpose of the derived class would be to add the missing automation stuff. May not work, but worth a shot.
Nero theZero 9-Feb-11 11:44am    
Thanks Nishant for your time, & sorry i didn't quite get you. I mean how can i derive a class from a control that is a part of an application!!? Once again, i don't have the code of the controls, or of anything at all. Please enlighten me a bit further.
Nish Nishant 9-Feb-11 15:01pm    
You can add a reference to an exe too (as long as it's a managed assembly). Once you add a reference to the exe, you can now derive from the control (assuming it's public which it most likely will be).
Nero theZero 9-Feb-11 22:34pm    
Thanks Nishant, that really sounds like a very good idea. But it seems i'm missing another clue here. Even if i manage to derive from the custom control successfully, how i'm gonna implement it in the application?? I mean, i have to automate the UI testing for the functional application that will be employing that derived control, not for the control in isolation. Please excuse any ignorance of mine.
Handle the control's Loaded event, and see if its Children colleciton is populated at that point. A WPF control doesn't have any children until it has been rendered.
 
Share this answer
 
Comments
Nero theZero 9-Feb-11 9:16am    
Thanks for the reply Simmons, but you didn't understand. My ToolBars DO NOT have any Children. It seems the ToolBars are developed as custom controls with the inner Buttons being added funtionalities to them, and then these funtionalities haven't been exposed to UIA by NOT implementing the corresponding AutomationPeer classes. Anyway, i'll give Loded event a try though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900