Coded UI Test: Why does application close after each test in Visual Studio 2012?

Coded UI Test: Why does application close after each test in Visual Studio 2012?

Rate This
  • Comments 6

 In Visual Studio 2010 SP1, Coded UI Test added a flag CloseOnPlaybackCleanup to ApplicationUnderTest class. For cases where an application is launched during test run, this flag helps determine whether to close the application under test after test is over.  Default value for the flag was set to true (closes the application) as it is not advisable to re-use resources from other test cases. But although this flag was introduced, the Coded UI engine was not honoring the value due to a bug that we have fixed. As a result, all applications would continue to run even after the flag is set to true in VS 2010 SP1

Since the bug is fixed in Visual Studio 2012 users will see  BrowserWindow / ApplicationUnderTest is getting closed after each test case if they don't have CloseOnPlaybackCleanup flag set to false. 

 If you want to reuse any application instance launched in another test case, you have to assign CloseOnPlaybackCleanup flag to false for ApplicationUnderTest / BrowserWindow object.

Please refer to sample code as below. If you run all these three tests together, BrowserWindow will be launched only once, remaining other tests will use existing browser instance from the previous test. If you run each test individually, then each test case will close the browser at the end of the run.



 The same principle is applied with running tests using Command Line. If you are running tests altogether, the Application Under test will remain open in between tests in case CloseOnPlaybackCleanup is set to false. Once the run is over, all application instances which were launched during the run are closed.

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
  • Hi Aditya_msft,

    If I run those test methods via Microsoft Test Manager, the application will not be closed.

    I am using VS 2012 Update 2.

    Does it work as designed?



  • This code worked when I copied it into a test project.

    However, if I record a test and generate the code, then move the code to UIMap.cs and edit to set the CloseOnPlaybackCleanup property to false, the browser still closes after the test run completes.

    Is there a fix for this? It is not practical to avoid using the recorder to generate test methods.

  • Hi,

    In my test, I am not using any Application Under Test/Browser Window objects to launch the application. In spite of that, after the test execution using MSTest, the application is getting closed. The blog here mentions that this will happen as the CloseOnPlaybackCleanup flag is set to true by default for Application Under Test/Browser Window classe objects. The actual behaviour of the MSTest is contradicting to what is mentioned in the blog here.

    Could you please clarify the same?

  • This code is working for me thanks. Also it would be nice if there is a way to run the test in multiple browser without running the test again every time you change the default browser.

  • Hello,

    I'm using a client server app that I want to launch the application and run a full regression suite against. Can you tell me where to set the CloseOnPlaybackCleanup flag? I want to call a test that has a method to launch the application and then use an ordered test to run multiple tests against the application.


  • I have the same scenario as lobuejr. Anyone has any clue? There is an application which I need to preserve, it is not a browser.

Page 1 of 1 (6 items)