I am doing UI tests. At first I started with Firefox Browser driver only so I would declare the WebDriverWait variable under the class and would assign it under the [SetUp] method as shown in the code block and every test would be able to use it.
public class FirefoxTest {
public IWebDriver _driver;
public WebDriverWait _wait;
[SetUp]
public void SetupTest() {
_driver = new FirefoxDriver();
_wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
}
Then I tried to incorporate more BrowserDrivers by specifying them with the [TestCaseSource(typeof(WebDriverFactory), "Drivers")] attribute. So now the _driver variable have to be moved out of the [SetUp] and _wait variable doesn't know what _driver to use.
I tried to instantiate it in every Test but that was repetitive and those test used methods that also require WebDriverWait variable and those methods would not run a second time when another test tries to implement them because the WebDriverWait variable would already be declared.
My question is where can I instantiate WebDriverWait and other things that are driver dependent and that are usually written in [SetUp] and [TearDown] such as driver.Quit() when the driver are given as [TestCase].
Right now I have test written like
[TestCaseSource(typeof(WebDriverFactory), "Drivers")]
public void SomeTest(IWebDriver driver){
driver.Navigate().GoTo....
}
The problem is that I then have to include
WebDriverWait _wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
driver.Quit()
in all the tests and the _wait in all the methods that are reused in the tests. Things that I had in the [SetUp] and [Teardown].