vsingh
vsingh

Reputation: 135

Unable to install chromedriver on docker machine using Webdrivermanager

I am using webdrivermanager plugin by Boni Garcia for driver installation. When I use it for execution on my local and everything working fine but I face issues when I try to do the same via Jenkins. Details below:

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

Now when I try to execute the same maven project via Jenkins, I am facing issue. My slave machine is a docker machine.

At first, I tried webdrivermanager to take care of the chrome driver installation and I got error stating that binary not found.

ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("start-maximized");
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(options);

Error:

org.openqa.selenium.WebDriverException: 
unknown error: cannot find Chrome binary
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 3.10.0-862.14.4.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)

Then I tried using driver from within the framework. I saved the chromedriver file in a drivers folder within my framework and then tried to execute it, but still got an error (different error this time though)

    ChromeOptions options = new ChromeOptions();
    options.addArguments("headless");
    options.addArguments("start-maximized");
    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver");
    driver = new ChromeDriver(options);

Error:

      Running TestSuite
/home/jenkins/workspace/Dental_EIEI_Angular/EIEI Test Jenkins/src/test/resources/drivers/chromedriver: /home/jenkins/workspace/Dental_EIEI_Angular/EIEI Test Jenkins/src/test/resources/drivers/chromedriver: cannot execute binary file
Apr 03, 2019 2:19:23 PM org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 126 (Exit value: 126)

Upvotes: 2

Views: 2797

Answers (1)

Nilamber Singh
Nilamber Singh

Reputation: 874

I was running into an issue which was something similar to what you are facing. The WebDriverException : unknown error: cannot find Chrome binary is because your framework is unable to find the chrome binary in jenkins. To set the binary using your code is not fissible because you should know the path of binary file. Instead of getting into that hassle, simply create a docker-compose.yml file to get your infra up and running to execute your tests.

version: "3"
services:
  selenium-hub: 
    image: selenium/hub
    container_name: selenium-hub
    ports: 
      - "4444:4444"
    environment:
      - GRID_BROWSER_TIMEOUT=30
  chrome:
    image: selenium/node-chrome
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
  firefox:
    image: selenium/node-firefox
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

then you can use docker-compose up -d to run your infra in detached mode. You also need to do some relevant changes in your code to access the selenium-hub server.

System.setProperty("webdriver.chrome.driver", "src//test//resources//driver//chromedriver");
                ChromeOptions cap = new ChromeOptions();
                cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
                webDriver = new RemoteWebDriver(new URL("http://"+serverIP+":4444/wd/hub"), cap);
                webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

where serverIP is localhost if you want to run the application in your local system or if you want to run it in jenkins then you need the IP address of the selenium-hub server which can be found by running docker inspect on jenkins

Upvotes: 2

Related Questions