Reputation: 5408
I've converted an NUnit test project from .NET Framework to .NET Core. When I try to execute a Selenium test using Visual Studio, I am seeing this error:
OpenQA.Selenium.DriverServiceNotFoundException : The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html.
I've included the Selenium.WebDriver.ChromeDriver
Nuget Package and chromedriver.exe
appears in the output bin folder. Without having to set the ChromeDriver url as an environment variable, how do I get Visual Studio to find the file?
[Test]
public void Test()
{
var driver = new ChromeDriver();
driver.Url = "http://www.google.com";
}
Upvotes: 4
Views: 3544
Reputation: 629
This happens because in .Net Core the NuGet packages are loaded from a global location instead of the packages folder in .NET Framework projects.
You can use the following and it will run correctly:
ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
Upvotes: 4
Reputation: 41
This works for me
var currentDirectory = Directory.GetCurrentDirectory();
var driverService = ChromeDriverService.CreateDefaultService(currentDirectory);
driverService.Start();
var driver = new ChromeDriver(driverService);
Upvotes: 1
Reputation: 178
What i did when i had the problem was to set a var:
var driverDirectory = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
And just pass it to ChromeDriver on creation.
Upvotes: 0