带有PhantomJS的WebDriverJS适用于OSX,但不适用于Linux

时间:2014-09-08 12:30:18

标签: linux node.js selenium phantomjs webdriver-io

我正在使用以下组合:

每个组件都可以单独运行,当我运行时:

var client = webdriverjs.remote({ 
    desiredCapabilities: { 
        browserName: 'phantomjs',  
        'phantomjs.binary.path': '/path-to/node_modules/phantomjs/bin/phantomjs'
    }, 
    logLevel: 'silent' 
});

client.init();

它在OSX / Mac上运行正常,但在我们的CI Linux服务器(Ubuntu)上,我收到以下错误消息;

PhantomJS is launching GhostDriver...
Unable to open file '/path/to/phantomjsdriver.log'

在不可原谅的Java堆栈跟踪之前......

Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.java:83)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:176)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:112)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:89)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:110)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:57)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:112)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:173)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:200)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:162)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:128)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
    at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
    at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException

&安培;

Driver info: driver.version: PhantomJSDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:590)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:127)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:140)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:110)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    ... 14 more
 Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.

我怀疑是权限问题,但想知道是否有人之前遇到过这个问题。 至少,能够弄清楚为什么它在Mac上运行会很棒。

1 个答案:

答案 0 :(得分:2)

此文件 - phantomjsdriver.log - 只能由具有文件写入权限的用户创建。 以“root”身份执行程序解决了这个问题。