Selenium C# Mstest - chromedriver.exe does not exist. Getdirectory() referring some-other directory while executing vis mstest commands

北城余情 提交于 2019-12-04 06:39:13

问题


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.

  1. I would download the ChromeDriver Nuget package. This way you always get the latest version.

  2. Right click on your project > properties. Click on Build tab.

  3. set Conditional compilation symbols = _PUBLISH_CHROMEDRIVER

  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!