当我运行Codeception测试时,有时在验收测试中,浏览器启动太晚,测试不等待它启动,并且我在浏览器启动之前通过的测试会出错:
[ConnectionException]无法在http://127.0.0.1:4444/wd/hub连接到Webdriver。请确保Selenium Server或PhantomJS正在运行。
#1 Codeception \ Subscriber \ Module->之前
#2 D:\ path \ Yii \ basic \ vendor \ symfony \ event-dispatcher \ EventDispatcher.php:212
#3 D:\ path \ Yii \ basic \ vendor \ symfony \ event-dispatcher \ EventDispatcher.php:44
有一次浏览器根本没有启动。
我的命令:
C:\Windows\System32\cmd.exe /K "cd /D D:\path\Yii\basic && vendor\bin\codecept run"
acceptance.suite.yml :
class_name: AcceptanceTester
extensions:
enabled:
- Codeception\Extension\RunProcess:
- java -jar -Dwebdriver.chrome.driver="D:/Selenium/chromedriver.exe" -Dwebdriver.gecko.driver="D:/Selenium/geckodriver.exe" "D:/Selenium/selenium-server-standalone-3.6.0.jar"
modules:
enabled:
- WebDriver:
url: https://hotel.localhost/
browser: chrome
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
codeception.yml :
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: true
modules:
config:
Yii2:
configFile: 'config/test.php'
cleanup: false
coverage:
enabled: true
whitelist:
include:
- models/*
- controllers/*
提前谢谢。
答案 0 :(得分:1)
按照记录的here向RunProcess配置添加一些睡眠。
要等待启动进程,请使用sleep选项。在这种情况下,您需要将配置指定为对象:
extensions:
enabled:
- Codeception\Extension\RunProcess:
0: java -jar ~/selenium-server.jar
1: mailcatcher
sleep: 5 # wait 5 seconds for processes to boot