问题描述
我正在尝试通过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图标在底座上弹出一会儿,然后立即消失.
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图标弹出,消失并抛出硒错误无法创建新会话."
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
Found the solution here: https://github.com/Polymer/web-component-tester/issues/573#issuecomment-310828303
报价:
打开一个终端窗口,然后输入以下行:
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:会话未创建,无法连接到渲染器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!