Can you name the scripts as steps in Behat 3?

When writing functional tests, some parts are repeated quite often. For example, users logging in:

I go to "/login"
I fill in "login" with "username"
I fill in "password" with "password"
I press "Login"

I would like to define these steps as:

Given I am logged in as "userA" 

Now on Behat 2.x I would define a step in php:

return array(
    new Step\Given('I go to "/login"'), 
    new Step\Then('I fill in "login" with "username"'), 
    new Step\Then('I fill in "password" with "password"'), 
    new Step\Then('I press "Login"'), 
);

Is this behavior still encouraged for Behat 3? Is there a better way to do this?

+4
source share
1 answer

This is called a chain of steps , and it was removed in Behat 3. Here is the original answer from Beh Creator.

MinkContext, , , , . , , :

class FeatureContext extends MinkContext
{
    /**
     * @Given I am logged in as :user
     */
    public function iAmLoggedInAsUser($user)
    {
        $this->visit('/login');
        $this->fillField('login', 'username');
        $this->fillField('password', 'password');
        $this->pressButton('Login');
        // make assertion to be sure user is logged in
    }
}

, Behat -

+7

Source: https://habr.com/ru/post/1569115/


All Articles