How do I keep the browser open after a coded ui test finishes?

前端 未结 3 772
庸人自扰
庸人自扰 2021-01-21 01:32

I\'m using Visual Studio 2012 Coded UI tests for a web application. I have a test for logging into the app which starts the browser, locates the login dialogue, enters credenti

3条回答
  •  萌比男神i
    2021-01-21 02:02

    I have found the following method to work for my data driven coded UI test in Visual Studio 2015.

    You will want to use [ClassInitialize] and get your browser open and direct it according to where your [TestMethod] begins.

    Use [ClassCleanup] to release the resources after all the methods in the test class have been executed.

    You can redirect test methods different after the class has been initialized by using the [TestInitialize] and clean-up test using the [TestCleanup]. Be careful with those though because they will occur for each test method and if it closes your browser instance your following test will fail.

    private static BrowserWindow browserWindow = null;
    
    [ClassInitialize]
    public static void ClassInitialize(TestContext context)
    {
        Playback.Initialize();
        browserWindow = BrowserWindow.Launch(new Uri("http://198.238.204.79/"));          
    }
    
    [ClassCleanup]
    public static void TestCleanup()
    {
        browserWindow.Close();
        Playback.Cleanup();
    }
    

提交回复
热议问题