Home > OS >  "java.lang.IllegalStateException: The driver is not executable" when I try to run my proje
"java.lang.IllegalStateException: The driver is not executable" when I try to run my proje

Time:11-25

My project (Java-Selenium-Maven-Cucumber) works on my device (Windows 10), but I'm unable to launch chrome driver in Linux server through Jenkins.

I added chromedriver for Linux 64 to my framework.

This is my code:

private static WebDriver driver;

    public static WebDriver get() {
        if (driver == null) {
            String browser = ConfigurationReader.get("browser");
            switch (browser.toLowerCase()) {
                case "chrome":
                    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") "/chromedriver" );
                    driver = new ChromeDriver();
                    break;

This is the error;

java.lang.IllegalStateException: The driver is not executable: /home/jenkins/workspace/Website-Automation/chromedriver
    at com.google.common.base.Preconditions.checkState(Preconditions.java:585)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:150)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:141)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at utilities.Driver.get(Driver.java:35)
    at step_definitions.Hooks.setUp(Hooks.java:22)

If I add "chmod x /home/jenkins/workspace/Website-Automation/chromedriver" to Jenkins like the below code, I get another error for this time; org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.

stage('Build') {
            steps {
                    sh '''
                    chmod  x /home/jenkins/workspace/Website-Automation/chromedriver
                    mvn test'''
            }
        }

CodePudding user response:

This is happening because chromedriver does not have executable permissions. You can give it executable permissions like this:

chmod  x /home/jenkins/workspace/Website-Automation/chromedriver

Since you are running the tests in Jenkins, you need to run this command before the tests.

Something like this:

chmod  x /home/jenkins/workspace/Website-Automation/chromedriver
mvn clean test

In your case I noticed that you are using WebDriverManager. If you have Jenkins job already configured the only change you need to do is remove the line where you manually set the driver path and uncomment the previous line:

  WebDriverManager.chromedriver().setup();

If this does work, may be you need to update WebDriverManager version in the pom file.

Current version:

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

Your code should be like:

public static WebDriver get() {
        if (driver == null) {
            String browser = ConfigurationReader.get("browser");
            switch (browser.toLowerCase()) {
                case "chrome":
                    WebDriverManager.chromedriver().setup();
                    driver = new ChromeDriver();
                    break;

CodePudding user response:

Before check your system.dir location ;

System.out.println(System.getProperty("user.dir"));

Then check if there is a webdriver under this location.

I have

 System.setProperty("webdriver.edge.driver", "C:\\Users\\user\\Desktop\\msedgedriver.exe")

It's working.

Note : The version of the Chrome browser and the version of the chrome driver must be the same.

  • Related