How to use custom controls in recording.usercode

Ranorex Spy, Recorder, and Studio.
bd142857
Posts: 2
Joined: Thu Jan 14, 2010 1:49 pm

How to use custom controls in recording.usercode

Post by bd142857 » Thu Jan 14, 2010 2:02 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to use custom controls in recording.usercode

Post by Support Team » Mon Jan 18, 2010 1:11 pm

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
.
Image