Last Updated: February 25, 2016
·
1.813K
· davert

Codeception: Cest Format Example

In case you need few very similar acceptance tests in Codeception...

When you got a few tests that follow a common path, you can use Cest format to move that
common parts into protected methods and use them in tests:

<?php

class FormCest {

    // test #1
    public function purchaseWithValidCard($I)
    {
        $this->fillForm($I, '1233 3453 2342 2343', 'jon@doe.com');
        $I->see('Thank you for your order');
    }

    // test #2
    public function purchaseWithInvalidCard($I)
    {
        $this->fillForm($I, 'xxxxxx', 'jon@doe.com');
        $I->see('Sorry, your crdit card is invalid');
    }

    // common method used by both tests
    protected function fillForm($I, $credit, $email)
    {
        $I->amOnPage('/purchase');
        $I->fillField('Credit Card', $credit);
        $I->fillField('Email', $email);
        $I->click('Order');
    }

}

2 Responses
Add your response

$I->fillField('Email', $credit);
must be
$I->fillField('Email', $email);

over 1 year ago ·

Oh. thanks )

over 1 year ago ·