Page 1 of 1

How to use custom controls in recording.usercode

Posted: Thu Jan 14, 2010 2:02 pm
by bd142857
Hello all,

I am new to Ranorex and I want to ask a question about testing custom WPF controls. I have implemented a custom WPF control which directly derives from System.Windows.Controls.Control. First of all, I tried to see my control on Ranorex Spy but I couldn't. than I have learned that I have to override "OnCreateAutomationPeer" and implement a peer class. I have updated my control and at last I have managed to see my control on Spy. Then I tried to get my control on the user code side of a recording(Recordingx.UserCode.cs) in order to call some properties of the control for validation but I could not manage. And as I understand, if I manage to get my control's adapter, it will have the type Ranorex.Unknown. So i will not manage to use the properties. What is your suggestion, is it a bad idea to use Ranorex for testing custom developped WPF controls? :cry:

Cheers

Re: How to use custom controls in recording.usercode

Posted: Mon Jan 18, 2010 1:11 pm
by Support Team
If you do not derive from System.Windows.Controls.Control, but from System.Windows.Controls.UserControl (which is the way recommended by Microsoft), then you do not need to override the OnCreateAutomationPeer in the first place and Ranorex will immediately see all the controls you add to your user control!
bd142857 wrote:Then I tried to get my control on the user code side of a recording(Recordingx.UserCode.cs) in order to call some properties of the control for validation but I could not manage.
Calling properties directly on the control is currently only supported for Windows Forms controls, for WPF controls this is a wanted feature we will implement in one of the next Ranorex versions.
bd142857 wrote:What is your suggestion, is it a bad idea to use Ranorex for testing custom developped WPF controls?
No, this is definitely not a bad idea :-) If you use standard WPF controls in your user control, Ranorex will instantly see and identify these controls. The only thing Ranorex can't automatically recognize are controls that you draw yourself, e.g. shapes. In order to automate such controls as well, you should - instead of calling properties and methods of your control directly - rather extend the UIAutomation support of your control! See the following MSDN page for more information: http://msdn.microsoft.com/en-us/library/cc165614.aspx
By doing that, Ranorex will get the information from your control through UIAutomation; besides you also improve the screen reader support of your control.

Regards,
Alex
Ranorex Support Team