简体   繁体   English

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

[英]How can I access an actor (e.g. AcceptanceTester) in a Codeception helper

when I use the AcceptanceHelper generated by codeception (_support/AcceptanceHelper.php), how can I access the Actor / AcceptanceTester ($I). 当我使用由代码接收(_support / AcceptanceHelper.php)生成的AcceptanceHelper时,如何访问Actor / AcceptanceTester($ I)。 And how can I access my functions from StepObjects? 以及如何从StepObjects访问我的函数?

I have: 我有:

acceptance/_steps/MyStepObject.php 接受/_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);
}   
}

In the class _support/AcceptanceHelper.php I want to call methods from the AcceptanceTester like $I->canSee('something') and I want to call my own methods (like 'login' ) from my StepObject. 在类_support/AcceptanceHelper.php我想从AcceptanceTester调用方法,例如$I->canSee('something') ,我想从我的StepObject调用我自己的方法(例如'login' )。

I know I can get a specific module (eg the WebDriver) with $this->getModule('WebDriver') . 我知道我可以使用$this->getModule('WebDriver')获得特定的模块(例如$this->getModule('WebDriver') But how can I get the AcceptanceTester / my StepObject? 但是,如何获得AcceptanceTester / StepObject?

Passing in the $I variable from the test. 从测试中传递$ I变量。 It's a bit verbose but works fine. 它有点冗长,但效果很好。

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

and then in tests write: 然后在测试中写道:

$I->deleteCookies($I);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Codeception中,我应该将自定义方法添加到AcceptanceTester还是Helper / Acceptance-有区别吗? - In Codeception, should I add custom methods to AcceptanceTester or Helper/Acceptance - is there a difference? Codeception Actor 演员 vs 助手? - Codeception Actor Actor vs Helper? 如何使用PHP计算目录中的所有文件? (例如124个文件) - How can I count all files in a directory with PHP? (e.g. 124 Files) 如何在特定时间间隔内运行PHP脚本(例如每天一次)? - How can I run PHP script in certain interval (e.g. once a day)? 如何检查用户是否通过Google Adwords访问(例如,使用__utm * coockie)? - How can I check if a user came via Google Adwords (e.g. by using the __utm* coockie)? 如何在PHP中使用Ajax从网站(例如IMDB)中获取数据 - How can I fetch data from a website (e.g. IMDB ) using Ajax in PHP 如何选择0作为前缀的值,例如00-09 - How can I select values with 0 as prefix e.g. 00-09 如何对 SQL 查询进行排序,但将某些 UTF-8 字符排序为正常等效字符? (例如É被视为E等) - How can I sort an SQL query but have certain UTF-8 characters be ordered as their normal equivalent? (e.g. É be regarded as E etc) 我如何在jQuery中的页面加载时播放动画,以便它播放index.php而不播放other_page.php - How can I play an animation on page load in jQuery so that it plays for index.php but not e.g. other_page.php 如何在PHP中循环$ num,例如1、2、3、4、1、2、3、4、1、2、3、4 - How to loop $num in php, e.g. 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM