Page 1 of 1

Action 'close' failed on element

Posted: Thu Feb 21, 2013 12:03 am
by Ciege
Hi guys,
Just got done upgrading to 4.0.2.21666 from 3.1.0.13946.

On a line of code that has been used literally thousands of times with no issue, I am now receiving an unexpected exception. I know I can catch this exception myself, and probably will, but I use .CLOSE throughout my tests and am now concerned that I will have to visit the code of each of my tests to specifically add a specific try/catch for that specific exception.

Anything else you can suggest to mitigate this?

For reference, this was discussed as an issue in the past that was actually solved for me: http://www.ranorex.com/forum/closeappli ... t2727.html

Code:

Code: Select all

//Wait for Start Page form to open
Ranorex.Form HDJobPropertiesFormForm = RFW.WaitForFormOfForm(HDClientForm, "JobPropertiesForm", 30);
if (HDJobPropertiesFormForm == null)
{
    Report.Warn("Unable to open Library - Master Job properties Form. Cannot verify all forms will be in a maximized state.");
}
else
{
    HDJobPropertiesFormForm.Activate();
    HDJobPropertiesFormForm.Maximize();
    Thread.Sleep(1000);
    HDJobPropertiesFormForm.Close();     <THIS IS LINE 3081 THAT THROWS THE EXCEPTION

    //Wait for the HDJobPropertiesFormForm to go away
    WindowVisible = HDJobPropertiesFormForm.Visible;
    while (WindowVisible == true)
    {
        Thread.Sleep(500);
        WindowVisible = HDJobPropertiesFormForm.Visible;
    }
    Thread.Sleep(1000);
}
HDJobPropertiesFormForm is just a standard Form that exists within my AUT. I am just calling the close method for this form.

The Exception:

Code: Select all

Ranorex.ActionFailedException: Action 'close' failed on element '{Form:Job Properties - Library}'. ---> System.InvalidOperationException: Failed to get response from control within 2000 milliseconds.
at Ranorex.Plugin.WinFormsFlavorElement.InvokeMethod(BindingFlags flags, String name, Object[] args, Duration timeout)
at Ranorex.Plugin.WinFormsFlavorElement.InvokeMethod(BindingFlags flags, String name, Object[] args)
at Ranorex.Plugin.WinFormsFlavorElement.InvokeAction(Element element, String name, Object[] args)
at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
--- End of inner exception stack trace ---
at Ranorex.Core.Element.InvokeAction(String name, Object[] args)
at Ranorex.Form.Close()
at RanorexFramework.RFW.HardDollarStartClient(String strHardDollarPath, String strJobToOpen, String strRemoteServerName) in C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\RanorexFramework\RanorexFramework\Class1.cs:line 3081

Re: Action 'close' failed on element

Posted: Thu Feb 21, 2013 11:52 am
by Support Team
Hi Ciege,
Ciege wrote:Just got done upgrading to 4.0.2.21666 from 3.1.0.13946.
I don't think that the behavior you experience is a change from 3.1.0 to 4.0.2. As far as I can see, there were no substantial changes made to the WinForms plugin that would influence that behavior.

Actually, this exception is by design if, for example, the form takes longer than 2 seconds to close. I.e.if the form performs some internal operation on a close event handler that takes longer than 2 seconds, then Ranorex throws an exception - I just reproduced that behavior with 3.1.0, too.

As you stated in the post you mention, there was a bug fixed in Ranorex V2.3.1 that a SerializationException was sometimes thrown by the Close method on WinForms forms. Still, you have to catch the timeout exception you experience, since Ranorex does not know whether the Close action was actually got by the WinForms form.

If you know that your form takes more time to close, you can call Control.InvokeMethod instead and pass "Close" and a longer timeout as arguments.

Regards,
Alex
Ranorex Team

Re: Action 'close' failed on element

Posted: Thu Feb 21, 2013 3:38 pm
by Ciege
OK, I'll look into what will be my easiest fix throughout my code to address this specific exception.
It is odd though that I can switch my VM back to the 3.1 version of Ranorex with the same version of my AUT and the exception does not occur at the same place, then reverting back to the new 4.0.2 the exception does occur.

It's not the end of the world, just need to take some time to address the issue from my end I suppose.

Thanks...

Re: Action 'close' failed on element

Posted: Thu Feb 21, 2013 4:47 pm
by Support Team
Ciege wrote:It is odd though that I can switch my VM back to the 3.1 version of Ranorex with the same version of my AUT and the exception does not occur at the same place, then reverting back to the new 4.0.2 the exception does occur.
Right, that was worrying me, too. That's why I did a code study on all changes since 3.1 and tried to reproduce the problem both with 3.1.0 and 4.0.2. However, I did not find any differences.

Could that be timing? Or a control that is now, with 4.0.2, recognized as a WinForms control?

Regards,
Alex
Ranorex Team

Re: Action 'close' failed on element

Posted: Thu Feb 21, 2013 5:11 pm
by Ciege
Well, the Control.InvokeMethod suggestions works...
I'm still just curious as to what the new delay is... I'm watching the test run (Windows 8 with a runtime license) and have noticed that my test EXE is pegging the CPU while it is running. That seems to be the root of the issue. My AUT is being resource starved because the EXE is taking 99% of the CPU according to task manager.

Time to do a little investigation...