Page 1 of 1

Issue using the CloseApplication function

Posted: Thu Oct 16, 2014 2:08 pm
by JimLin
I am testing a desktop application using RS v5.1.1.

I am trying to use the CloseApplication functionality and am having problems. I have the code module in the TearDown section of each test case and if the AUT is up and running, then it gets closed gracefully or ungracefully as appropriate.

The issue I have, which I have tried to research a solution for but failed, is that if the test case is successful and the AUT is closed gracefully as part of the test, the TearDown step hangs because Ranorex is looking for something to close but can't find it because it has already been closed during the test. The test step will eventually timeout with an error.

I have written some code for an IF (the AUT is running) close/kill it then end ELSE IF (the AUT is not running) then end, but it doesn't solve the issue. I have also used it as part of a standard recording module, but the same issue occurs.

Sorry, I can't get the code to format correctly.

Code: Select all

  public void Close_Application_TCASProcess2()
        {
        	if (repo.TCASApplication.TCASProcess.Visible.Equals(true)) // AUT has hung, crashed etc {   	
        	Report.Log(ReportLevel.Info, "Application", "Closing application containing item 'TCASApplication.TCASProcess'.", repo.TCASApplication.TCASProcessInfo);
                Host.Local.CloseApplication(repo.TCASApplication.TCASProcess, 10000);
                }
        	else if (repo.TCASApplication.TCASProcess.Visible.Equals(false)) // AUT has closed gracefully as part of the test
        	{
        	Report.Info("TCAS process has closed successfully"); 
	        }
        }
Any help or suggestions gratefully received.

Cheers,
James

Re: Issue using the CloseApplication function

Posted: Mon Oct 20, 2014 1:16 pm
by Support Team
Hi JimLin,

If the Visible property is false, it will throw an ElementNotFoundException. You can either use a try-catch block in order to handle this exception or you can use the exists()-method of the desired element. I would recommend using the exists()- method.
For example:

Code: Select all

if(repo.Calculator.SelfInfo.Exists())
{
    Report.Info("Closed by Teardown Section");
    repo.Calculator.Close.Click();
}
else
    Report.Info("Calculator already closed");
This will check the existence of the calculator application and closes the application but it does not throw an exception.

Regards,
Markus (S)

Re: Issue using the CloseApplication function

Posted: Mon Oct 20, 2014 5:30 pm
by JimLin
Hi Marcus, thanks for the code and explanation. I have implemented it successfully.