首页 > 解决方案 > 如何在 Jenkins 工作中使用 Selenium WebDriver?

问题描述

我编写了一些使用 Selenium 和 Chrome 版本 76.0.3809.68 的 WebDriver 的 JUnit 测试。当我使用 mvn clean install 执行 maven 模块时,一切正常,但是当我尝试在 Jenkins 作业中运行它时,出现以下错误:

The driver is not executable: /jenkins/workspace/webUI.ITests/target/test-classes/calculator/chromedriverunix

现在我已经尝试对 chromedriver.exe 文件做同样的事情,但我得到了同样的错误。这两个驱动程序都来自 selenium 网站,应该是正确的。这是我设置驱动程序的代码:

if (System.getenv("ON_JENKINS") == null) {
            URL res = this.getClass().getResource("chromedriverunix");
            File file = Paths.get(res.toURI()).toFile();
            return file.getAbsolutePath();
        } else {
            URL res = this.getClass().getResource("chromedriver.exe");
            File file = Paths.get(res.toURI()).toFile();
            return file.getAbsolutePath();
        }

这两个文件肯定都存在于构建中。先感谢您!

标签: seleniumjenkinsselenium-chromedriver

解决方案


这似乎与 Unix 上的权限有关。您可以通过执行chmod 777 chromedriverunixchmod +x chromedriverunix在chromedriver所在的文件夹中更改它。


推荐阅读