简体   繁体   中英

JAVA: 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?

From your exception:

driver is not executable: 

Make it executable

chmod +x geckodriver

And retry.

I faced the same issue when executing my tests using Java+Eclipse. I have added geckodriver under by project workspace, to make it simple just right-click the geckodriver in eclipse and check all the checkboxes under the Execute column (in properties window). This will make the geckodriver executable (otherwords you allow executable access to it)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM