php - 如何在 Codeception 助手中访问参与者(例如 AcceptanceTester)

标签 php selenium acceptance-testing codeception

当我使用 codeception (_support/AcceptanceHelper.php) 生成的 AcceptanceHelper 时,如何访问 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);
}   
}

_support/AcceptanceHelper.php 类中,我想从 AcceptanceTester 调用方法,例如 $I->canSee('something') 我想调用我的拥有来 self 的 StepObject 的方法(如 'login')。

我知道我可以使用 $this->getModule('WebDriver') 获取特定模块(例如 WebDriver)。但是我怎样才能得到 AcceptanceTester/我的 StepObject?

最佳答案

从测试中传入 $I 变量。它有点冗长,但工作正常。

公共(public)函数 deleteCookies($I){...}

然后在测试中写:

$I->deleteCookies($I);

关于php - 如何在 Codeception 助手中访问参与者(例如 AcceptanceTester),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26159708/

相关文章:

testing - 使用具有随机值的 Selenium IDE

python - 使用 SLIM 使用 Python 编写 Fitnesse 测试

python - 哪些工具用于编写 Python Web 应用程序(django)的验收测试?

php - 获取自定义请求头

php - file_get_contents() 将 UTF-8 转换为 ISO-8859-1

python - 如何处理 python WebDriver 中的零星 BadStatusLine、CannotSendRequest 错误

jasmine - 我可以使用 phantom.js 来测试一个 javascript 繁重的应用程序吗?

php - 使用php : Password hash doesn't match批量创建seafile用户(cloudstorage)

php - 在 PHP 中从 Highchart 生成文件夹中的图像

python - 无法从网页获取表格内的所有 pdf 链接