I am trying to parallelize my Selenium tests. I discovered that Selenium's IWebDriver is not thread safe. I don't know if there are serious dangers to not having thread safe tests, but I'd like to try to account for any "bad practices" in any case. In my code, I am using the following design.
public abstract class Parent
{
public IWebDriver driver;
public Parent(IWebDriver driver) { this.driver = driver; }
public bool ElementExists(By by) {
if (this.driver.FindElement(by) != null)
return true;
return false;
}
}
public class Child1 : Parent
{
public Child1(IWebDriver driver) : base(driver) { }
}
public class Child2 : Parent
{
public Child2(IWebDriver driver) : base(driver) { }
}
Is this code thread safe?
To my understanding, since I am passing in a IWebDriver instance to the constructor, I need not worry about the child classes erroneously using the same IWebDriver. However, just from looking at examples of non-thread safe code, having the IWebDriver field in the abstract Parent class is a concern.