设置与 vagrant 或 docker 混合的 selenium、chromedriver 和 wdio

Setting up selenium, chromedriver, and wdio mixed with vagrant or docker

我开始尝试学习如何为一个小项目编写自动化测试,但开箱即用。经过几个小时的搜索和试验,我找到了适合我的项目的正确配置,并认为分享它可能会在未来帮助人们。

这里是我在调试过程中遇到的错误的小总结:

我认为我的问题可能是由于让 WDIO 在我的本地计算机上执行我的测试而 Selenium 在 Vagrant VM 中对浏览器进行锤击。因此,这主要适用于为 WDIO 和 Selenium/Chromedriver 使用单独环境(vagrant->local、vagrant->vagrant、docker->local 等)的人。 Here is a gist of the configuration file I ended up with.

我从 fanatique/vagrant-selenium-vm and modified it to use Chrome instead of Firefox because send_keys was broken with Firefox/geckodriver at the time of writing 开始。换出包后,我会用 wdio 开始测试,但它似乎挂起。打开详细日志记录显示它尝试启动但失败,没有解释原因。

[00:06:39]  COMMAND POST     "/wd/hub/session"
[00:06:39]  DATA        {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"browserName":"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.6.2","name":"webdriverio"}}}

它需要从 fanatique/vagrant-selenium-vm's setup.sh to see the logs from Selenium in real time, then I was able to see a "only local connections are allowed" message from chromedriver. That led me to a SO post 中的 nohup java ... 命令中删除 & 说要将 --whitelisted-ips="" 作为 arg 添加到 chromedriver - 但我仍然得到 本地连接 错误信息。 Chrome 本身最终需要一个 --no-sandbox 标志 - 这允许 WDIO 连接到 Selenium 中的 chromedriver 和我的测试 运行 从那里。