在Selenium Grid中注册PhantomJS节点时出错

我有以下问题

  • 我成功推出了Selenium Grid hub:

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

  • 之后我尝试使用以下命令启动PhantomJS节点:

phantomjs --webdriver=8090 --webdriver-selenium-grid-hub=http://localhost:4444


但得到了错误:

[INFO – 2016-03-25T13:56:28.397Z] GhostDriver – Main – 在端口8090上运行[INFO – 2016-03-25T13:56:28.397Z] GhostDriver – Main – 注册到Selenium HUB’http :// localhost :4444 ‘版本:使用’127.0.0.1:8090’与org.openqa.grid.selenium.proxy.DefaultRemoteProxy作为远程代理。 [ERROR – 2016-03-25T13:56:28.400Z] GhostDriver – main.fail – {“line”:97,“sourceURL”:“phantomjs://platform/hub_register.js”,“stack”:“register @” phantomjs://platform/hub_register.js:97:79 \ nglobal code @ phantomjs://code/main.js:78:37“}

phantomjs://platform/console++.js:263错误

标准节点工作正常,但PhantomJS错误。 我做错了什么?

来自phantomjs http://phantomjs.org/build.html的解决方法*** d / l源代码并在src / ghostdriver注释掉行中的hub_register.js,如下所示:

// var ghostdriver = ghostdriver || {};

 return { capabilities: [{ browserName: "phantomjs", version: version, //platform: ghostdriver.system.os.name + '-' + ghostdriver.system.os.version + '-' + ghostdriver.system.os.architecture, maxInstances: 1, seleniumProtocol: "WebDriver" 

编译,一切正常!

快捷方式: https : //github.com/darwin10/phantomjs

原始资料来源: https : //github.com/detro/ghostdriver/issues/394

对于任何仍在寻找的人,这里有linux和windows x64构建,其中有v2.1.1的解决方法(Windows构建是在一个拉取请求 – hex编辑器解决方法不适用于Windows cos .exe的压缩)

https://github.com/mrorgues/PhantomJSCustomEdition

您可以使用dd命令覆盖部分二进制文件。
我要替换platform: //atform: ::

 $ cp /usr/local/bin/phantomjs . $ ./phantomjs --version 2.1.1 $ xxd -c 16 phantomjs | grep -C 2 'platform:' 01c6aaa0: 7273 696f 6e3a 2076 6572 7369 6f6e 2c0a rsion: version,. 01c6aab0: 2020 2020 2020 2020 2020 2020 2020 2020 01c6aac0: 706c 6174 666f 726d 3a20 6768 6f73 7464 platform: ghostd 01c6aad0: 7269 7665 722e 7379 7374 656d 2e6f 732e river.system.os. 01c6aae0: 6e61 6d65 202b 2027 2d27 202b 2067 686f name + '-' + gho $ printf '//' | dd of=phantomjs conv=notrunc bs=1 seek=$((0x01c6aac0+0)) 2+0 records in 2+0 records out 2 bytes transferred in 0.000117 secs (17085 bytes/sec) $ xxd phantomjs | grep 'atform:' 01c6aac0: 2f2f 6174 666f 726d 3a20 6768 6f73 7464 //atform: ghostd $ ./phantomjs --version 2.1.1 $ mv phantomjs /usr/local/bin/ 

如果找不到该字符串,请尝试增加每行的八位字节数( xxd -c 256 )。

我遇到过同样的问题。 而不是像Ojen G.所建议的那样下载源代码和编译,我使用了neuro-sys发布的修补程序来对可执行文件进行更改。 我的操作系统是Ubuntu 16.04。

  1. 下载replacestrings.c程序。

     wget https://gist.githubusercontent.com/neuro-sys/3bf00b6cf28a93e07e44/raw/52f715fd49fbd271a9450b61d5cd3cf29907a5a0/replacestring.c 
  2. 编译程序

     gcc replacestring.c -o replacestring 
  3. 用二进制替换Java源代码字符串,创建固定二进制文件。

     ./replacestring "$(strings /usr/lib/phantomjs/phantomjs | grep "platform: ghostdriver")" " " < /usr/lib/phantomjs/phantomjs > f_phantomjs 
  4. 制作二进制可执 并作为替代品

     chmod +x f_phantomjs sudo chown root:root f_phantomjs sudo mv f_phantomjs /usr/lib/phantomjs cd /usr/lib/phantomjs sudo echo "Fixed error in phantomjs; old file in e_phantomjs" > README.txt sudo mv phantomjs e_phantomjs sudo ln f_phantomjs phantomjs 

完成这些步骤后,它运行正常(Selenium hub已经运行):

 phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://localhost:4444 [INFO - 2016-05-07T16:33:35.534Z] GhostDriver - Main - running on port 8080 [INFO - 2016-05-07T16:33:35.534Z] GhostDriver - Main - registering to Selenium HUB 'http://localhost:4444' version: using '127.0.0.1:8080' with org.openqa.grid.selenium.proxy.DefaultRemoteProxy as remote proxy. [INFO - 2016-05-07T16:33:35.604Z] HUB Register - register - Registered with grid hub: http://localhost:4444/ (ok) 

尝试用本地IP替换localhost

phantomjs --webdriver=8090 --webdriver-selenium-grid-hub=http://localhost:4444

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

遵循这个要点: https : //gist.github.com/neuro-sys/41e368839a9b20dafb34

编辑二进制文件以将//放在违规行前面对我有效,但不是字符串替换。

– >关注使用hdex的部分

搜索platform:

并用//atform:替换//atform:

//替换字母pl (hex2F2F

我花了2个月试图解决这个问题,尝试一切可能,我的主要问题是很多解决方案都不会连接到网格,而且那些在docker容器中的东西只能连接到托管在其上的本地网格Docker主机。

所以……我终于建立了自己的解决方案,它起作用: https : //github.com/madhavajay/selenium-node-phantomjs

Docker镜像是madhavajay / selenium-node-phantomjs

它使用PhantomJS 2.1.1自定义构建和固定的Ghostdriver然后我自己调整到最新的Ghostdriver分支,以允许自定义–remoteHost参数全部包含在具有可配置环境变量的Docker容器中。

我希望这可以拯救我所遭受的失去的一周。