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);
}
答案 0 :(得分:1)
您应该可以通过scenario
访问该信息。正如docs中所述:
您可以使用Cept和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);
}