Custom Ranorex Classes

Ask general questions here.
this_is_ridiculous
Posts: 27
Joined: Tue Apr 27, 2010 10:33 pm

Custom Ranorex Classes

Post by this_is_ridiculous » Tue Apr 27, 2010 10:54 pm

Hi!
I'm new to Ranorex. I'm currently using version 2.1.4.xxxx. I've found there's no functionality to move and resize windows onboard. So i think it should be developed manually. And from this point i've got a few question:
1. Is there any way for cross converting e.g. Ranorex.Form to System.Windows.Forms.Form?

2. Is there any way to create custom Ranorex classes? Let's assume I need the funcionality mentioned above for tested application's windows (move and size) and I'd like them to be implemented as methods. So I need my custom class inherited from Ranorex.Form with some custom methods to do the work. If it is possible how could this be achieved?

3. If there is the way to create custom class inherited from the native Ranorex class will Ranorex Spy (the integrated one to the Studio) see my custom class instead of native class. This could be e.g. Window instead of Form with only a few methods added to it?

Thanks in advance.
Artem.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Custom Ranorex Classes

Post by Ciege » Wed Apr 28, 2010 12:34 am

There was a brief discussion on resizing windows from Ranorex here that you might find useful.
http://www.ranorex.com/forum/resizing-a ... -t866.html
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

this_is_ridiculous
Posts: 27
Joined: Tue Apr 27, 2010 10:33 pm

Re: Custom Ranorex Classes

Post by this_is_ridiculous » Wed Apr 28, 2010 11:10 am

That's not exactly what i need. We use Ranorex for product localization instead of testing. Product has flipping windows with side caption and it's not good to know where window does have its caption right now. And it really does not matter so much wheather it's dotNet window or MFC window to move or resize it using winapi if force the window to repaint itself. And Currently Move and size is functionality works throuh winapi. But window that should be moved or resized is passed as parameter to corresponding function. But I want these functions to be methods of any window that is detected by Ranorex as Form. That's the point.

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

Re: Custom Ranorex Classes

Post by Support Team » Wed Apr 28, 2010 11:36 am

Since V2.2 the Ranorex.Form class provides Move and Resize methods.

ad 1.) No, a Ranorex.Form just represents any kind of form - not necessarily a System.Windows.Forms.Form.

ad 2.) You can create your own adapter classe just by inheriting from Ranorex.Form. Your users can then use the custom adapter class.

ad 3.) Well, there is a way, but you have to create a Ranorex plugin and that ususally requires special training. Basically, you have to create a simple plugin (see this forum thread on how to create a simple Ranorex plugin) and then call the Ranorex.Core.ElementEngine.Register(string, type) method in the plugin initialization to register your custom adapter class (e.g. "FormCustom") for the "form" capability.

Regards,
Alex
Ranorex Support Team
.
Image

this_is_ridiculous
Posts: 27
Joined: Tue Apr 27, 2010 10:33 pm

Re: Custom Ranorex Classes

Post by this_is_ridiculous » Wed Apr 28, 2010 12:29 pm

Support Team wrote: 2.) You can create your own adapter classe just by inheriting from Ranorex.Form. Your users can then use the custom adapter class.

Regards,
Alex
Ranorex Support Team
Thanks! Nice to hear that.

Is there any kind of example of creating custom Ranorex classes and inheritance of Ranorex classes?

Would be greatful for any help.

Artem.

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

Re: Custom Ranorex Classes

Post by Support Team » Wed Apr 28, 2010 12:55 pm

Hi!

No sorry we don't have an example for creating his own adapter. But take a look to this link
http://support.microsoft.com/?scid=kb%3 ... 5&x=9&y=10

Regards,
Peter
Ranorex Support Team
.
Image

this_is_ridiculous
Posts: 27
Joined: Tue Apr 27, 2010 10:33 pm

Re: Custom Ranorex Classes

Post by this_is_ridiculous » Wed Apr 28, 2010 1:09 pm

That didn't help. I get this error:

Cannot implicitly convert type 'string' to 'Blackbox.Window'. An explicit conversion exists (are you missing a cast?) (CS0266)
my custom class description looks like:

Code: Select all


public class Window : Ranorex.Form
	{
		[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
    	private static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
		
    	public Window()
    	{
    		
    	}
    	
    	public void RePlaceReSize(int xPos, int yPos, int xSize, int ySize)
    	{
    		IntPtr winHandle = (IntPtr)this.Element.GetAttributeValue("Handle");
    		MoveWindow(winHandle, xPos, yPos, xSize, ySize, true);
    	}
    	
}

Next in the script i try to use Window instead of Form but i get error i mentioned above. What kind of cast am i missing?

Thanks in advance.
Artem.

this_is_ridiculous
Posts: 27
Joined: Tue Apr 27, 2010 10:33 pm

Re: Custom Ranorex Classes

Post by this_is_ridiculous » Wed Apr 28, 2010 4:37 pm

Hi all!

Ok! For now i've resolved my problem with custom classes. May be someone also will face the same problem.

My aproach is the following:

Code: Select all

public class Window : Ranorex.Form
	{
		[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
    	private static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    	    	
    	public Window()
    	{
    		
    	}
    	
    	public static Window NewWindow(string xPath)
    	{
    		Ranorex.Form frm = xPath;
    		return frm.As<Window>();
    	}
    	
    	    	
    	public void RePlaceReSize(int xPos, int yPos, int xSize, int ySize)
    	{
    		IntPtr winHandle = (IntPtr)this.Element.GetAttributeValue("Handle");
    		MoveWindow(winHandle, xPos, yPos, xSize, ySize, true);
    	}
    	
}
Don't worry about the DllImport. I used this WinApi to move and size windows before version 2.3. But still it does the trick. The RePlaceReSize could be used to prepare the window in one line of code for screenshooting for example. Actually this is the purpose of custom classes in Ranorex. Trying to move away from Borland SilkTest to more common coding aproach. :)

Than all windows/dialogs of the tested/localized app that are recorded as Ranorex.Form can be initialized like this:

Code: Select all

Window wConn = Window.NewWindow("/form[@title='_MAPCONNECT']");

Please see the screenshot attached.
You may ask why custom screenshooting method... It's because of layerd windows in the product. The opacity of those windows can be set up manually and these windows could be captured only using Windows framebuffer.

Regards!

Artem.
Attachments
intelisense.png
and the result of this all on the attached screenshot
intelisense.png (23.21 KiB) Viewed 1539 times

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

Re: Custom Ranorex Classes

Post by Support Team » Wed Apr 28, 2010 5:39 pm

To create a fully functional adapter, I recommend adding two implicit casts (from string and from Element) and an additional constructor to your adapter class. Please, see the attached file for a standard implementation of the MyAdapter class!
MyAdapter.cs
MyAdapter recommended implementation
(2.83 KiB) Downloaded 285 times
Regards,
Alex
Ranorex Support Team
.
Image

this_is_ridiculous
Posts: 27
Joined: Tue Apr 27, 2010 10:33 pm

Re: Custom Ranorex Classes

Post by this_is_ridiculous » Wed Apr 28, 2010 5:48 pm

WOW!!! Your support is awsome!! I wish all teams to have such a support! THANK YOU AGAIN!