none
Visual Studio 2013 kills processes started by Coded UI test

    Question

  • I am staring processes with Process.Start(). How do I stop Visual Studio killing them at the end of the test?

    Simplest possible example:

            [TestMethod]
            public void CodedUITestMethod1()
            {
                Process.Start("notepad.exe");
                System.Threading.Thread.Sleep(2000);
            }
    

    I run the test, notepad is started, and after 2s when the test finishes, notepad is killed. I think the processes are being killed rather than the application closed because they close very quickly.

    When the test is run with a test agent, this doesn't happen.

    I am using Visual Studio Update 5.

    Tuesday, July 12, 2016 6:35 PM

Answers

  • There appears to be some confusion here.

    Yes we can use CloseOnPlaybackCleanup flag to close applications at the end of a test, if we use the ApplicationUnderTest class. The default behaviour is to close applications.

    However my question was about applications that are started either with Process.Start, or ApplicationUnderTest with CloseOnPlaybackCleanup false. These are still being closed, but they are closed as you discovered at the end of a test run when the test engine closes.

    I think this is a bug because it makes it look as if CloseOnPlaybackCleanup=false is not working, and it is inconsistent with behaviour when run with a test agent. So I have submitted it to Visual Studio Connect here

    • Marked as answer by johnsonalice Tuesday, July 19, 2016 10:51 PM
    Tuesday, July 19, 2016 10:51 PM

All replies

  • Hi johnsnalice,

    As far as I know, the this is the default action in CodedUI Test. And according to following blog mentioned that "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.".

    https://blogs.msdn.microsoft.com/visualstudioalm/2012/11/08/coded-ui-test-why-does-application-close-after-each-test-in-visual-studio-2012/

    And I also tested the CloseOnPlaybackCleanup for both of BrowserWindows and Windows Desktop application (Notepad), I found that the browsr window wil not closed if I set  CloseOnPlaybackCleanup as false. But for Desktop application, it just don't close the application between tests. After all tests execute finished, the application still be closed.

    Besides, I also tested in Test Agent and get the same result that Notepad are openning after test finished. For this issue, I will use process monitor tomorrow to check whether there has any difference between execute Test through Test Agent. After testing, I will update the result here as soon as possible.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Wednesday, July 13, 2016 12:54 PM
    Moderator
  • Hi johnsnalice,

    After checking with process monitor for this issue, I found that in local test executed by vstest.executionengine.x86.exe, which is the parent process of the notepad.exe. When test executed complete, this vstest.executionengine.x86.exe process is closed which lead to its child process (notepad.exe) also closed.

    In remote test agent, the test is executed by QTAgentProcessUI.exe. It is the parent process of the notepad.exe. And after the test executed finished, this process is not exist because it is managed by Test Agent. The agent is not closed after test executed and the QTAgentProcessUI also exist after test executed. This is why the notepad.exe is not closed.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 14, 2016 6:06 AM
    Moderator
  • Is there a way to stop this? I thought maybe something in the test settings, but I have Keep Test Execution Engine Running checked. There are two reasons this behaviour isn't desirable:

    1. It's inconsistent - so someone writing a test might think the test is ok because when they run it from Visual Studio the applications close, but when it is run by the test agent the application is left open, breaking other tests.
    2. It's desirable to be able to keep the applications open when creating the tests in Visual Studio, as a developer might want the application to stay open to make it easier to develop the next part of the test, or to diagnose why the test failed. However this behaviour is not needed when the test is ready to run with a test agent.

    Best regards,

    Alice

    Thursday, July 14, 2016 6:37 PM
  • Hi Alice,

    I have checked the settings in Test Settings and I don't find such settings.

    There are two workarounds for the two situation:

    Run in local:

    If the test is run in local and process is closed but this application still needed in other test, please try use CloseOnPlaybackCleanup flag mentioned in the link I provided in first reply. It can keep the application opening until all tests complete.

    Run in Remote Test Agent:

    Please try find the Close button of this program and execute the Mouse.Click() to close this application manually in TestCleanup method, which can let the program closed when every test finished.

    Since this is a default action in Coded UI, I suggest you submit your idea to Visual Studio Connect and share the feedback link here. I will vote it and it also can let other communities who has the same problem to vote and add comments for this issue. Thanks for your feedback.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 15, 2016 2:19 AM
    Moderator
  • There appears to be some confusion here.

    Yes we can use CloseOnPlaybackCleanup flag to close applications at the end of a test, if we use the ApplicationUnderTest class. The default behaviour is to close applications.

    However my question was about applications that are started either with Process.Start, or ApplicationUnderTest with CloseOnPlaybackCleanup false. These are still being closed, but they are closed as you discovered at the end of a test run when the test engine closes.

    I think this is a bug because it makes it look as if CloseOnPlaybackCleanup=false is not working, and it is inconsistent with behaviour when run with a test agent. So I have submitted it to Visual Studio Connect here

    • Marked as answer by johnsonalice Tuesday, July 19, 2016 10:51 PM
    Tuesday, July 19, 2016 10:51 PM
  • The responders to your issue *clearly* did not read your question or simply don't know how to read. This was working as expected in VS 2010: an application started with Process.Start would *stay open* upon completion of the test. With VS 2013 those applications started with Process.Start are being killed on completion of the test. It makes no sense. It's a bug.

    I honestly have yet to read a single response from a moderator on this site that actually addresses and solves the users problem. Unbelievable. And worthless. Back to stackoverflow.

    Wednesday, March 8, 2017 10:50 PM