1

Recently I came to know from this 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 functionalities 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 custom 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 gratefully appreciated.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
atiyar
  • 7,762
  • 6
  • 34
  • 75

1 Answers1

3

You can have a look at what patterns and properties are supported via AutomationElement.GetSupportedProperties() and AutomationElement.GetSupportedPatterns() to see if there's a different pattern which you can use. It might be that there are list elements, etc. via SelectionPattern or similar which will give you access to the buttons.

Otherwise, get in touch with the vendors and ask them to add the relevant peers.

You can always get the coordinates (maybe by the BoundingRectangleProperty) then use Win32 functions to simulate a mouse click in the appropriate place. Nasty. This thread might help.

Lunivore
  • 17,277
  • 4
  • 47
  • 92
  • THANKS a lot Lunivore. Definitely i'm gonna try the Get methods first. But if i must follow the coordinate approach, is there any way i can communicate with TextBoxes or ComboBoxes too, other than simulating only mouse click for Buttons? Some of my ToolBars contains them too :-( – atiyar Feb 09 '11 at 16:58
  • 2
    Not that I know of. You could try UISpy and see if it can come up with anything, but I suspect if your tree is empty it won't. I wish custom control users would actually implement the automation peers properly - it's so important! – Lunivore Feb 09 '11 at 17:03
  • Well, i see nothing but dead-end then. UISpy, Spy++, Coded UI Test Builder, Inspect - they all came up with no deeper than the ToolBars. Anyway, thanks for your time Luni. – atiyar Feb 09 '11 at 17:31
  • I do know another team wrapped their 3rd party components and gave them AutomationPeers when they were lacking. Maybe that approach could help you. I'm afraid I have no detail on how it was done. – Lunivore Feb 09 '11 at 22:06