简体   繁体   English

当我尝试通过 Jenkins 在 Linux 服务器中运行我的项目时,出现“java.lang.IllegalStateException: The driver is not executable”

[英]"java.lang.IllegalStateException: The driver is not executable" when I try to run my project in Linux server through Jenkins

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.我的项目 (Java-Selenium-Maven-Cucumber) 在我的设备 (Windows 10) 上运行,但我无法通过 Jenkins 在 Linux 服务器中启动 chrome 驱动程序。

I added chromedriver for Linux 64 to my framework.我将 Linux 64 的 chromedriver 添加到我的框架中。

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;如果我像下面的代码一样将“ chmod +x /home/jenkins/workspace/Website-Automation/chromedriver ”添加到 Jenkins ,这次我会得到另一个错误; org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. org.openqa.selenium.WebDriverException:等待驱动程序服务器启动超时。

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

This is happening because chromedriver does not have executable permissions.发生这种情况是因为 chromedriver 没有可执行权限。 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.由于您正在运行 Jenkins 中的测试,因此您需要在测试之前运行此命令。

Something like this:是这样的:

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

In your case I noticed that you are using WebDriverManager.在您的情况下,我注意到您正在使用 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:如果您已经配置了 Jenkins 作业,您需要做的唯一更改是删除您手动设置驱动程序路径的行并取消注释上一行:

  WebDriverManager.chromedriver().setup();

If this does work, may be you need to update WebDriverManager version in the pom file.如果这确实有效,您可能需要更新 pom 文件中的 WebDriverManager 版本。

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;

Before check your system.dir location;在检查您的 system.dir 位置之前;

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

Then check if there is a webdriver under this location.然后检查这个位置下有没有webdriver。

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.注意:Chrome浏览器的版本和chrome驱动的版本必须一致。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试运行我的代码时,我得到“ java.lang.Exception:java.lang.IllegalStateException” - I am getting “java.lang.Exception: java.lang.IllegalStateException” when i try to run my code java.lang.IllegalStateException: 驱动程序可执行文件不存在 chrome 驱动程序 - java.lang.IllegalStateException: The driver executable does not exist chrome driver 当我尝试在库项目中使用getSystemService时获取java.lang.IllegalStateException - Getting java.lang.IllegalStateException when I try to use getSystemService in library project 当我尝试通过ID查找GridLayout时出现java.lang.IllegalStateException - java.lang.IllegalStateException when I try to find GridLayout by id java.lang.IllegalStateException:驱动程序不可执行:/resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs - java.lang.IllegalStateException: The driver is not executable: /resources/phantomjs-2.1.1-linux-x86_64/bin/phantomjs java.lang.IllegalStateException:驱动程序可执行文件不存在:尝试通过Selenium,ChromeDriver和Chrome执行测试时 - java.lang.IllegalStateException: The driver executable does not exist: while trying to execute tests through Selenium, ChromeDriver and Chrome 线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件是一个目录 - Exception in thread “main” java.lang.IllegalStateException: The driver executable is a directory java.lang.IllegalStateException:驱动程序可执行文件不存在 - java.lang.IllegalStateException: The driver executable does not exist java.lang.IllegalStateException:Current user principal is not of type when i try to integrate keycloak with spring boot web + spring security project - java.lang.IllegalStateException:Current user principal is not of type when i try to integrate keycloak with spring boot web + spring security project java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException: The path to the driver executable must be set with Selenium and Java - java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException: The path to the driver executable must be set with Selenium and Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM