Search code examples
asp.netunit-testingseleniumselenium-webdrivervs-unit-testing-framework

Run Selenium tests with same user session


We are running a number of Selenium tests on our site (ASP.NET MVC), and on TestInitialize we start the web driver, and on TestCleanup we close and quit. This means that for each test we need to perform the login procedure, even though running a large number of tests could be run with the same logged in session in the browser.

Somehow we want the test to see if there is an open session in the browser, and use it, and if not, perform the log in. Is that even possible?


Solution

  • Move your code to start the web driver and login code into an AssemblyInitialize method which will start the browser and login once per test assembly.

    https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assemblyinitializeattribute.aspx