Reputation: 103
Is it possible to get current environment config in Helper Class in Codeception?
Now I'm passing it as $env
variable from Cest where I use this Helper.
class FavoritesCest
{
public function _before(AcceptanceTester $I)
{
$I->loggedInIntoFrontend(LoginPage::LOGIN, LoginPage::PASSWORD, $I->getScenario()->current('env'));
}
...
}
In Cest I use $I->getScenario()->current('env')
, but in Helper I can't use Actor class to get environment this way.
// Helper Class
class Frontend extends Acceptance
{
public function loggedInIntoFrontend($name, $password, $env)
{ ... }
}
Has anyone encountered this?
Upvotes: 0
Views: 1436
Reputation: 694
You can use the following approach to get current environment in Helper class:
// 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') {
...
}
}
}
Upvotes: 1