硒与ChromeDriver:未创建会话,无法连接到渲染器 [英] Selenium & ChromeDriver: session not created, unable to connect to renderer

查看:21
本文介绍了硒与ChromeDriver:未创建会话,无法连接到渲染器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Mac 上通过 Webdriver.io、Selenium 和 ChromeDriver 运行自动化测试.我正在使用所有相关软件的最新版本:

I am trying to run automated tests via Webdriver.io, Selenium and ChromeDriver on Mac. I am using the latest versions of all involved software:

  • 硒 3.9.1
  • ChromeDriver 2.35
  • Chrome 64
  • 操作系统:macOS High Sierra 10.13.3

当我尝试从 CLI 运行 wdio 时,我得到以下输出:

When I try to run wdio from the CLI, I get the following output:

$ ./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 上弹出片刻,然后立即消失.

The process then stops. The Chrome icon pops up for a moment on the dock, then disappears immediately.

我尝试从 CLI 启动 Selenium 独立服务器,导航到 http://localhost:4444/wd/hub/static/resource/hub.html 并尝试在那里手动启动 Chrome 会话,但结果是一样的:Chrome 图标弹出,消失,Selenium 抛出错误无法创建新会话."

I have tried starting the Selenium standalone server from the CLI, navigating to http://localhost:4444/wd/hub/static/resource/hub.html and trying to start a Chrome session manually there, but the result is the same: the Chrome icon pops up, disappears, and Selenium throws an error "Unable to create new session."

我也尝试下载旧版本的 Chromium 并强制 ChromeDriver 使用它,但它无法启动可执行文件.

I have also tried downloading an older version of Chromium and forcing ChromeDriver to use that, but it's just unable to launch the executable.

推荐答案

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

引用:

经过一番努力,我终于把它修好了.这是因为我的 localhost 是根据新的 Ipv6 标准(如 [::1])映射的,但 selenium 需要 ipv4 地址,如 127.0.0.1.所以我不得不像这样使用系统中的命令来更改它:

Finally i got it fixed after lot of struggle. It was happening because my localhost was mapped according to new Ipv6 standard like [::1] but the selenium needed the ipv4 address like 127.0.0.1. so i had to change it using the command in my system like this :

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

Open a terminal window and type this line:

sudo open -a TextEdit/etc/hosts

sudo open -a TextEdit /etc/hosts

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

You will be prompt to type in your admin password and your host file will open in TextEdit. Add this line in your host file :

127.0.0.1 本地主机

127.0.0.1 localhost

保存文件并关闭.就是这样.

Save the file and close. That's it.

(附录:TextEdit 拒绝为我保存文件,即使是超级用户,所以我使用 sudo vim/etc/hosts 代替)

(addendum: TextEdit refused to save the file for me, even as superuser, so I used sudo vim /etc/hosts instead)

这篇关于硒与ChromeDriver:未创建会话,无法连接到渲染器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆