Can Ranorex implement automate GUI with Multi thread

Ask general questions here.
sheng
Posts: 3
Joined: Thu Aug 07, 2008 4:08 pm

Can Ranorex implement automate GUI with Multi thread

Post by sheng » Thu Aug 07, 2008 4:24 pm

Hi Ranorex Support
My question is can Ranorex to be used in Multi thread, for example, same windows application but launched two times, as these may have the same classname of the Form and control Id, Can Ranorex still automate the GUI of the application? how Ranorex distinguish the same Forms but different instance?

if yes, can you give a sample code of how

The reason I want this is, we have a windows application(developed in VB6) by other company, we want to automate inputing data using the application interface, as this take quite a while to add one record, we need multi thread to speed it up

Thanks
Sheng

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Fri Aug 08, 2008 11:18 am

Please see the following sample:

Code: Select all

System.Diagnostics.Process.Start("calc.exe");
Application.Sleep(1000);
calc1 = Form.Active;

//Application.Start("calc.exe");
System.Diagnostics.Process.Start("calc.exe");
Application.Sleep(1000);
calc2 = Form.Active;

calc1.Activate();
// find and click button '2'
button2 = calc1.FindButton(126);
Mouse.ClickControl(button2);
Logger.Info("Button '2' clicked...");

calc2.Activate();
// find and click button '2'
button2 = calc2.FindButton(126);
Mouse.ClickControl(button2);
Logger.Info("Button '2' clicked...");

calc1.Activate();
// find and click button '+'
buttonAdd = calc1.FindButton(92);
Mouse.ClickControl(buttonAdd);
Logger.Info("Button '+' clicked...");

calc2.Activate();
// find and click button '+'
buttonAdd = calc2.FindButton(92);
Mouse.ClickControl(buttonAdd);
Logger.Info("Button '+' clicked...");

calc1.Activate();
// find and click button '5'
button5 = calc1.FindButton(129);
Mouse.ClickControl(button5);
Logger.Info("Button '5' clicked...");

calc2.Activate();
// find and click button '5'
button5 = calc2.FindButton(129);
Mouse.ClickControl(button5);
Logger.Info("Button '5' clicked...");

calc1.Activate();
// find and click button '='
buttonEqual = calc1.FindButton(112);
Mouse.ClickControl(buttonEqual);
Logger.Info("Button '=' clicked...");

calc2.Activate();
// find and click button '='
buttonEqual = calc2.FindButton(112);
Mouse.ClickControl(buttonEqual);
Logger.Info("Button '=' clicked...");

// Validate output
textBox = calc1.FindTextBox(403);
Validate.HasText(textBox, new Regex("^7"),"Check calculator output", true);							

// Validate output
textBox = calc2.FindTextBox(403);
Validate.HasText(textBox, new Regex("^7"),"Check calculator output", true);						

This sample starts the windows calculator two times and automates both instances simultaneously.

Jenö
Ranorex Team

sheng
Posts: 3
Joined: Thu Aug 07, 2008 4:08 pm

Post by sheng » Fri Aug 08, 2008 12:02 pm

Thanks for this, Looks quite promising...

But ususally one application may have more than one form, how does Ranorex identify when you click a button on application(instance 1) popup a form that will related to instance 1 not instance 2?

For example add a person details GUI have name form and address form, how Ranorex to deal with if adding two person at the same(2 thread) without interfering each other?

Many thanks again
Sheng

sheng
Posts: 3
Joined: Thu Aug 07, 2008 4:08 pm

Post by sheng » Tue Aug 12, 2008 12:38 pm

Hi, any help with my question? Please ....

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Tue Aug 12, 2008 2:33 pm

Hi sheng,

You can determine the parent application of your form with a small workaround as follows:

Code: Select all

using System.Runtime.InteropServices;

namespace DefaultNamespace
{

	public class Class1
	{
		[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
		public static extern IntPtr GetParent(IntPtr hWnd);
		
		
		public Class1()
		{
			if(app1.Handle == GetParent(dialog.Handle)) 
				//Application1
			else if(app2.Handle == GetParent(dialog.Handle)) 
				//Application2
		}
	}
}
Hope this helps!

Gabor
Ranorex Support Team