How can i use external class in Codeception?

早过忘川 提交于 2019-12-11 09:59:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!