2016-11-15 3 views
1
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: [email protected] 
       WebDriver: 
        browser: 'firefox' 
        capabilities: 
         platform: Windows 7 

    chrome: 
     modules: 
      config: 
       qa_user: [email protected] 
       WebDriver: 
        browser: 'chrome' 
        capabilities: 
         platform: Windows 8.1 

И я бегу тест, как это:Codeception получить среду, на которой тесты работают

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

Теперь, мне было интересно, если есть способ получить окр внутри самого теста во время выполнения.

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); 
    } 

ответ

0

Вы должны быть в состоянии получить доступ к этой информации с помощью scenario. Как сказано в документе docs:

Вы можете получить доступ к \ Codeception \ Scenario в форматах Cept и Cest. По умолчанию в переменной Cept $ доступна переменная, в то время как в 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); 
} 
Смежные вопросы