Webdriver 无法与 phantomjs 创建会话

Webdriver unable to create session with phantomjs

我已按照 Setting up PhantomJS 中的说明进行操作。

请查找目录结构如下

吽 find . -name phantomjs; ll
./node_modules/.bin/phantomjs
./node_modules/phantomjs
./node_modules/phantomjs/bin/phantomjs
./node_modules/phantomjs/lib/phantom/bin/phantomjs
total 16
-rw-r--r--  1 sarbbo  Y\Domain Users  1269 Mar 23 12:02 specs.js
drwxr-xr-x  4 sarbbo  Y\Domain Users   136 Mar 23 12:08 node_modules
-rw-r--r--  1 sarbbo  Y\Domain Users   204 Mar 23 12:25 conf.js

conf.js内容如下

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['specs.js'],
  capabilities: {
    'browserName': 'phantomjs',
    'phantomjs.binary.path': require('phantomjs').path
  }
}

根据 capabilities: {'browserName': 'chrome'}

的需要工作

执行protractor conf.js时,出现如下错误:

通过 webdriver-manager [webdriver-manager 已使用 webdriver-manager start 命令启动]

12:41:41.043 INFO - Executing: [new session: Capabilities [{phantomjs.binary.path=/Users/sarbbo/GitHub/protractor/node_modules/phantomjs/lib/phantom/bin/phantomjs, count=1, browserName=phantomjs}]])
12:41:41.052 INFO - Creating a new session for Capabilities [{phantomjs.binary.path=/Users/sarbbo/GitHub/protractor/node_modules/phantomjs/lib/phantom/bin/phantomjs, count=1, browserName=phantomjs}]
12:41:41.054 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'rushpress-lm', ip: '10.73.199.247', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.2', java.version: '1.8.0_25'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:175)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:111)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:88)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:108)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:57)
    at org.openqa.12:41:41.059 WARN - Exception: org.openqa.selenium.browserlaunchers.Proxies

并通过量角器 错误 - 无法启动 WebDriver 会话。

/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113
  var template = new Error(this.message);
                 ^
UnknownError: org.openqa.selenium.browserlaunchers.Proxies
    at new bot.Error (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113:18)
    at Object.bot.response.checkResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
    at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:152:24
    at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
    at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
    at notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
    at notifyAll (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:442:7)
    at resolve (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:420:7)
    at fulfill (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:535:5)
    at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
==== async task ====
WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:149:22)
    at Function.webdriver.WebDriver.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:123:30)
    at Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:294:22)
    at DriverProvider.getNewDriver (/usr/local/lib/node_modules/protractor/lib/driverProviders/driverProvider.js:50:7)
    at Runner.createBrowser (/usr/local/lib/node_modules/protractor/lib/runner.js:178:37)
    at /usr/local/lib/node_modules/protractor/lib/runner.js:259:24
    at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:797:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)
[launcher] Process exited with error code 1

任何指针都会有很大帮助。

谢谢

更新量角器解决了问题,它使用 selenium-server-standalone-2.45.0.jar

您可能需要使用 sudo 执行以下命令。

npm i protractor -g
webdriver-manager update

2015 年 3 月 26 日更新

以上适用于 phantomjs-1.9.8 但不适用于 phantomjs-2.0.0。 我在本地更新 phantomjs version 并从本地副本安装。

发生了同样的问题。看起来,selenium-server-standalone-2.45.0.jarphantomjs-2.0.0

不兼容

TL;DR

我在搜索解决方案时遇到了

Downgrading back to version 2.43.1 fixes the issue, so i suspect a change in 2.44.0 has broken the ability to use PhantomJS on the grid.

Issue 8102: PhantomJS Doesn't Work on Selenium Grid 2.44.0

我系统中 /usr/local/lib/node_modules/protractor/selenium 处的 selenium-server-standalone 也是 selenium-server-standalone-2.44.0.jar

所以,我试图通过 webdriver-manager 寻找降级 selenium-server-standalone,但 找不到任何合适的选项

吽 webdriver-manager --help
Usage: webdriver-manager <command>
Commands:
  update: install or update selected binaries
  start: start up the selenium server
  status: list the current available drivers

Options:
  --out_dir        Location to output/expect                         [default: "/usr/local/lib/node_modules/protractor/selenium"]
  --seleniumPort   Optional port for the selenium standalone server
  --ignore_ssl     Ignore SSL certificates                           [default: false]
  --proxy          Proxy to use for the install or update command
  --alternate_cdn  Alternate CDN to the binaries
  --standalone     Install or update selenium standalone             [default: true]
  --chrome         Install or update chromedriver                    [default: true]
  --ie             Install or update IEDriver                        [default: false]

Please specify one command

所以我通过 curl/usr/local/lib/node_modules/protractor/selenium

下载了 selenium-server-standalone-2.43.1.jar
sudo curl -O https://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar

但是在通过 webdriver-manager start 命令启动 webdriver-manager 时,显示了以下消息。

Selenium Standalone is not present. Install with webdriver-manager update --standalone

我刚刚下载了 selenium-server-standalone-2.43.1.jar,但为什么 webdriver-manager 抱怨?

在查看 /usr/local/lib/node_modules/protractor 上的 webdriver-manager 代码时,我注意到以下内容:

if (!binaries.standalone.exists) {
  console.error('Selenium Standalone is not present. Install with ' +
      'webdriver-manager update --standalone');
  process.exit(1);
}

它试图根据 /usr/local/lib/node_modules/protractor/config.json

匹配 selenium-server-standalone 的存在

以下是/usr/local/lib/node_modules/protractor/config.json

的内容
{
  "webdriverVersions": {
    "selenium": "2.44.0",
    "chromedriver": "2.14",
    "iedriver": "2.44.0"
  }
}

关于更新 量角器 /usr/local/lib/node_modules/protractor/config.json 已更新为

{
  "webdriverVersions": {
    "selenium": "2.45.0",
    "chromedriver": "2.14",
    "iedriver": "2.45.0"
  }
}

然后执行 webdriver-manager update 安装的 selenium-server-standalone-2.45.0.jarchromedriver


现在,在执行时 protractor conf.js 它按预期执行。