8

I start a selenium grid hub with it's default startup command,

java -jar selenium-server-standalone-2.33.0.jar -role hub

And I start up PhantomJS in it's webdriver mode, on the same machine, like,

phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444

When PhantomJS starts up, I get nothing but "All 'OK'" messages,

[INFO  - 2013-09-09T18:10:38.849Z] GhostDriver - Main - running on port 8080
[INFO  - 2013-09-09T18:10:38.850Z] GhostDriver - Main - registering to Selenium HUB 'http://127.0.0.1:4444' using '127.0.0.1:8080'
[INFO  - 2013-09-09T18:11:47.164Z] HUB Register - register - Registered with grid hub: http://127.0.0.1:4444/ (ok)

But if I try to use that browser, with

driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
                          desired_capabilities=DesiredCapabilities.PHANTOMJS)

Looking at the output from the PhantomJS executable,

[INFO  - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - _decorateNewWindow - page.settings: {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.2 Safari/534.34","webSecurityEnabled":true}
[INFO  - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - page.customHeaders:  - {}
[INFO  - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - CONSTRUCTOR - Desired Capabilities: {"platform":"ANY","javascriptEnabled":true,"browserName":"phantomjs","version":""}
[INFO  - 2013-09-09T18:17:12.531Z] Session [0c5c9500-197c-11e3-8eed-b3b7a73965aa] - CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":"1.9.2","driverName":"ghostdriver","driverVersion":"1.0.4","platform":"mac-10.7 (Lion)-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2013-09-09T18:17:12.531Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 0c5c9500-197c-11e3-8eed-b3b7a73965aa

Everything seems to be fine, but the code crashes :/ I get a huge error stacktrace, mainly down to,

selenium.common.exceptions.WebDriverException: Message: u'Error forwarding the new session new session request for webdriver should contain a location header with the session.'

And if you check the output of the grid hub,

INFO: Trying to create a new session on test slot {seleniumProtocol=WebDriver, browserName=phantomjs, maxInstances=1}
INFO: Available nodes: [host :http://127.0.0.1:8080 time out : 300000]

There also seems to be an issue. It seems like, for whatever reason, the grid hub doesn't get any information back from the PhantomJS executable, even though it seems like it is processing things correctly.

For testing, I also have a regular selenium node running, on the same machine, with the command

java -jar selenium-server-standalone-2.33.0.jar -role node

and if I start up a Firefox RemoteWebDriver session (in Python), with

driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
                          desired_capabilities=DesiredCapabilities.FIREFOX)

all is fine.

It looks like everything is set up correctly, I'm keeping things as 'vanilla' and close to what the docs say as possible, but just can't get over the fence here.

The exact same error happens when trying in Java, too

WebDriver driver = new RemoteWebDriver(DesiredCapabilities.phantomjs());

Screenshot of the grid console with both connected, PhantomJS is alive and well there,

enter image description here

Left is default selenium node, right is PhantomJS (and 10.0.0.222 is my laptop's IP address in work).

And my versions are 1.9.2 for PhantomJS and obviously 2.33.0 for selenium.

4

1 回答 1

11

原来这是phantomjs 1.9.2版本的一个bug特性。他们更新到最新的 ghostdriver (v1.4) 库,我想这就是它被引入的地方。Ghostdriver 遵守新的 Selenium 协议,使用帖子来创建会话,而不是使用位置标头。Selenium 现在从帖子正文中的 json 中获取位置等。事实证明,您看到的错误和我一直看到的错误是因为您使用的是旧的 selenium jar,它使用旧样式的会话创建协议和新版本的 selenium。现在你的问题的答案是回到 phantomjs 1.9.1将您的 selenium jar 更新为 2.35.0(请参阅下面的链接)。为了重现您的错误,我使用 ruby​​ 和 python selenium webdrivers 以及作为集线器运行的 2.33.0 selenium jar 和作为 ghostdriver worker 运行的 phantomjs 1.9.2 进行了测试。

这是 github 问题中描述的相同错误:

https://github.com/ariya/phantomjs/issues/11610

我相信这与这个特定的提交有关。您可以看到“位置”的标题已被删除。

https://github.com/detro/ghostdriver/commit/60bf3c90aa825cc3db4fa899b6a67bb7f109d55d

以下是上述提交所针对的问题的描述: https ://github.com/detro/ghostdriver/issues/247

从那里你可以看到它是一个让事情与 selenium-webdrivers 最新协议一起工作的修复:“新规范:https ://code.google.com/p/selenium/wiki/JsonWireProtocol#/session Selenium 的变化:https: //code.google.com/p/selenium/source/detail?r=8c3c65772d57 "

看起来更新到最新的 selenium-webdriver-standalone jar 将使您能够使 1.9.2 正常工作。我已经确认我的 ruby​​ webdriver 现在可以与 2.35.0 jar 和 phantomjs 1.9.2 成功连接。

你可以在这里获取最新的 jar:

https://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.35.0.jar&can=2&q=

于 2013-09-15T02:21:52.377 回答