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
Can Ranorex implement automate GUI with Multi thread
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Please see the following sample:
This sample starts the windows calculator two times and automates both instances simultaneously.
Jenö
Ranorex Team
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
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
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Hi sheng,
You can determine the parent application of your form with a small workaround as follows:
Hope this helps!
Gabor
Ranorex Support Team
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
}
}
}
Gabor
Ranorex Support Team