Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I instantiate a new ChromeDriver using a relative path in C#?

It works using an absolute path like:

WebDriver = new ChromeDriver(@"C:\Users\<my user>\Documents\<my project>\WebDrivers\Chrome\");

But since I run my tests on a TFS build server too, I need it to be a relative path.

like image 376
Aaron Avatar asked Jan 10 '23 22:01

Aaron


1 Answers

Add the drivers into your solution and in the properties window, define that you want to copy the files to the output directory.

File Properties

In the picture above, the drivers are in the resources directory:

/my solution
   /resources
     /chromedriver.exe
     /IEDriverServer.exe

After a build, they will be copied to:

/bin
   /debug
      /resources
        /chromedriver.exe
        /IEDriverServer.exe

When you are creating your driver, you can define the path to the driver now relative in the bin directory.

return new ChromeDriver("resources");
like image 111
Simon Lang Avatar answered Jan 23 '23 02:01

Simon Lang