Cannot use Step Object in Cest Codeception

Solution 1:

It looks like that you want to use the Helper functionality in Codeception.

Just find the correct helper class. The default one is tests/_support/Helper/Acceptance.php and add your method there...

<?php 

namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

use Codeception\Module;

class Acceptance extends Module
{
    public function loginAsAdmin()
    {
        // ... your login here
    }
}

Make sure that the helper is activated in your codeception.yml and also be aware of to run the codecept build command to regenerate the auto-generated AcceptanceTester class. If you need the AcceptanceTester class to do assertions, you can add it as one function parameter.

If anything works as expected, you can just use your AcceptanceTester in your Cest without any extra dependency injection:

class UserCest
{
    function showUserProfile(AcceptanceTester $I)
    {
        $I->loginAsAdmin();
    }
}