Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). And how can I access my functions from StepObjects?

I have:

acceptance/_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.

I know I can get a specific module (e.g. the WebDriver) with $this->getModule('WebDriver'). But how can I get the AcceptanceTester / my StepObject?

like image 252
mcode Avatar asked Oct 02 '14 11:10

mcode


People also ask

What is Codeception in yii2?

Yii Framework provides basic and advanced application templates. Both include sample Codeception tests, thus to start with Codeception you need to start new Yii project from a one of those templates.

Which Codeception method may be used to check that a variable is greater than expected?

assertGreaterThanOrEqual. Asserts that a value is greater than or equal to another value.


1 Answers

Passing in the $I variable from the test. It's a bit verbose but works fine.

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

and then in tests write:

$I->deleteCookies($I);

like image 51
dwenaus Avatar answered Oct 07 '22 01:10

dwenaus