2016-11-15 113 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 

,我想知道是否有一種方法在運行時間去測試本身內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); 
    } 

回答

0

您應該可以通過scenario訪問該信息。如在docs中所述:

您可以訪問Ceptic和Cest格式的\ Codeception \ Scenario。在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); 
} 
相關問題