14

I'm writing some codedUI tests in VS2010 to test a web application. I'd like to be able to open the browser once for the entire set of tests in the solution and then close it again when the tests finish.

I've tried AssemblyInitialize attribute on a method, with my BrowserWindow.Launch in there, but it gives me the following exception when I run it:

Assembly Initialization method OrdersGridTesting.SuiteSetup.Login threw exception. Microsoft.VisualStudio.TestTools.UITest.Extension.TechnologyNotSupportedException: Microsoft.VisualStudio.TestTools.UITest.Extension.TechnologyNotSupportedException: The browser is currently not supported.. Aborting test execution.

This same code works fine when I put it into a TestMethod, which leads me to believe that this isn't possible. Can someone suggest another method of doing this if so? I'd like a method that doesn't involve adding the same code to every test class in the project, if possible.

Thanks!

abatishchev
  • 92,232
  • 78
  • 284
  • 421
rythos42
  • 1,187
  • 2
  • 10
  • 26
  • Can't even do this in `ClassInitialization`, which would be a not-terrible alternative. – rythos42 Aug 22 '11 at 17:08
  • It throws an error because playback hasn't been initialized. TestInitialize implicitly calls playback.initialize() – stoj Jan 18 '12 at 18:58

2 Answers2

13

If using ClassInitialize, you need to initialize the playback engine with Playback.Initialize()

  [ClassInitialize]
  public static void LaunchBroswer(TestContext context)
  {         
     Playback.Initialize(); 
     BrowserWindow browser = BrowserWindow.Launch(new System.Uri("about:blank"));
  }
Tom E
  • 2,489
  • 2
  • 17
  • 22
  • 1
    I continued working with TestInitialize after I asked the question...and realized that I didn't want to load the browser before the entire test run anyway. If I did, I wouldn't have the test conditions reset before each test run! But I'm glad to know this for the future. – rythos42 Aug 31 '11 at 16:32
  • 1
    I added Playback.Initialize() function to my AssemblyInitialize method and it didn't make a difference - I'm still getting the error. I'm using an ordered test list to run all my tests. – Ciaran Gallagher Sep 03 '12 at 09:41
  • 1
    I even tried this where I couldn't get it solved. It still keeps closing the browser after testing the step. – hirosht Jan 14 '15 at 05:11
0
 BrowserWindow uatwebjetcomauBrowser = BrowserWindow.Launch(new System.Uri(this.LaunchBrowserParams.Url));
Stephen
  • 1,739
  • 2
  • 26
  • 36
  • 1
    I'm afraid that's an overly simplistic answer. I'm not going to run it, but the 'Playback.Initialize()' is required in order for the 'Launch' to not throw an exception when you run it in 'AssemblyInitialize'. – rythos42 Mar 01 '12 at 17:13