Joe Lloyd
Joe Lloyd

Reputation: 22323

Adding Chrome Selenium Driver to Ubuntu

Background

I have a series of selemium tests on bitbucket being run as a maven project. Jenkins runs my maven projects headlessly on my server. Selenium required an extra driver to be installed on the server for chrome tests to be run.

Problem

I have installed the chrome driver at the root of the jenkins folder on the server since the jenkins user is the one that runs the tests and only has access to these folders. When I run the test I get the following error

java.lang.IllegalStateException: 
The driver executable does not exist: 
/var/lib/jenkins/jobs/ChromeLogin01/workspace/~/chromedriver

The part of the path that is ~/chromedriver is in my selenium script. I didnt expect the path to include all of the stuff before and thought the ~ would bring me to the root of the Jenkins user.

What I've Tried

So I thought that ~/chromedriver would redirect correctly but it didnt. I also did && ~/chromedriver since that should reset the PATH to root. After a few variation of this it seems like it couldn't be done with a regular cd statement.

Question

How do I get my tests to find the chrome driver that I have installed on the server without having to install the driver into every test?

Upvotes: 0

Views: 1363

Answers (2)

r0101
r0101

Reputation: 405

You can replace ~ in your script with System.getProperty("user.home"), this would bring you to the root of the Jenkins user. Like this System.getProperty("user.home") + "/chromedriver"

Upvotes: 1

Nicolae Iorga
Nicolae Iorga

Reputation: 23

If you are using the Selenium standalone version, you could do this:

java -jar selenium-server-standalone-2.44.0.jar -role hub -hubConfig hubConfig.json -Dwebdriver.chrome.driver=chromedriver.exe

In the example above, the .jar file and the chromedriver.exe are in the same folder.

You could also try, from inside of your tests to set the location of the chromedriver like this:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

If the distance (Folder distance) from your executed test files to your chromedriver is constant like this:

chromedriver path = "/workspace/selenium/drivers/chromedriver" 
tests path = "/workspace/tests/test X" (where X is 1, 2... n)

Then the path to the chromedriver would be:

pathToChromeDriver = "{PathToTestX}/../../selenium/drivers/chromedriver"

Hope this helps.

Also, are you using the chromedriver specific for your OS?

Upvotes: 0

Related Questions