I am using xUnit, SpecFlow, Selenium and headless Chrome to run automated tests, but every so often I will get a series of crashes when running on localhost
when tr
As discussed the issue could be because of multiple reasons
svc.Port = Randomiser.Next(29700, 29900);
. You should never assign the port yourself, it can be conflicting with some other program port as well and even the same port number can be generated in random which will cause the issue
You are launching scripts in parallel. In rare cases there could be a race condition in driver launch and the driver may fail to launch. So I would add Factory pattern to my driver initialization code like below
public sealed class ChromeFactory
{
private static readonly object padlock = new object();
ChromeFactory()
{
}
public static WebDriver NewInstance
{
get
{
lock (padlock)
{
return new ChromeDriver();
}
}
}
}
And initialize the driver like below
Context.Driver = ChromeFactory.NewInstance