【问题标题】:Codeception acceptance tests run before browser startsCodeception 验收测试在浏览器启动之前运行
【发布时间】:2017-10-20 07:10:07
【问题描述】:

当我运行 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/*

提前谢谢你。

【问题讨论】:

    标签: selenium testing yii2 codeception acceptance-testing


    【解决方案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
    

    【讨论】:

    • 谢谢!虽然没有适当的浏览器启动检测让我感到惊讶,但我必须依靠经验选择的值,希望它足够大。
    • 将 sleep 替换为:"timeout 300 bash -c 'while [[ \"$(curl -s -o /dev/null -w ''%{http_code}'' localhost:4444)\ " != '200' ]]; do sleep 5; done' || false"
    • 这很好用,我把它改成使用等待它。例如。 0:java -jar ~/selenium-server.jar 1:等待它 127.0.0.1:4444
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2022-11-17
    • 2014-02-01
    • 1970-01-01
    • 2020-04-25
    • 2018-01-14
    • 2018-10-06
    相关资源
    最近更新 更多