8

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?

mcode
  • 534
  • 4
  • 18

1 Answers1

4

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);

dwenaus
  • 3,206
  • 2
  • 27
  • 27