Selenium WebDriver.ChromeDriver Nuget 包已安装,但不适用于 MSTest

Selenium WebDriver.ChromeDriver Nuget package installed, but not working for MSTest(Selenium WebDriver.ChromeDriver Nuget 包已安装,但不适用于 MSTest)

本文介绍了Selenium WebDriver.ChromeDriver Nuget 包已安装,但不适用于 MSTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已添加 WebDriver.ChromeDriver nuget打包到我的解决方案中,其中包含 Selenium WebDriver 使用 Chrome 运行自动化测试所需的 ChromeDriver.exe 文件.查看包内容,它只包含以下文件:

I have added the WebDriver.ChromeDriver nuget package to my solution, which contains the ChromeDriver.exe file, required for Selenium WebDriver to run automated tests using Chrome. Looking at the package contents, it just contains the file following file:

toolschromedriver.exe

应该 要做的就是将此文件夹添加到 PATH 环境变量中,以便可以通过以下代码访问 chromedriver.exe(这是在 UnitTest 项目中)使用 MSTest):

What this is supposed to do is add this folder to the PATH environment variable so that chromedriver.exe is accessible via the following code (this is in a UnitTest project using MSTest):

[TestMethod]
public void LaunchWebsite_Chrome()
{
     // create ChromeDriver - this should work if chromedriver.exe 
     // is known to the environment PATH variable
     IWebDriver driver = new ChromeDriver();

     driver.Navigate().GoToUrl("http://localhost/");
}

但是,我仍然遇到以下异常:

However, I am still getting the following exception:

chromedriver.exe 文件不存在于当前目录或 PATH 环境变量的目录中.驱动程序可以在 http://code.google.com/p/chromium/downloads 下载/列表.

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://code.google.com/p/chromium/downloads/list.

查看 nuget 文档,它表明 nuget 包的 tools 文件夹中的任何内容都会自动添加到 PATH 环境变量中:

Looking at the nuget documentation, it suggests that anything in the tools folder of the nuget package will get added to the PATH environment variable automatically:

http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package:包的 tools 文件夹用于存放可从包管理器控制台访问的 powershell 脚本和程序.文件夹复制到目标项目后,添加到`$env:Path (PATH) 环境变量中.

http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package: The tools folder of a package is for powershell scripts and programs accessible from the Package Manager Console. After the folder is copied to the target project, it is added to the `$env:Path (PATH) environment variable.

但是,这似乎不起作用.我什至在命令行上运行了 echo %PATH%,但它没有显示我的工具文件夹已注册.

However, this doesn't seem to be working. I have even run echo %PATH% on the command line and it doesn't show my tools folder as registered.

我做错了什么?

推荐答案

我不会为此烦恼 NuGet 包,因为这不是一个类库 - 从技术上讲,这就是 NuGet 的全部意义所在.自该版本发布以来,ChromeDriver 也进行了多次更新.

I wouldn't bother with the NuGet package for this, simply because this is not a class library - which is technically, what NuGet is all about. ChromeDriver has also been updated many times since that release.

无论如何,我会说我刚刚做了同样的事情来看看问题是什么:

Anyway, I would say that I have just done the same thing to see what the issue is:

  1. 下载 NuGet 包
  2. 使用 Visual Studio,通过右键单击项目 -> 添加项目 -> 现有项目,将新项目添加到项目中
  3. 导航并选择 chromedriver.exe
  4. 更改属性以确保复制到输出目录"设置为始终复制.

您可能在第 4 点上落伍了.该设置默认设置为 不复制.

You are probably falling down on point 4. That setting is set to Do not copy by default.

这篇关于Selenium WebDriver.ChromeDriver Nuget 包已安装,但不适用于 MSTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Selenium WebDriver.ChromeDriver Nuget 包已安装,但不适用于 MSTest

基础教程推荐