Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

c# - Selenium WebDriver.ChromeDriver Nuget package installed, but not working for MSTest

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

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:

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.

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

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.

What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. Download NuGet package
  2. Using Visual Studio, add a new item to the project by right-clicking on the project -> Add Item -> Existing Item
  3. Navigate and select the chromedriver.exe
  4. Change the properties to ensure "Copy to Output Directory" is set to Copy always.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...