2

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

There, when Im 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.

(MSDN : http://blogs.msdn.com/b/visualstudioalm/archive/2012/11/08/using-same-applicationundertest-browserwindow-across-multiple-tests.aspx

StackOverFlow : https://stackoverflow.com/questions/27936231/codedui-the-browser-gets-closed-as-finish-testing-without-keeping-for-testing)

My written code is provided below.

---
-- common.cs  
[TestMethod]
    public void LoadLocalHost()
    {
      this.UIMap.LoadLocalHost();
    } 
---
-- UIMap.Designer.cs
public void LoadLocalHost()
    { 
      this.UIMsnInternetExplorerWindow.LaunchUrl(new System.Uri("http://localhost:5500/"));
      Console.WriteLine(UIMsnInternetExplorerWindow.CloseOnPlaybackCleanup);
      UIMsnInternetExplorerWindow.CloseOnPlaybackCleanup = false;
    }

Highly appreciate an assistance from some one who can.

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 '15 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/… – Niels van Reijmersdal Jan 27 '15 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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