Since you're using visual studio, just add the geckodriver.exe file to the solution, and from right-click -> properties, choose to "Copy always" the file to your output (when building the solution and run tests, this file will always exists with your compiled DLL).
After that, also deploy your file with the class attribute (add this above your BaseTest class, or [TestInitialize] like so:
[DeploymentItem("@*folder*\geckodriver.exe", "Drivers")]
[TestInitialize]
public void InitializeTest() {...}
OR
[DeploymentItem("@*folder*\geckodriver.exe", "Drivers")]
public class BaseTest {...}
Now that your driver executable gets deployed each time you run a test, you can find it here: AppDomain.CurrentDomain.BaseDirectory
in the folder Drivers
.
Then, just initialize your Driver like this using the constructor public FirefoxDriver(string geckoDriverDirectory);
(You combine the base folder of your compile (either debug or run (they have different folders), with the folder the driver is in "Drivers" and search the geckodriver.exe in it.)
public FirefoxDriver(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Drivers"));
Note: The solution above is for when you're using selenium on unit testing
. If you can't find the attribute DeploymentItem, the just use a static location for your driver (e.g.) "C:/" and call the contruction: public FirefoxDriver("C:/geckodriver.exe");