Learn to use Visual Studio, Visual Studio Online, Application Insights and Team Foundation Server to decrease rework, increase transparency into your application and increase the rate at which you can ship high quality software throughout the application lifecycle
More videos »
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.
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.
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.