I use a simple acceptance test that does the following:
Each functionality is tested in several steps, for example -
...
$I->wantTo('Try to login with right credentials'); // step 1
$I->amOnPage('/user/login'); // step 2
$I->fillField('#login-form-login','admin'); // step 3
$I->fillField('#login-form-password','admin'); // step 4
$I->click('#login-form button[type=submit]'); // step 5
$I->seeCurrentUrlEquals('/user/admin'); // step 6
...
I want to know how long performed each set of steps/ individual step.
Since all the functions are collected together in one test, the result of running this command is present a report that shows the time that was spent on the entire test as a whole.
codecept run acceptance --html
Is it possible in Codeception make group of steps (some markers, may be..) and show time that spent for perform these groups?
You can add the following code to the FunctionalTester
or helper class:
class FunctionalTester extends \Codeception\Actor {
...
private $firstTimeTag;
private $secondTimeTag;
public function markFirstTimeTag()
{
$this->firstTimeTag = new DateTime();
}
public function markSecondTimeTag()
{
$this->secondTimeTag = new DateTime();
}
public function calculateTheDiffFor($step)
{
echo $step.": ". round($this->secondTimeTag->getTimestamp() -
$this->firstTimeTag->getTimestamp(), 3). " s\n";
}
...
}
And then use this actions in Cept/ Cest files:
$I->wantTo('Try to login with right credentials'); // step 1
$I->markFirstTimeTag();
$I->amOnPage('/user/login'); // step 2
$I->fillField('#login-form-login','admin'); // step 3
$I->fillField('#login-form-password','admin'); // step 4
$I->click('#login-form button[type=submit]'); // step 5
$I->markSecondTimeTag();
$I->calculateTheDiffFor("Login attempt");
$I->seeCurrentUrlEquals('/user/admin'); // step 6
The output can be seen in the Jenkin's logs, for example.