0

I am using Java 1.8 and Selenium 2.53.0. I have taken these and created a lib/jar using maven that handles driver instantiation. In that lib I also packaged the ChromeDriver.exe in the assets folder.

In my other project I have called that lib as a dependency and I'm using the AutomationDriver object from inside my lib. In the lib it automatically instantiates any driver I call for with the settings I've already specified. However, it's a special case with ChromeDriver.exe because it needs to have

System.setProperty("webdriver.chrome.driver", "./path/to/chromedriver");

set to reference the path. I was using relative paths in my project before and it worked fine, but now that I have it as a lib I can't seem to figure out the relative path that would reach the asset within the lib so that it will work on every machine without having to download/route to another ChromeDriver.

  • How is the relative path to an asset within a lib/jar handled?
  • How can I set my system property to use that asset?
  • Is there a way that it can query it's own path to it automatically and use that?
demongolem
  • 9,474
  • 36
  • 90
  • 105
James
  • 36
  • 5
  • Possible duplicate of [Get a resource using getResource()](http://stackoverflow.com/questions/2593154/get-a-resource-using-getresource) – SiKing Jun 08 '16 at 20:13
  • You dont need to store the driver in the .jar if you use the GitHub project called `webdrivermanager` . – djangofan Jun 08 '16 at 20:17

1 Answers1

2

Instead of handling manually the chromedriver binary, you can use the library WebDriverManager. If you are using Maven, you can add it as a dependency as follows:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.0.1</version>
</dependency>

Then simply call to this line in your code:

WebDriverManager.chromedriver().setup();

The library automatically downloads the proper chromedriver binary for you, setting up to be used in your Selenium WebDriver code.

Boni García
  • 4,618
  • 5
  • 28
  • 44