硒、Java、Maven、PhantomJS + TeamCity

Selenium, Java, Maven, PhantomJS + TeamCity

我在 Selenium/Java 有一个项目,通常 运行 在 chromedriver.exe 进行测试(我在 Windows 上工作)- 完全没有问题。

我最近决定将 运行 在 Linux 上的项目添加到我们的 TeamCity 中,因为它不能 运行 在浏览器上测试,我想切换到 PhantomJS 驱动程序.

我已经尝试了我在网上找到的所有解决方案的多种变体,但仍然无法正常工作。 目前我的资源中有 phantomjs 二进制文件,我在枚举 class:

中得到这样的驱动程序
PHANTOMJS {
    @Override
    public WebDriver initNewDriver() {
        System.setProperty("phantomjs.binary.path", ClassLoader.getSystemResource(RELATIVE_PATH_TO_FILE_IN_RESOURCES).getFile());
        return new PhantomJSDriver();
    }

然后在测试中 class 我从 driver.get(SOME_URL) 开始——这是它得到的最远的。

无论我做什么,当我尝试通过 'clean test' 在 TeamCity 上 运行 它时,我得到如下信息:

[userLoginTest] java.lang.IllegalStateException: The driver executable does not exist: /opt/buildAgent1/work/c4641c7cfd3331f7/web/drivers/phantomjslinux/phantomjs [14:41:41] [userLoginTest] java.lang.IllegalStateException: The driver executable does not exist: /opt/buildAgent1/work/c4641c7cfd3331f7/web/drivers/phantomjslinux/phantomjs at com.google.common.base.Preconditions.checkState(Preconditions.java:518) at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:123) at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:254) at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:190) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94) at test.core.base.SeleniumDriver.initNewDriver(SeleniumDriver.java:47) at test.core.base.TestBase.(TestBase.java:25)

我不太了解 TeamCity,很难找到适用于我的项目并且我真正理解的解决方案。所以欢迎任何帮助。谢谢:)

由 运行 npm install phantomjs 在服务器上解决并从那里使用 PhantomJS。