问题
i created an external class called StringHelper and i putted the require into the _bootstrap.php.
I used it into my acceptance test and it didn't work:
<?php
class StringHelper {
public static function getString($length) {
return "Hello World";
}
}
_bootstrap.php
require_once 'components/StringHelper.php';
My LoginCest.php
<?php
use \AcceptanceTester;
class LoginCest
{
public function test01(AcceptanceTester $I)
{
$I->wantTo('Try to access without permission');
$I->amOnPage('#/list');
$I->waitForText('You don`t have permission.', 10, '.alert');
}
public function test02(AcceptanceTester $I)
{
$I->wantTo(StringHelper::getString(2));
SeleniumHelper::fillField($I, '#desc_login', StringHelper::getString(2));
$I->click("#btn-enter");
$I->waitForText('Please, fill the login field', 10, '.alert');
}
}
My returned message:
Acceptance Tests (2) --------------------------------------------
Trying to Try to access without permission (LoginCest::test01) Ok
Trying to test02 (LoginCest::test02) Ok
Here in "Trying to test02" why doesn't appear "Hello World"?
回答1:
Try to write a module/helper for this function as codeception queues the commands, so when your command is executed codeception is not "listening".
Refer here: http://codeception.com/docs/06-ModulesAndHelpers
来源:https://stackoverflow.com/questions/24491757/how-can-i-use-external-class-in-codeception