Search code examples
javalinuxseleniumfirefoxgeckodriver

Running Selenium Tests on Linux using GeckoDriver: driver is not executable


I am currently working on a test automation project using Selenium WebDriver on a Linux machine. (Ubuntu 16.04.3) Tests can be executed without any errors on a Windows machine, since I am trying to run the tests on a Linux VM I encountered critical issues while initializing the GeckoDriver.

Here is part of my code:

System.setProperty("webdriver.gecko.driver", _GECKO_DRIVER);
WebDriver driver = new FirefoxDriver();

The variable _GECKO_DRIVER is the file path to a linux executable, I downloaded from this mirror: https://github.com/mozilla/geckodriver/releases (inside tar.gz folder)

Unfortunately JAVA is not able to initialize the driver, so tests can not be run and it results in following error:

Exception in thread "main" java.lang.IllegalStateException: 
The driver is not executable: path/to/repo/./src/main/resources/Driver/GeckoDriver/geckodriver
at com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:140)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)

How can I fix this issue and initialize the driver correctly?


Solution

  • From your exception:

    driver is not executable: 
    

    Make it executable

    chmod +x geckodriver
    

    And retry.