I would like to create a set(more than two) of Selenium C# [TestClass] which are structured in a way that would run on a single WebDriver object.

Is it possible to possible to have an object lifetime extend to multiple classes in different namespace?

For an example when a login tests is done, search test should see that webdriver has already opened chrome browser and has logged it.

2 Answers 2


Yes, you can do this.

One way would be as follows:

  • create a base test class from which your actual test classes inherit
  • create a protected WebDriver variable in this class (so your inherited tests can use it)
  • in the base class's TestInitialize method, create a new object if the variable is null, otherwise don't do anything.

That way, only the first test in any given run will create the WebDriver object.


Yes you can easily, however I strongly do not recommend it. It sounds like you want one test case to perform an action, and another test case to resume where it left off. I do not recommend this.

In my opinion, test cases that assume location are fine when it comes to manually testing but once you get into un-ordered automation, test cases can be called and its navigation could be left off in random location. In our case, our site is extreamly dynamic so it may apply more to myself, but I strongly believe that since the purpose of automation is to save time and build consistent tests, there is no reason not to start from the beginning at every test case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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