Visual Studio 2015 and selenium: adding a chrome edge

VS never ceases to amaze me. Or rather, it never ceases to amaze me with how I either forget how to do something between every new solution I create, or how things change between solutions.

I am trying to use ChromeDriver with Selenium (in C #). I have installed the Selenium.Webdriver and Selenium.Chrome NuGet packages to a project and everything seems to be fine. No errors in usage directives and errors when trying to create a new ChromeDriver.

Here's the Selenium driver code:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Threading;

...

public class GCDriver {
    public static IWebDriver Instance { get; set; }

    public static void Initialize () {
        Instance = new ChromeDriver();
    }

    public static void Wait(TimeSpan timeSpan) {
        Thread.Sleep((int)(timeSpan.TotalSeconds * 1000));
    }

    public static void Close() {
        Instance.Quit();
    }
}

      

When trying to start (initialize) the ChromeDriver, as I always do, I get this error:

Test Name:  One
Test FullName:  MyTests.TestUnitTest1.One
Test Source:    C:\Users\149999frho\Source\Workspaces\QA\Automation\MyTests\TestUnitTest1.cs : line 17
Test Outcome:   Failed
Test Duration:  0:00:00,0118783

Result StackTrace:  
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String    executableName, Uri downloadUrl)
   at OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService()
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor()
   at Automation.GCDriver.Initialize() in C:\Users\149999frho\Source\Workspaces\QA\Automation\Automation\Selenium\GCDriver.cs:line 16
   at MyTests.TestUnitTest1.Init() in C:\Users\149999frho\Source\Workspaces\QA\Automation\MyTests\TestUnitTest1.cs:line 12
Result Message: Initialization method MyTests.TestUnitTest1.Init threw    exception. OpenQA.Selenium.DriverServiceNotFoundException:    OpenQA.Selenium.DriverServiceNotFoundException: 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://chromedriver.storage.googleapis.com/index.html..

      

The fact is that chromedriver.exe IS is located in the Solution \ Project \ Automation \ bin \ Debug folder. As it should be since the NuGet package is installed.

What am I missing here? Should I add any other links after installing the NuGet package? Adding the chromedriver.exe file as a reference is not possible, btw - VS complains that it is not actual COM code or something.

The links seem to be okay - and the links folder looks EXACTLY the same as in the other solution that works:

enter image description here

UPDATE: I found a workaround: adding the path to the chromedriver.exe file when creating a new instance of ChromeDriver. Instance = new ChromeDriver (). However, this is an idiotic and useless solution as I have to use an absolute path - VS does not accept a relative one. If you share a project, you will not be able to manage it.

So the problem is that the project doesn't know where the file is, installed by its own NuGet package manager. Argh! How is this possible with a piece of software in this price range ?!

+3


source to share





All Articles