在设置Selenium + NodeJS时运行测试JS脚本时出错

时间:2015-05-06 04:00:06

标签: node.js google-chrome selenium

我主要按照本指南在运行Ubuntu 14.04的Vagrant中设置Selenium + Node + Chrome。

http://www.chrisle.me/2013/08/running-headless-selenium-with-chrome/#comment-30581

当我在步骤6中运行完全示例时,NodeJS返回错误,而不是返回步骤7中显示的结果。

错误,由NodeJS提供:

vagrant@dev:/pm/setup/install/chrome$ node test.js   /pm/setup/install/chrome/node_modules/selenium-webdriver/lib/goog/async/nexttick.js:39   goog.global.setTimeout(function() { throw exception; }, 0);
                                            ^ UnknownError: unknown error: unable to discover open pages   (Driver info: chromedriver=2.2,platform=Linux 3.13.0-44-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 20.67 seconds Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-44-generic', java.version: '1.7.0_79' Driver info: org.openqa.selenium.chrome.ChromeDriver
    at new bot.Error (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/atoms/error.js:113:18)
    at Object.bot.response.checkResponse (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
    at /pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:158:24
    at promise.ControlFlow.runInFrame_ (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
    at promise.Callback_.goog.defineClass.notify (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
    at promise.Promise.notify_ (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)
    at Array.forEach (native)
    at Object.goog.array.forEach (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/goog/array/array.js:203:43)
    at promise.Promise.notifyAll_ (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/promise.js:552:16)
    at goog.async.run.processWorkQueue [as _onTimeout] (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/goog/async/run.js:125:21) From: Task: WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:155:22)
    at Function.webdriver.WebDriver.createSession (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:129:30)
    at Builder.build (/pm/setup/install/chrome/node_modules/selenium-webdriver/builder.js:416:22)
    at Object.<anonymous> (/pm/setup/install/chrome/test.js:8:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16) From: Task: WebDriver.navigate().to(http:// www.google.com)
    at webdriver.WebDriver.schedule (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:360:15)
    at webdriver.WebDriver.Navigation.to (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:1097:23)
    at webdriver.WebDriver.get (/pm/setup/install/chrome/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:791:26)
    at Object.<anonymous> (/pm/setup/install/chrome/test.js:10:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

Selenium Server提供的控制台输出

16:48:57.861 INFO - Executing: [new session: {browserName=chrome}] at URL: /session) 16:48:57.862 INFO - Creating a new session for Capabilities [{browserName=chrome}] Starting ChromeDriver (v2.2) on port 9110 16:49:18.529 WARN - Exception thrown java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-44-generic', java.version: '1.7.0_79' Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:188)
        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:89)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:63)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:205)
        at org.openqa.selenium.remote.server.JsonHttpRemoteConfig.handleRequest(JsonHttpRemoteConfig.java:192)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:167)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:139)
        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:677)
        at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
        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:914)
        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:357)
        at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534) Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-44-generic', java.version: '1.7.0_79' Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:72)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:215)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)
        ... 8 more Caused by: org.openqa.selenium.WebDriverException: unknown error: unable to discover open pages   (Driver info: chromedriver=2.2,platform=Linux 3.13.0-44-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 20.67 seconds Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-44-generic', java.version: '1.7.0_79' Driver info: org.openqa.selenium.chrome.ChromeDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:129)
        ... 13 more 16:49:18.534 WARN - Exception: unknown error: unable to discover open pages   (Driver info: chromedriver=2.2,platform=Linux 3.13.0-44-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 20.67 seconds Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-44-generic', java.version: '1.7.0_79' Driver info: org.openqa.selenium.chrome.ChromeDriver

我已阅读了许多其他指南,修改过并重新安装了10次以上。但是一直有不同的错误,这是迄今为止最有希望的错误。

在命令行中卷曲https://www.google.com,给出页面的完整html源。

提前感谢您帮助解决此问题!

环境:Vagrant中的Ubuntu 14.04。主机是Mac OS X Yosemite v10.10.2

0 个答案:

没有答案