InvalidOperationException when closing process

Aug 3, 2009 at 12:24 PM

When I do the command application.Close() on an OutOfProcessApplication with TestApi 0.3. I get the following exception:

System.InvalidOperationException was unhandled
  Message="Exception of type 'System.InvalidOperationException' was thrown."
  Source="UIAutomationClient"
  StackTrace:
       at System.Windows.Automation.AutomationElement.GetCurrentPattern(AutomationPattern pattern)
       at Microsoft.Test.ApplicationControl.UIAutomationApplicationImpl.CloseProcessWorker()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

Have any clues to why I might get this exception?

 

Aug 4, 2009 at 12:04 PM

I am unable to repro your exception.  Could you provide a code snippet to provide a little more context to how you are calling application.Close(). 

Aug 6, 2009 at 8:52 AM
Edited Aug 6, 2009 at 8:54 AM

 

I have a Class that provides with Connecting and Closing an application that should be automated.

public

class TestApiConnect
{

 private Microsoft.Test.ApplicationControl.OutOfProcessApplication m_app;
 public Microsoft.Test.ApplicationControl.OutOfProcessApplication automatedApplication { get { return m_app; } }

public void Connect( String applicationFilePath )
{

m_app = new Microsoft.Test.ApplicationControl.OutOfProcessApplication(
  new Microsoft.Test.ApplicationControl.OutOfProcessApplicationSettings{
    ProcessStartInfo = new ProcessStartInfo(applicationFilePath),
    ApplicationImplementationFactory = new Microsoft.Test.ApplicationControl.UIAutomationOutOfProcessApplicationFactory()
});
m_app.start();

}

public void Close()
{
  if(m_app != null)
   {
      m_app.Close(); <--- ERROR occurs in this call.
     m_app = null;
    }
System.Windows.Automation.Automation.RemoveAllEvenentHandlers();
}
}

 

In my TestCases I inherit the "TestApiConnect" and employ functions.

public class Test : TestApiConnect
{
public void Connect(String applicationPath)
{ try ( base.Connect(applicationPath); catch()}

public void Disconnect()
{ base.Close();}

public boolean SomeKindOfAutomationOnTheUI(){ return true if ok. Can then continue with further automations}

}

A test could look something like:
Test.Connect()
Test.SomeKindOfAutomationOnTheUI()
Test.SomeOtherAutomation()
Test.Disconnect()


Perhaps this information can give some more insight...

I also encounter searching for dynamic children ,especially a datagrid, that are created during runtime are way slower than when using TestApi 0.2... I wouldn't consider that issue connected to this problem or ?

*Edited: Removed font tags that was just annoying