Sunday, November 2, 2014

Creation Of Cest

Ever wanted a structure as classes for your Cepts!
Then Cest format should be your choice.
The biggest advantage is that it is very simple and compatibility with Cept scenarios.
So if your script/test is bit lengthy and you need to split it then you can approach the cest approach.

Just create a new cest file by running the command in console as :
$ php codecept.phar generate:cest suitename CestName

The generated file will look like this:

<?php
class Mytest
{
    public function _before(\AcceptanceTester $I)
    {
    }

    public function _after(\AcceptanceTester $I)
    {
    }

    // tests
    public function actualtest(\AcceptanceTester $I)
    {  
    }
}
?>

Here in the above file the _before and _after annotations are used for the setup and flow of test execution.
So _before will prepare the test set up before the test execution.
And _after will prepare the generation of falied reports,generation of reports etc.

We will pass the actor objects to actualtest method.

<?php
class Mytest
{
    // test
    public function myLogin(\AcceptanceTester $I)
    {
        $I->wantTo('log in to site');
        $I->amOnPage('/');
        $I->click('Login');
        $I->fillField('username', 'test');
        $I->fillField('password', 'password');
        $I->click('Login');
        $I->see('Home');
        $I->seeInCurrentUrl('/home');
    }
}
?>

0 comments:

Post a Comment

Powered by Blogger.