如何在Codeception中使用外部类? [英] How can i use external class in Codeception?
本文介绍了如何在Codeception中使用外部类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个名为StringHelper的外部类,并将需求放入_bootstrap.php中。
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
_bootstrap.php
require_once 'components/StringHelper.php';
我的LoginCest.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');
}
}
我返回的消息:
Acceptance Tests (2) --------------------------------------------
Trying to Try to access without permission (LoginCest::test01) Ok
Trying to test02 (LoginCest::test02) Ok
在尝试 test02 中为什么没有出现 Hello World ?
Here in "Trying to test02" why doesn't appear "Hello World"?
推荐答案
在代码接收到命令时尝试为此功能编写模块/帮助程序,因此在执行命令时,代码接收为
Try to write a module/helper for this function as codeception queues the commands, so when your command is executed codeception is not "listening".
在这里参考: http: //codeception.com/docs/06-ModulesAndHelpers
这篇关于如何在Codeception中使用外部类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文