I've a C# automation Solution and I have 2 project in it:
Project A contains a BaseTest
class which creates a driver using DriverManager
,
and a test class ProjectATest
that derives from BaseTest
class.
Project B contains a test class ProjectBTest
which also derives from BaseTest
class.
My Chrome version is 113 while the newest version is 114. when executing the Project A's test DriverManager creates a driver v113 as expected. But when executing Project B's test, it creates a driver v114 which causes test failure.
Exception Message:
OneTimeSetUp: System.InvalidOperationException : session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 113.0.5672.129 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe (SessionNotCreated)
BaseTest
class: (driver creation)
namespace Project_A
{
public class BaseTest
{
protected IWebDriver driver;
[OneTimeSetUp]
public void Setup()
{
new DriverManager().SetUpDriver(new ChromeConfig());
driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://stackoverflow.com/");
}
}
}
ProjectATest
class:
namespace Project_A
{
internal class ProjectATest : BaseTest
{
[Test]
public void TestA() => Assert.Pass();
}
}
ProjectBTest
class:
namespace Project_B
{
internal class ProjectBTest : BaseTest
{
[Test]
public void TestB() => Assert.Pass();
}
}
I have tried to use Firefox but then everything works just fine.
I've found a solution,
According to the DriverManager
docs:
You can specify to automatically download a driver matching the version of the browser that is installed in your machine (only for Chrome, Edge, Firefox and Internet Explorer):
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
This solved the problem, but still didn't found an answer to the different behavior between these two projects,
and why it fails in Project B
.