【问题标题】:Selenium, Java, Maven, PhantomJS + TeamCitySelenium、Java、Maven、PhantomJS + TeamCity
【发布时间】:2017-08-04 17:27:54
【问题描述】:

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

我最近决定将该项目添加到我们在 Linux 上运行的 TeamCity,由于它无法在浏览器上运行测试,我想切换到 PhantomJS 驱动程序。

我已经尝试了我在网上找到的所有解决方案的多种变体,但仍然无法正常工作。 目前我的资源中有 phantomjs 二进制文件,并且我在枚举类中获得了这样的驱动程序:

PHANTOMJS {
    @Override
    public WebDriver initNewDriver() {
        System.setProperty("phantomjs.binary.path", ClassLoader.getSystemResource(RELATIVE_PATH_TO_FILE_IN_RESOURCES).getFile());
        return new PhantomJSDriver();
    }

然后在测试类中,我从 driver.get(SOME_URL) 开始 - 这是它有史以来最远的。

无论我做什么,当我尝试通过“干净测试”在 TeamCity 上运行它时,我都会得到这样的结果:

[userLoginTest] java.lang.IllegalStateException:驱动程序可执行文件不存在:/opt/buildAgent1/work/c4641c7cfd3331f7/web/drivers/phantomjslinux/phantomjs [14:41:41] [userLoginTest] java.lang.IllegalStateException:驱动程序可执行文件不存在:/opt/buildAgent1/work/c4641c7cfd3331f7/web/drivers/phantomjslinux/phantomjs 在 com.google.common.base.Preconditions.checkState(Preconditions.java:518) 在 org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:123) 在 org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:254) 在 org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:190) 在 org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104) 在 org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94) 在 test.core.base.SeleniumDriver$3.initNewDriver(SeleniumDriver.java:47) 在 test.core.base.TestBase.(TestBase.java:25)

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

【问题讨论】:

  • 此路径是否存在 RELATIVE_PATH_TO_FILE_IN_RESOURCES ?里面有 phantomjs 二进制文件吗?它与您使用的机器兼容吗?对于您正在运行 TeamCity 的任何用户,它是否具有适当的权限?
  • 是的,它是 phantomjs 二进制文件的路径。 TeamCity 在 Linux 上运行,版本 2.6.32-504.16.2.el6.x86_64,我相信所有的权限都在那里

标签: java maven selenium phantomjs teamcity


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2017-10-12
    • 2016-10-23
    相关资源
    最近更新 更多