selenium: For .net core nuget libs do not copy to bin folder
Error in FileUtilities in Selenium .net
For .net core nuget libs do not copy to bin folder. And WebDriver could not found chromedriver.exe
/// <summary>
/// Gets the directory of the currently executing assembly.
/// </summary>
/// <returns>The directory of the currently executing assembly.</returns>
public static string GetCurrentDirectory()
{
>>>> Assembly executingAssembly = typeof(FileUtilities).Assembly;
>>>> string location = Path.GetDirectoryName(executingAssembly.Location);
if (string.IsNullOrEmpty(location))
{
// If there is no location information from the executing
// assembly, we will bail by using the current directory.
// Note this is inaccurate, because the working directory
// may not actually be the directory of the current assembly,
// especially if the WebDriver assembly was embedded as a
// resource.
location = Directory.GetCurrentDirectory();
}
string currentDirectory = location;
// If we're shadow copying, get the directory from the codebase instead
if (AppDomain.CurrentDomain.ShadowCopyFiles)
{
Uri uri = new Uri(executingAssembly.CodeBase);
currentDirectory = Path.GetDirectoryName(uri.LocalPath);
}
return currentDirectory;
}
Workaround: <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (6 by maintainers)
chromedriver.exe is not a part of Selenium libs deployed to NuGet, it should be downloaded independently.
Ah, yes, there is a collision.
https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/Internal/FileUtilities.cs#L113-L115 reads
whereas https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/DriverService.cs#L270 and https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/DriverService.cs#L277 mention “the current directory” that implicitly reads as “the current working directory”.
Thank you for perseverance, reopening the issue.
I have the same issue, the workaround is simply to specify
.
fordriverPath
e.g.ChromeDriverService.CreateDefaultService(".")
.The
GetCurrentDirectory
function is poorly named since it does not get the current directory however I recognise that the current working directory != where the files are always. To me a better solution would be to look in these directories forchromedriver.exe
rather than assuming one directory must have the file based on shadow copy settings etc. Approximately:Personally I placed the
PATH
check right at the end because I assume it’s a feature to check the file system locations “closer” to the application than in thePATH
i.e. if I have an old version ofchromedriver.exe
in myPATH
but one copied to mybin
folder … please use thebin
folder one.Anyway, thank you for Selenium and maintaining the code and GitHub issues.