2

每次在 Yii2 中多次运行 Codeception 验收测试时,我都会遇到相同的错误。

下面是错误堆栈:

[UnknownServerException] 错误消息 => 'URL' http://localhost/project/backend/web/index.php/user/list' 未加载。错误:'ReferenceError:找不到变量:CustomEvent'' 由 Request => {"headers":{"Accept":"application/json","Content-Length":"85","Content-Type" 引起:"application/json;charset=UTF-8","Host":"127.0.0.1:4444"},"httpVersion":"1.1","method":"POST","post":"{\" url\":\"http:\/\/localhost\/project\/backend\/web\/index.php\/user\/list\"}","url":"/url","urlParsed" :{"锚点":"","查询":"","文件":"url","目录":"/","路径":"/url","

这就是 Cest 类代码(我认为问题不会出现在代码中):

use \AcceptanceTester;
use \Yii;

class CreateUserCest
{

// private $username;
// private $email;

## I don't think this work, but neither is the problem (if I commented it the error persists)
public function _before(AcceptanceTester $I)
{
    try{
        $this->login($I, 'admin@admin.com', 'foobar');        
    }catch(Exception $e){
        $I->amGoingTo('Jump login cuz Im already logged');
    }
}

public function _after(AcceptanceTester $I)
{
}

private function login(AcceptanceTester $I, $email, $password)
{
    $I->amOnPage('/backend/web/index.php/site/login');
    $I->amGoingTo('Log in the application');
    $I->see("Login");
    $I->fillField("#loginform-email", $email);
    $I->fillField("#loginform-password", $password);
    $I->click('Login');
    $I->see(Yii::t('app', 'Go to').' backoffice'); // We are succesfull logued
}

// Just username, email and password
public function createEmptyOne(AcceptanceTester $I)
{
    $username = "UsuarioTest".rand(1, 10000);
    $email = "UsuarioTest".rand(1, 10000)."@test.com";

    $I->amGoingTo("Create a user with the basic data (username, email, password)");
    $I->amOnPage("/backend/web/index.php/user/create"); ## 16/04/2015 Page loading never ends because of JS error
    $I->fillField("#signupform-username", $username);
    $I->fillField("#signupform-email", $email);
    $I->fillField("#signupform-password", 'attime7931');
    // $I->click(Yii::t('app', 'Confirm'));
    $I->click('Confirmar');
    $I->seeInDatabase('user', ['username' => $username, 'email' => $email]);
}

// List users
public function listUsers(AcceptanceTester $I)
{
    $username = "UsuarioTest".rand(1, 10000);
    $email = "UsuarioTest".rand(1, 10000)."@test.com";

    $I->amGoingTo("List users");
    $I->haveInDatabase('user', array('username' => $username, 'email' => $email));
    $I->amOnPage("/backend/web/index.php/user/list");
    $I->seeInCurrentUrl('/user/list');
    $I->see('Crear usuario');
    // $I->see(Yii::t('app', 'Create User'));
    // $I->see($username);
    $I->see($email);
}

public function updateUser(AcceptanceTester $I)
{
    $username = "UsuarioTest".rand(1, 10000);
    $email = "UsuarioTest".rand(1, 10000)."@test.com";
    $I->haveInDatabase('user', array('username' => $username, 'email' => $email));
    $id = $I->grabFromDatabase('user', 'id', ['username' => $username, 'email' => $email]);

    $I->amGoingTo("Update user with id $id");
    $I->amOnPage("/backend/web/index.php/user/update/$id");
    $I->see('Datos principales');
    $I->see($username);
    $I->see($email);
}

}

我在 Chrome 控制台上收到此错误(我也尝试在 Firefox 中运行测试,它返回相同的结果):

未捕获的类型错误:未定义不是函数

当我点击错误时,它指向这一行

jQuery('#w0').yiiGridView({"filterUrl":"/project/backend/web/index.php/user/list","filterSelector":"#w0-filters input, #w0-filters select"} );

编辑

我试图通过将 jQuery-2.1.3.min.js 添加到我的 AppAsset 来修复 yiiGridView 错误,以避免在 yiiGridView 脚本之后重新加载。并且错误仍然存​​在

第二次编辑 我已经修复了 yiiGridView 错误并且自定义事件错误仍然存​​在。原因必须是另一个

4

0 回答 0