I'm using Codeception to test my Yii2 application.
I switched from the default PhpBrowser into PhantomJS 2 as PhpBrowser can't handle native javascript popup such as 'confirm()' for acceptance testing.
so I change my acceptance.suite.yml configuration into this:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- tests\codeception\_support\FixtureHelper
config:
WebDriver:
url: http://www.lppm.local
browser: firefox
window_size: 1366x768
restart: true
and this is my test script:
<?php
use \tests\codeception\_pages\PeriodPage;
$I = new AcceptanceTester\AdminSteps($scenario);
$I->wantTo('Ensure that period access right is working fine');
$I->amGoingTo('Go to period main page');
PeriodPage::openBy($I);
$I->expectTo('See Action Buttons in grid view');
$I->seeElement('.glyphicon-trash');
$I->seeElement('.glyphicon-pencil');
$I->amGoingTo('Create a new period');
$I->click(PeriodPage::$create_button);
$I->seeInCurrentUrl('period/create');
$I->fillField('input[name="Period[name]"]', 'New Period');
$I->fillField('input[name="Period[start_date]"]', '2014-01-01');
$I->fillField('input[name="Period[end_date]"]', '2014-08-01');
$I->click('Create');
$I->expectTo('Redirected to the new period detail page');
$I->seeInCurrentUrl('period/view');
$period_url = $I->grabFromCurrentUrl();
$I->wantTo('Ensure period access right is working fine for normal user');
$normal_user = $I->haveFriend('Normal User');
$normal_user->does(function(\AcceptanceTester\GuestSteps $I) use ($period_url, $scenario){
$I->login('user', 'user');
$I->see('User, '.dropdown-toggle');
$I->wantTo('Ensure that no action button is available in view page');
$I->amOnPage($period_url);
$I->dontSee('.btn');
$I->wantTo('Ensure that no action button is available in index page');
PeriodPage::openBy($I);
$I->dontSee(PeriodPage::$create_button);
$I->dontSeeElement('.glyphicon-trash');
$I->dontSeeElement('.glyphicon-pencil');
});
but I get this error when I run the script with PhantomJS enabled:
There was 1 failure:
--------- 1) Failed to ensure that period access right is working fine in PeriodAccessRightCept (/var/www/lppm/tests/codeception/acceptance/PeriodAccessRightCept.php) Couldn't see element ".glyphicon-trash": Failed asserting that an array is not empty.
this script is working fine when I use PhpBrowser