Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98800

Parallelizing Selenium tests and being thread safe

$
0
0

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.


Viewing all articles
Browse latest Browse all 98800


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>