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');
}
}
Written by Michael Bodnarchuk
Related protips
2 Responses
$I->fillField('Email', $credit);
must be
$I->fillField('Email', $email);
over 1 year ago
·
Oh. thanks )
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#