Custom event error while testing with Codeception

I’m having the same error every time I run Codeception acceptance tests more than once in Yii2.

Below is the error stack :

[UnknownServerException] Error Message => ‘URL ‘((h.t.t.p))://localhost/project/backend/web/index.php/user/list’ didn’t load. Error: ‘ReferenceError: Can’t find variable: CustomEvent’’ caused by 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”:{“anchor”:"",“query”:"",“file”:“url”,“directory”:"/",“path”:"/url",“relative”:"/url",“port”:"",“host”:"",“password”:"",“user”:"",“userInfo”:"",“authority”:"",“protocol”:"",“source”:"/url",“queryKey”:{},“chunks”:[“url”]},“urlOriginal”:"/session/3f1a3090-e4fc-11e4-acf5-cdfb0adce833/url"}

And thats the Cest class code (I dont think that the problem will be into the code):




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);

}


}



Any JavaScript error at console.