2017-10-20 152 views
0

當我運行Codeception測試時,有時在驗收測試中,瀏覽器啓動太晚,測試不會等待它啓動,並且在瀏覽器啓動之前通過的測試出現錯誤:在瀏覽器啓動之前運行代碼驗收測試

[ConnectionException]無法連接到Webdriver http://127.0.0.1:4444/wd/hub。請確保Selenium Server或PhantomJS正在運行。

#1 Codeception \訂戶\模塊 - >前

#2 d:\路徑\的Yii \基本\供應商\ symfony的\事件調度\ 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/* 

預先感謝您。

回答

1

爲文檔here中的RunProcess配置添加一些睡眠。

要等待進程啓動,請使用睡眠選項。在這種情況下,你需要配置被指定爲對象:

extensions: 
    enabled: 
     - Codeception\Extension\RunProcess: 
      0: java -jar ~/selenium-server.jar 
      1: mailcatcher 
      sleep: 5 # wait 5 seconds for processes to boot 
+0

謝謝!但令我驚訝的是,沒有正確的瀏覽器啓動檢測,我不得不依靠經驗選擇的值,希望它足夠大。 –

相關問題