[英]"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.