I'm working on a CodedUI project to check on a Web Solution.

There, when I'm testing for launching the site (as in launching the web URL), I am facing an issue with closing the browser as it finish testing, where it wont allow to use the same browser instance for further testing, Unless if I keep open a instance of a browser (IE) prior manually before running the test.

Can anyone please assist me with this, where I was unable to find a suitable solution. I even went through articles in MSDN where I posted regarding this issue as a comment which I'm facing, since I tried various ways of Code Snippets so far.

My written code is provided below.

-- common.cs  
    public void LoadLocalHost()
-- UIMap.Designer.cs
public void LoadLocalHost()
      this.UIMsnInternetExplorerWindow.LaunchUrl(new System.Uri("http://localhost:5500/"));
      UIMsnInternetExplorerWindow.CloseOnPlaybackCleanup = false;

Highly appreciate an assistance from some one who can.

1 Answer 1


Preferable you want each test to run in isolation. You don't want any artifacts of a previous test laying around. So closing the browser after each test sounds as a good thing.

A test follows three steps

  • Setup: Launch browser, setup database, etc
  • Test: Run single testcase
  • Teardown: Cleanup

I think you can use TestInitialize and TestCleanup methods, see the Anatomy of a Unit Test.

Also see: https://stackoverflow.com/questions/6193744/what-would-be-an-alternate-to-setup-and-teardown-in-mstest

  • well my current requirement is not to isolate the browser for each step, sir. with that requirement will you be able to assist me further?
    – hirosht
    Jan 27, 2015 at 10:12
  • If I start an application with Process.Start then it stays alive during the second test. Maybe that helps. The code: app = Process.Start(_basePath & "Application.exe") msdn.microsoft.com/en-us/library/… Jan 27, 2015 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.