如何在Codeception帮助器中访问actor(例如AcceptanceTester)

mco*_*ode 6 php selenium acceptance-testing codeception

当我使用codeception生成的AcceptanceHelper(_support/AcceptanceHelper.php)时,如何访问Actor/AcceptanceTester($ I).如何从StepObjects访问我的函数?

我有:

接受/ _steps/MyStepObject.php

namespace AcceptanceTester;


class MyStepObject extends \AcceptanceTester
{
public function deleteCookies(){
    $I = $this;

    $I->amGoingTo("delete all cookies...");
    $I->executeInSelenium(function(\WebDriver $webdriver) {$webdriver->manage()->deleteAllCookies(); });
    $I->reloadPage();
}

public function loginUser($user,$password,$language = 'Untranslated')
{
    $I = $this; 

    $I->amOnPage(\LoginPage::$URL);
    $I->deleteCookies();
    $I->amGoingTo('fill the fields...');
    $I->fillField(\LoginPage::$usernameField, $user);
    $I->fillField(\LoginPage::$passwordField, $password);
    $I->click(\LoginPage::$loginButton);
}   
}
Run Code Online (Sandbox Code Playgroud)

在类中_support/AcceptanceHelper.php我想调用AcceptanceTester中的方法$I->canSee('something'),我想'login'从我的StepObject 调用我自己的方法(比如).

我知道我可以获得一个特定的模块(例如WebDriver)$this->getModule('WebDriver').但是我怎样才能获得AcceptanceTester/my StepObject?

dwe*_*aus 4

从测试中传入 $I 变量。这有点冗长,但效果很好。

public function deleteCookies($I){...}

然后在测试中写:

$I->deleteCookies($I);