问题
when i'm running the selenium test from VS2017 it is able to pick the drivers successfully BUT when i run the same test using mstest command - internally it is referring some other directory!
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\mstest.exe/ testcontainer:..\Test\Sun.TestAutomation.dll /test:"myfristtest" /resultsfile:..\Test\TestResultLog.trx //Mstest commands
OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The file C:\Test\xsed_2018-12-07 10_55_51\Out\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html.
code:
this.DriversPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory()));
additional information:
drivers are available in debug folder why my mstest is referring the drivers in "Out" folder ??
回答1:
This post is a bit old but since it was brought back to the the front, this may help someone.
I would download the ChromeDriver Nuget package. This way you always get the latest version.
Right click on your project > properties. Click on Build tab.
set Conditional compilation symbols = _PUBLISH_CHROMEDRIVER
- under output path set: bin\Debug\
Once installed, clean solution and rebuild and you should see the file in the bin dir.
for your chromedriver call it should look something like this:
Driver = new ChromeDriver(Path.Combine(GetBasePath, @"bin\debug"), options);
Then add the GetBasePath code:
public static string GetBasePath
{
get
{
var basePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
basePath = basePath?.Substring(0, basePath.Length - 10);
return basePath;
}
}
回答2:
This PC -> Properties -> advanced system settings -> Environment variables -> system variables -> Varible PATH add folder, where you have chromedriver.exe
来源:https://stackoverflow.com/questions/53668341/selenium-c-sharp-mstest-chromedriver-exe-does-not-exist-getdirectory-referr