Page 1 of 1

Ranorex get struck on attempting to click a button in msgbox

Posted: Tue Dec 23, 2014 1:34 pm
by ChrisDavid

Code: Select all

public void Handle_messagebox()
{

if(repo.Folder1.Button1Info.Exists())
{
	Report.Info("Found message box. Clicking on Ok button.");

	repo.Folder1.Button1.MoveTo();
	repo.Folder1.Button1.Click();	            
}
else
{
	Report.Info("Did not find Message box.");
}

}
I have above simple code but while executing it, Ranorex seems to be struck on identifying the button in the message box. 'If statement' gets executed(which means button is recognized) and the info message is displayed and then for some reason ranorex gets struck there and no action is performed forever. No 'item not found' error is thrown even. Its just struck for hours and no action is performed. Once the button is clicked manually, run seems to continue with next steps.

This is inconsistent, This passes sometimes and fails most of the times. Sometimes it gets struck in the 'if' statement itself, once button is clicked manually info message in else statement in displayed.

This happens particullary with this message box only, with other this kind of message/dialog box, it seems to be working fine.

Can anyone please clarify why this is happening and how we can rectify it?

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Wed Dec 24, 2014 1:01 pm
by Support Team
Hi Chris,

Please make sure that the Use Cache property of the Folder1 reposiotry folder is set to false and just use either a RepoItem.MoveTo or a RepoItem.Click:
if(repo.Folder1.Button1Info.Exists())
{
   Report.Info("Found message box. Clicking on Ok button.");

   repo.Folder1.Button1.MoveTo();
   Mouse.Click();            
}
// OR:
if(repo.Folder1.Button1Info.Exists())
{
   Report.Info("Found message box. Clicking on Ok button.");

   repo.Folder1.Button1.Click();         
}
I hope this helps!

Regards,
Markus

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Wed Dec 24, 2014 3:02 pm
by ChrisDavid
Hi Markus,

Thanks for your response. 'Use Cache' property of the repository folder is set to False already.

The issue is inconsistent and we can not determine where it will fail. Sometimes it gets struck in 'If Statement', sometimes at Movteto() step, sometimes in click() step.

You first suggestion is working fine but sometimes it gets struck at the MoveTo step itself. Log during the run shows as its searching for the item but it does not fails after the search out time of the item, it keeps on searching the item forever and gets struck there. Why is this happening? Is there any other way to handle this?

I access my application from remote machine and so sometimes just using click() does not clicks the item correctly and so I have to use both MoveTo() and Click(). And so I cant use your 2nd suggestion.

Regards,
Chris

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Sat Dec 27, 2014 2:58 am
by ChrisDavid
On performing few more trial and error on this I found out that it does not have anything to do with the item in the repository but just the appearance of this particular dialog box is making Ranorex to pause indefinitely.

In the code I removed all the lines that access this dialog and added a step to press enter key at the time when this dialog box will be displayed. But still somtimes Ranorex seems to be struck as soon the dialog is displayed. I just have Report.Info after this dialog is displayed. But still Report.Info step is also not executed.

Code: Select all

Report.Info("Previous dialog is closed");	   //This line is executed
Report.Info("Looking for next dialog");           //At this point dialog box will be displayed and no more code is executed(including this line) until the dialog box is closed manually.
Report.Info("Press enter key to close dialog");
Keyboard.Press(System.Windows.Forms.Keys.Enter);
In the above code, first line is executed and then the log gets struck there and no more action is performed by ranorex after the dialog is displayed. Next line is just a report.info line which is also not executed. Ranorex gets struck there for indefinitely. Once the dialog is closed by manual intervention, run continues from where it was struck.

This is not consistent, happens once in 5 times but when it happens, its getting struck forever which is causing lots of trouble for us. Why does the display of a particular item is making ranorex struck there forever until the item is closed? How to handle it?

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Mon Dec 29, 2014 2:13 pm
by Support Team
Hi Chris,

That's weird, it sounds like a problem with the main thread of your application, could it be that the main thread is paused when the specific dialogue is shown?
May I also ask you what kind of application you test, a WPF application?
Would it be possible to send us a sample application which allows us to reproduce the issue on our machine?

Regards,
Markus

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Tue Dec 30, 2014 6:55 pm
by dhale
Some additional information about the issue:
This is a WinForms app, using .net 4.0. The issue is random, sometimes happens right away, sometimes late into the test run. Caching is off for the dialog in question. Happens on both 32 and 64 bit Win7 workstations.

It appears Ranorex is hung at creating the adapter for the ok button best I can tell via the debugger within Ranorex.
Specifically, when I paused the test run when it hangs and look at the call stack, it is hung in the repository method

Code: Select all

public virtual Ranorex.Button Ok_Button
            {
                get
                {
                    return _ok_buttonInfo.CreateAdapter<Ranorex.Button>(true);
                }
            }
The message box that is causing the issue is configured as follows: (note descriptive text has been edited out)

Code: Select all

MessageBox.Show("SomeText: More text.", "Alert text",
                        MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
I suspect (but am unsure) that the issue may be related to MessageBoxOptions.DefaultDesktopOnly option specified. When I look at threads, I see that Main is in Location: get_Ok_Button, priority is: normal, and Frozen is: No

If we manually dismiss the dialog, the test run will continue without fail.

I have taken a snapshot of the dialog if it may help any.

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Tue Dec 30, 2014 10:19 pm
by dhale
I just tried a slightly different approach, via pop up watcher class to see if that would behave any different - no luck. Same issue. Random freezing after multiple sucess when late in the test run. Still gets stuck in the repository when trying to create the adapter.

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Wed Jan 07, 2015 2:06 pm
by Support Team
Hi dhale,

We analyzed the issue and this is indeed connected to the MessageBoxOptions, in specific to the "DefaultDesktopOnly" member.
It works as expected when you don't use this option at all or when you use one of the other members since the "DefaultDesktopOnly" option somehow creates another process for the MessageBox and makes the main form "Not Responding" and furthermore forces Ranorex to freeze since the MSAA peer hangs.

I would therefore highly recommend to not use the "MessageBoxOptions.DefaultDesktopOnly" attribute.

Regards,
Markus

Re: Ranorex get struck on attempting to click a button in msgbox

Posted: Wed Jan 07, 2015 4:33 pm
by dhale
Thanks for the confirmation.
We will work with our developers to get around this particular issue.