Selenium C#Mstest-chromedriver.exe不存在. GetDirectory()在执行vis mstest命令时引用其他目录 [英] Selenium C# Mstest - chromedriver.exe does not exist. Getdirectory() referring some-other directory while executing vis mstest commands

查看:151
本文介绍了Selenium C#Mstest-chromedriver.exe不存在. GetDirectory()在执行vis mstest命令时引用其他目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从VS2017运行硒测试时,当我使用mstest命令运行相同的测试时,它能够成功选择驱动程序-但在内部它是在引用其他目录!

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命令

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:该文件 C:\ Test \ xsed_2018-12-07 10_55_51 \ Out \ chromedriver.exe不存在. 该驱动程序可以在以下位置下载 http://chromedriver.storage.googleapis.com/index.html .. >

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.

代码:

this.DriversPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory()));

其他信息:

驱动程序在debug文件夹中可用,为什么我的mstest引用" Out "文件夹中的驱动程序??

drivers are available in debug folder why my mstest is referring the drivers in "Out" folder ??

推荐答案

该帖子有些陈旧,但是由于它被带到最前面,所以可能会对某人有所帮助.

This post is a bit old but since it was brought back to the the front, this may help someone.

  1. 我将下载ChromeDriver Nuget软件包.这样,您始终可以获得最新版本.

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

设置条件编译符号= _PUBLISH_CHROMEDRIVER

set Conditional compilation symbols = _PUBLISH_CHROMEDRIVER

安装后,请清洁解决方案并重新生成,您应该在bin目录中看到该文件.

Once installed, clean solution and rebuild and you should see the file in the bin dir.

您的chromedriver调用看起来应该像这样:

for your chromedriver call it should look something like this:

Driver = new ChromeDriver(Path.Combine(GetBasePath, @"bin\debug"), options);

然后添加GetBasePath代码:

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;
        }
    }

这篇关于Selenium C#Mstest-chromedriver.exe不存在. GetDirectory()在执行vis mstest命令时引用其他目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆