java.lang.IllegalStateException:驱动程序可执行文件不存在:/var/lib/jenkins/jobs/Ancon-Automation/workspace\src\main\...\chromedriver.exe

时间:2018-08-17 06:09:39

标签: java selenium jenkins selenium-webdriver webdriver

点击构建时,我在 Jenkins控制台中遇到以下错误。但是,在我的intelij IDE中运行测试时,它会毫无故障地运行。是詹金斯(Jenkins)还是chromedriver.exe的路径出现此问题

[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
[ERROR] Tests run: 38, Failures: 1, Errors: 0, Skipped: 37, Time elapsed: 2.237 s <<< FAILURE! - in TestSuite
[ERROR] SetUp(com.ancon.automation.tests.TenantsTest)  Time elapsed: 1.593 s  **<<< FAILURE!
java.lang.IllegalStateException: The driver executable does not exist: /var/lib/jenkins/jobs/Ancon-Automation/workspace\src\main\java\com\ancon\automation\webDriver\chromedriver.exe**
    at com.ancon.automation.tests.TenantsTest.SetUp(TenantsTest.java:62)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   TenantsTest.SetUp:62 » IllegalState The driver executable does not exist: /var...
[INFO] 
[ERROR] Tests run: 16, Failures: 1, Errors: 0, Skipped: 15
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.616 s
[INFO] Finished at: 2018-08-17T09:56:58+05:30
[INFO] ------------------------------------------------------------------------
**[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project Ancon: There are test failures.
[ERROR]** 
[ERROR] Please refer to /var/lib/jenkins/jobs/Ancon-Automation/workspace/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Build step 'Invoke top-level Maven targets' marked build as failure

注意:我发现了类似的问题,但找不到正确的答案。

3 个答案:

答案 0 :(得分:1)

此错误消息...

java.lang.IllegalStateException: The driver executable does not exist: /var/lib/jenkins/jobs/Ancon-Automation/workspace\src\main\java\com\ancon\automation\webDriver\chromedriver.exe

...表示 JVM 无法在指定位置找到 ChromeDriver 二进制文件。

您的主要问题似乎是在 ChromeDriver 的有效绝对路径内的 OS path.separator 组合 。当前,已解析的有效绝对路径为:

/var/lib/jenkins/jobs/Ancon-Automation/workspace\src\main\java\com\ancon\automation\webDriver\chromedriver.exe

您需要使用 / 字符作为 path.separator ,因此您 ChromeDriver 的有效绝对路径变为:

  • Linux样式(将.exe部分剥离):

    /var/lib/jenkins/jobs/Ancon-Automation/workspace/src/main/java/com/ancon/automation/webDriver/chromedriver
    
  • Windows样式(包括.exe部分)

    /var/lib/jenkins/jobs/Ancon-Automation/workspace/src/main/java/com/ancon/automation/webDriver/chromedriver.exe
    

答案 1 :(得分:0)

请在代码中使用相对路径,如下所示设置驱动程序属性

System.setProperty("webdriver.chrome.driver", "src/main/java/com/ancon/automation/webDriver/chromedriver.exe");

答案 2 :(得分:0)

通过路径,看起来您正在Linux机器上运行测试,或者至少代码期望您在Linux机器上可执行文件。

由于它是use .exe extension on a linux box的愚蠢错误,因此您应该忽略这一点。另外,您只应在代码中处理此类情况,因为这会导致跨OS执行中令人沮丧的问题。

希望它在removing .exe part之后生效。