Open ModalDialog blocks TestClient : Automation API

Open ModalDialog blocks TestClient

Class library usage, coding and language questions.

Open ModalDialog blocks TestClient

Postby lasombra » Tue Mar 04, 2008 2:54 pm

My client application opens a new modal dialog to create a new user:
Code: Select all
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.
lasombra
 
Posts: 9
Joined: Tue Mar 04, 2008 2:36 pm

Postby Support Team » Tue Mar 04, 2008 6:03 pm

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: Select all
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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Postby lasombra » Tue Mar 04, 2008 8:43 pm

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: Select all
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: Select all
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.
lasombra
 
Posts: 9
Joined: Tue Mar 04, 2008 2:36 pm

Postby Support Team » Wed Mar 05, 2008 12:39 pm

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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Postby lasombra » Fri Mar 07, 2008 5:31 pm

Thanks Alex. In this form (threads) I could achieve what I wanted.
lasombra
 
Posts: 9
Joined: Tue Mar 04, 2008 2:36 pm


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests