Selenium和ChromeDriver:会话未创建,无法连接到渲染器

3
我正在尝试在Mac上使用Webdriver.io、Selenium和ChromeDriver运行自动化测试。我使用了所有相关软件的最新版本:
- Selenium 3.9.1 - ChromeDriver 2.35 - Chrome 64 - 操作系统: macOS High Sierra 10.13.3
当我尝试从CLI运行wdio时,我会得到以下输出:
$ ./node_modules/.bin/wdio --spec ./test_js/specs/features/aggregated/dataAccessControl.feature.js

----------
selenium-standalone installation starting
----------

---
selenium install:
from: https://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.1.jar
to: /PROJECT_PATH/node_modules/selenium-standalone/.selenium/selenium-server/3.9.1-server.jar
---
chrome install:
from: https://chromedriver.storage.googleapis.com/2.35/chromedriver_mac64.zip
to: /PROJECT_PATH/node_modules/selenium-standalone/.selenium/chromedriver/2.35-x64-chromedriver
---
File from https://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.1.jar has already been downloaded
---
File from https://chromedriver.storage.googleapis.com/2.35/chromedriver_mac64.zip has already been downloaded


-----
selenium-standalone installation finished
-----
A service failed in the 'onPrepare' hook
Error: Unable to connect to selenium
    at Timeout.hasStarted [as _onTimeout] (/PROJECT_PATH/node_modules/selenium-standalone/lib/check-started.js:17:10)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)

Continue...
ERROR: session not created exception
from disconnected: unable to connect to renderer
chrome
    at new RuntimeError (/PROJECT_PATH/node_modules/webdriverio/build/lib/utils/ErrorHandler.js:144:12)
    at Request._callback (/PROJECT_PATH/node_modules/webdriverio/build/lib/utils/RequestHandler.js:313:39)
    at Request.self.callback (/PROJECT_PATH/node_modules/request/request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/PROJECT_PATH/node_modules/request/request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/PROJECT_PATH/node_modules/request/request.js:1085:12)
    at Object.onceWrapper (events.js:313:30)

这个过程随后停止。Chrome图标在Dock上短暂出现,然后立即消失。
我尝试从CLI启动Selenium独立服务器,导航到http://localhost:4444/wd/hub/static/resource/hub.html并尝试在那里手动启动Chrome会话,但结果相同:Chrome图标弹出,然后消失,Selenium抛出错误“无法创建新会话”。
我还尝试下载旧版Chromium并强制ChromeDriver使用它,但无法启动可执行文件。
2个回答

10

在这里找到了解决办法:https://github.com/Polymer/web-component-tester/issues/573#issuecomment-310828303

引用:

终于在经历了很多困难后修复了它。这是因为我的本地主机映射使用了新的IPv6标准,例如[::1],但Selenium需要IPv4地址,例如127.0.0.1。所以我必须使用系统中的命令来更改它,就像这样:

打开一个终端窗口并输入以下命令:

sudo open -a TextEdit /etc/hosts

你会被提示输入管理员密码,你的主机文件将在TextEdit中打开。在你的主机文件中添加这一行:

127.0.0.1 localhost

保存文件并关闭。

(补充说明:对我来说,TextEdit拒绝保存该文件,即使作为超级用户,所以我改用sudo vim /etc/hosts)。


这解决了我的问题,我花了最近6个小时来调试它。 - Robert

0

Google Chrome 浏览器每天都在更新,您需要根据计算机上使用的浏览器版本使用 Chrome 驱动程序 exe,请使用最新的 Chrome 驱动程序和浏览器版本。 https://chromedriver.chromium.org/downloads


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接