I’ve encountered this precise situation that you’re going through and from my observations I can counsel 3 doable options:
1. ThreadStatic driver – it is the only option to have a novel driver occasion per TestMethod. The precise worth of the motive force is linked to the thread your check is operating on. Simply keep in mind to make use of [TearDown]
to shut the motive force occasion after the check is completed.
NOTE: Every [TestMethod]
inside a [TestFixture]
has its personal TestContext and runs on it is personal thread when utilizing parallelization. This context is created in the course of the [SetUp]
technique and persists till [TearDown]
.
2. A number of lessons in the identical file – you’ll be able to place a number of lessons marked as [TestFixture]
in the identical file and below the identical Namespace. They’ll prolong a base check class and have their very own distinctive driver. The disadvantage is that you’ll have to handle every lessons’ driver individually.
3. Instantiate your driver inside your Web page Objects – this answer entails having one PageObject class (if you’re aware of the Web page-Object sample) which initializes your driver after which injects it into different PageObject lessons.
For instance: say you’ve gotten a HomePage class. This class has a Driver property and whenever you invoke one thing like HomePage.GoTo()
or .OpenBrowser()
this Driver property will get a price assigned, relying in your configurations or any parameters chances are you’ll need to give the strategy. Then whenever you navigate out of your HomePage to a different web page, say “SettingsPage” you’ll be able to have a way referred to as HomePage.GoToSettingsPage()
which returns a new SettingsPage(myDriver)
and passes it your driver by the constructor. After all, this can restrict your capability to create new PageObjects at any level in your check aside from the primary one. Each time you navigate from one PageObject to a different you will want to go the motive force.
The principle concept is to uncouple your driver occasion from the check class.
There is likely to be different methods, however I hope my strategies helped.