| View previous topic :: View next topic |
| Author |
Message |
lasombra
Joined: 04 Mar 2008 Posts: 9
|
Posted: Tue Mar 04, 2008 2:54 pm Post subject: Open ModalDialog blocks TestClient |
|
My client application opens a new modal dialog to create a new user:
Code: click into code to enlarge
Ranorex.Element elemMenuItem = mainForm.Element.FindChild(Ranorex.Role.MenuItem, "New User");
elemMenuItem.DoDefaultAction();
Ranorex.Form myForm2 = Ranorex.Application.FindFormTitle("Standard User");
While the dialog is open, the client application is blocked until I close the modal dialog by hand. What or how I can do with ranorex, that the client application don't block and continues running?
I know that there is an issue with UIA, where I must to subscribe to an UIA event (e.g. SubscribeToInvoke) before I click on a button, that opens a modal dialog. But this possibility I miss in ranorex. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 256
|
Posted: Tue Mar 04, 2008 6:03 pm Post subject: |
|
The Element.DoDefaultAction() method blocks until the default action is executed. So, if the default action is an EventHandler that opens a modal dialog, the DoDefaultAction method will block until the EventHandler returns. It is similar to the .NET Control.Invoke mechanism.
The solution is either to use Mouse.ClickElement to click on the menu item or to spawn a new thread that searches for the Element and calls DoDefaultAction:
Code: click into code to enlarge
Thread thread = new Thread(new ThreadStart(delegate
{
Ranorex.Element elemMenuItem = mainForm.Element.FindChild(Ranorex.Role.MenuItem, "New User");
elemMenuItem.DoDefaultAction();
}));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Thread.Sleep(500);
Ranorex.Form myForm2 = Ranorex.Application.FindFormTitle("Standard User");
// do stuff with myForm2
Regards,
Alex
Ranorex Support Team |
|
| Back to top |
|
 |
lasombra
Joined: 04 Mar 2008 Posts: 9
|
Posted: Tue Mar 04, 2008 8:43 pm Post subject: |
|
Thanks for your answer. Unfortunately I have a strange problem with the Mouse.ClickElement, for which reason I'd like the DoDefaultAction(). Well, the problem is the following: I have a loop (can be a sequence too, the problem appears anyway) to create various users:
Code: click into code to enlarge
for (int i = 0; i < 5; i++)
{
myTreeView = myHelper.FindTreeView("mTreeView");
myTreeView.SelectItem("Everyone");
Ranorex.Application.Sleep(300);
myHelper.clickMenuItem("File/New/User");
myHelper.clickMenuItem("Edit/Rename");
Ranorex.Application.SendKeys("UserGroup" + i + "{ENTER}");
and in the class myHelper
Code: click into code to enlarge
public void clickMenuItem(String menuPath)
{
foreach (String menuItem in menuItems)
{
String[] menuItems = menuPath.Split('/');
foreach (String menuItem in menuItems)
{
Ranorex.Element elemMenuItem = mainForm.Element.FindChild(Ranorex.Role.MenuItem, menuItem);
Ranorex.Mouse.ClickElement(elemMenuItem);
}
}
}
The code opens a menu "File>New>User". This works well the first time. The second time the element "User" found by FindChild() contains the wrong x coordinate, which sends the mouse to the wrong point. The x coordinates seems to be the same as the x coordinate of the main application window (Ranorex.Form).
I don't understand why the first time to object properties are correct and the second time not.
Update
In some cases (e.g. other menu items) the use of the Ranorex.Mouse.ClickElement() don't work either the first time.
The menu is a MenuStrip. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 256
|
Posted: Wed Mar 05, 2008 12:39 pm Post subject: |
|
Well, that's in fact a strange problem. Are your testing application and the application under test separate processes?
You can also try using the MenuStrip.SelectItemText() method that basically replaces your myHelper.clickMenuItem method.
Anyway, if your using a separate thread to find the MenuItem element and invoke DoDefaultAction in that thread (like in my sample code posted before), it should also work.
Regards,
Alex
Ranorex Support Team |
|
| Back to top |
|
 |
lasombra
Joined: 04 Mar 2008 Posts: 9
|
Posted: Fri Mar 07, 2008 5:31 pm Post subject: |
|
| Thanks Alex. In this form (threads) I could achieve what I wanted. |
|
| Back to top |
|
 |
|