2017-03-09 49 views
0

是否可以在Codeception的Helper类中获取当前环境配置?Codeception - 如何在Helper类中获取当前环境配置

现在我通过它作为CEST的$env变量,我使用这个助手。

class FavoritesCest 
    { 
     public function _before(AcceptanceTester $I) 
     { 
      $I->loggedInIntoFrontend(LoginPage::LOGIN, LoginPage::PASSWORD, $I->getScenario()->current('env')); 
     } 

    ... 

    } 

在CEST我用$I->getScenario()->current('env'),但助手,我不能用演员类来获得环境这个样子。

// Helper Class 
    class Frontend extends Acceptance 
    { 
     public function loggedInIntoFrontend($name, $password, $env) 
     { ... } 
    } 

有没有人遇到过这个?

回答

1

您可以用下面的办法在助手类来获得当前的环境:

// Helper Class 
class Frontend extends Acceptance 
{ 
    private $currentEnv = ''; 

    // This hook will be called before each scenario. 
    public function _before(\Codeception\TestInterface $test) 
    { 
     $this->currentEnv = $test->getMetadata()->getCurrent('env'); 
    } 

    public function loggedInIntoFrontend($name, $password) 
    { 
     if ($this->currentEnv == 'my-env') { 
      ... 
     } 
    } 
} 
+1

其实我已经找到了如何解决我的问题在其他的方式,但你的例子也能正常工作!非常感谢! :) –

+0

另一种方式是什么? – gvanto

相关问题