2

Good Afternoon All,

I am creating a testing framework for a web app utilizing Selenium Web Driver and Visual Studio by way of C#. I have created a solution that includes two projects.

The first project is the the test framework which includes the Selenium Web Driver by way of NuGet and the Selenium Support file as well.

The second project included in the solution is the series of tests that will be run against the framework.

I am doing this this way to create an abstraction layer between the tests and the web driver. I have included a reference to the test framework in the second project to ensure that I can access the framework from the tests.

My issue is that whenever I try to run my tests (the second project) I receive an error stating that "OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. I can resolve this issue by placing the geckodriver.exe file in the bin for this project however this defeats the entire purpose of having two projects. I am using this two project model to keep all traces of selenium out of my tests and only have my framework interact with it.

It was my understanding that as my framework is the only place selenium commands are actually being fired off only my framework needed the drivers in its bin folder? Can someone confirm or deny this?

2 Answers 2

1

When your solution searches for the driver, it is looking in the bin path of whichever project is triggering it. Sadly, this means that your second solution will require the binary.

There are other ways, you can use a configuration to tell it where to look for the binary.

Chrome and Internet Explorer:

var driver = new ChromeDriver(pathToBinary);Source

var driver = new InternetExplorerDriver(pathToBinary);Source

Firefox:

var driverService = FirefoxDriverService.CreateDefaultService(pathToBinary);Source

driver = new FirefoxDriver(driverService);Source

I'd personally use a configuration file for the path

ConfigurationManager.AppSettings[binaryPath]

And then I use a tag in the test case to tell it what Binary to pull from the Config file.

[TestFixture(typeof(FirefoxDriver), "FirefoxPath")]

2
  • Thank you very much for this answer. I bit the bullet last night and included the IE, Gecko, and Chrome drivers in my test projects bin folder. I'll just have to settle for only including the WebDriver file in the framework bin as my abstraction. Commented Oct 26, 2016 at 20:30
  • 1
    Well as I said you can include them all in a config with their path or, for simplicity's sake (And likely a better long term answer) use Selenium Grid.
    – Paul Muir
    Commented Oct 27, 2016 at 12:19
0

A better solution is to use a Dynamic Path like this

new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

you will have to use the following:

using System.IO;
using System.Reflection;

but this will find the assembly in the Binary file for the Chrome Browser and you don't have to hard code the location.

2
  • 1
    Thank you so much Dynamic path worked for me. Commented Jun 27, 2019 at 13:26
  • @hemantgandhi please feel free to upvote my answer if it helped you
    – Malachi
    Commented Jun 27, 2019 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.