【问题标题】:Codeception get environment on which tests are runningCodeception 获取运行测试的环境
【发布时间】:2017-03-29 06:08:32
【问题描述】:
I have acceptance.suite.yml which looks like this.

class_name: AcceptanceTester
modules:
    enabled:
        - \Helper\Acceptance
        - WebDriver:
             url: https://staging.needhelp.com                 
env:
    firefox:
         modules:
            config:
                qa_user: qauser1@gmail.com
                WebDriver:
                    browser: 'firefox'
                    capabilities:
                        platform: Windows 7

    chrome:
         modules:
            config:
                qa_user: qauser2@gmail.com
                WebDriver:
                    browser: 'chrome'
                    capabilities:
                        platform: Windows 8.1

我这样运行测试用例:

$ codecept run acceptance UserCest.php --env firefox --env chrome

现在,我想知道是否有办法在运行时在测试本身中获取 env。

class UserCest extends BaseAcceptance
{



    public function login(AcceptanceTester $I)
    {
        $I->amOnPage("/");
        $I->see('Sign In');
        $env = $I->getConfig('env'); 
//something like this ?? which would return 'firefox' for the instance it is running as environment firefox. 

        $I->fillField($this->usernameField, $this->username);
        $I->fillField($this->passwordField, $this->password);
    }

【问题讨论】:

    标签: php phpunit codeception


    【解决方案1】:

    您应该可以通过scenario 访问该信息。正如docs中所说:

    您可以访问 Cept 和 Cest 格式的 \Codeception\Scenario。在 Cept 中 $scenario 变量默认是可用的,而在 Cests 中你应该通过依赖注入来接收它。

    所以在你的情况下,它应该看起来像这样:

    public function login(AcceptanceTester $I, \Codeception\Scenario $scenario)
    {
        $I->amOnPage("/");
        $I->see('Sign In');
    
        if ($scenario->current('browser') == 'firefox') {
            //code to handle firefox
        }
    
        $I->fillField($this->usernameField, $this->username);
        $I->fillField($this->passwordField, $this->password);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2017-04-03
      • 1970-01-01
      • 2017-10-17
      • 2014-10-16
      相关资源
      最近更新 更多