1

Closed

TestAPI 0.4, getting 'System.InvalidOperationException' upon calling AutomatedApplication.Close()

description

Hello,
the issue looks similar to http://testapi.codeplex.com/WorkItem/View.aspx?WorkItemId=13749 but has its own nuances:
 
We have a set of tests built over TestAPI v0.2, each test has tear-down method which calls App.Close(), where 'App' is OutOfProcess AutomatedApplication.
After switching to TestAPI v0.4 We've started to get following upon calling App.Close():
 
System.InvalidOperationException: Exception of type 'System.InvalidOperationException' was thrown.
at System.Windows.Automation.AutomationElement.GetCurrentPattern(AutomationPattern pattern)
at Microsoft.Test.ApplicationControl.UIAutomationApplicationImpl.CloseProcessWorker() in c:\dd\WPF_1\src\wpf\test\Infra\TestApi\TestApiWpf\Code\ApplicationControl\UIAutomationApplicationImpl.cs: line 250
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
Note: The work-around suggested in http://testapi.codeplex.com/WorkItem/View.aspx?WorkItemId=13749 (calling sampleAppPath.Replace("file:\", string.Empty)) doesn't work for our set of tests.
 
The issue is quite painful since we'd like to engage new features in TestAPI but we can't due to the issue.
Thank you in advance.

file attachments

Closed Feb 10, 2011 at 10:42 PM by ivom
NLord,I am closing this issue as it appears to no longer repro.Please, reactivate if you have a reliable repro and we will investigate.Thanks!Ivo

comments

vinsibal wrote Dec 11, 2009 at 5:40 PM

Could you please attach a repro. Thanks.

NLord wrote Dec 15, 2009 at 8:16 AM

As for the reproduction - please find modified NUnit sample solution enclosed. Run VerifyInput() from UIAutomationTest2() to get the issue.

Note: the original issue is stable for our custom tests, but for the attached solution is intermittent.
We get InvalidOperationException in UIAutomationApplicationImpl from time to time:

System.InvalidOperationException: No process is associated with this object.
at System.Diagnostics.Process.EnsureState(State state)
at System.Diagnostics.Process.EnsureState(State state)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
at System.Diagnostics.Process.WaitForExit(Int32 milliseconds)
at Microsoft.Test.ApplicationControl.UIAutomationApplicationImpl.WaitForExit() in c:\dd\WPF_1\src\wpf\test\Infra\TestApi\TestApiWpf\Code\ApplicationControl\UIAutomationApplicationImpl.cs: line 262
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Basing on the source code of UIAutomationApplicationImpl one might assume that the issue is related to threads management/"race conditions".

wrote Dec 15, 2009 at 8:16 AM

vinsibal wrote Dec 18, 2009 at 5:27 PM

From the repro app, which of the tests are failing with that exception? I do see UIAutomationTests.VerifyInput failing the exception from http://testapi.codeplex.com/WorkItem/View.aspx?WorkItemId=13749, but I don't see what stack from above.

When I update your tests with the workaround from the other work item (remove the "file:\" string), I don't get any exceptions.

Note that this seems to only happen with NUnit running on WinXP machines. I don't have any issues running these NUnit tests on Vista. Also, I'm not seeing these issues at all with XUnit or MSTest.

NLord wrote Dec 18, 2009 at 9:05 PM

" ...which of the tests are failing with that exception? "
It's VerifyInput() test from UIAutomationTest2 class (the second one). Also, you might be interested to have a look at the AbstractTest class which is base one for UIAutomationTest2. Please note, that application launching logic in AbstractTest does use the "remove the "file:\" string" work-around. Please also note, that for this sample solution the issue is intermittent while for our "production" tests it's constantly reproducible.

"Note that this seems to only happen with NUnit running on WinXP machines"
You are probably right, the configuration of our workstations is WinXP SP2/VS 2008/ReSharper 4.5/NUnit 2.5.0. However we are obliged to use WinXP and NUnit on the project and can't move to Vista.
Anyway, we had to write custom App.Close() method as a work-around for the issue. As for the rest we are quite happy with v0.4, thank you for the great tool.

wrote Feb 10, 2011 at 10:42 PM

wrote Feb 14, 2013 at 9:08 PM

wrote May 16, 2013 at 11:02 AM