I developed a series of unit tests in Visual Studio 2019, C# Selenium. How can run back to back with one browser instance? For example, the first test is going through a series of steps and creates a unique string e.g. id = "Id1Aug2020" I want the browser stays open for the second test, run the second test using the id created in the first test. the tests I have now, Test1 creates the id close browser and Test2 open a new browser do something else using a random id (not good), instead of the Id was created in Test1 and close the browser, and so forth.... how can I achieve this, any suggestions?
-
You have control over the browser instance, most probably you are shutting it down on your test hooks. Can you share your code? Additionally, you probably can keep the generated string in an instance variable of your test class (or equivalent) between tests, if this would yield a better design in your context.– João FariasCommented Aug 30, 2020 at 16:46
Add a comment
|
1 Answer
While I don't recommend this approach as it does not conform to F.I.R.S.T. (Fast, Isolated/Independent, Repeatable, Self-validating, Thorough) you can accomplish a reusable session by not tearing down after each test. It differs slightly depending on the Test Runner you are using MSTest/VSTest, NUnit, XUnit but are largely the same.
For NUnit you would use [OneTimeSetup]
to start the browser rather than [Setup]
.