Codeception's see () method with Yii2 does not display the entire content of the page

0

Hello! I'm testing a PHP system (7.2.1) that uses the Yii2 framework, and for that, by default I'm using codeception.

When writing functional tests, several methods are not working as expected. Among them is the see () method that should fetch text passed as a parameter on the specified page. In my case the see () method searches only the side menu of the application, not the page as a whole.

I would like help to try to solve this error, I already researched the framework documentation but could not find anything related to my problem.

Following is the code for the functional tests I wrote and the error displayed on the console.

Test class:

<?php

use app\models\Usuario;

class FirstTryLoginCest
{

    public function _before(\FunctionalTester $I)
    {
        $I->amOnRoute('site/login');
    }

    public function submitFormSuccessfully(\FunctionalTester $I)
    {
        $I->submitForm('#login-form', [
            '#usuario-username' => 'Fulano',
            '#usuario-password' => '12345678'
        ]);
        $I->see('Mural');
    }

    public function internalLoginByInstance(\FunctionalTester $I)
    {
        $admin = \app\models\Usuario::findOne(33);
        $I->amLoggedInAs($admin);
        $I->amOnPage('gestor/mural');
        $I->see('Fulano');
    }

}

Error displayed on console:

Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 7.1.5 by Sebastian Bergmann and contributors.

Functional Tests (2) -------------------------------------------------- 
✖ FirstTryLoginCest: Submit form successfully (0.14s)
✖ FirstTryLoginCest: Internal login by instance (0.07s)
----------------------------------------------------------------------- 

Unit Tests (0) -------------------------------------------------------- 
----------------------------------------------------------------------- 

Time: 464 ms, Memory: 16.00MB

There were 2 failures:

---------
1) FirstTryLoginCest: Submit form successfully
Test  tests/functional/FirstTryLoginCest.php:submitFormSuccessfully
Step  See "Mural"
Fail  Failed asserting that  on page /index-test.php?r=site%2Flogin
-->  Username cannot be blank. Password cannot be blank. Lembrar no 
próximo acesso Entrar Esqueci minha senha Copyright &COPY; 2018 Nome da 
empresa 
--> contains "Mural".

Scenario Steps:

3. $I->see("Mural") at tests/functional/FirstTryLoginCest.php:19
2. $I->submitForm("#login-form",{"#usuario- 
username":"Fulano","#usuario-password":"12345678"}) at 
tests/functional/FirstTryLoginCest.php:16
1. $I->amOnRoute("site/login") at 
tests/functional/FirstTryLoginCest.php:10


---------
2) FirstTryLoginCest: Internal login by instance
Test  tests/functional/FirstTryLoginCest.php:internalLoginByInstance
Step  See "Fulano"
Fail  Failed asserting that  on page /gestor/mural
-->  Toggle navigation Fulano Fulano Fulaninho Administrador 
Perfil Sair Fulano Gii Debug Same tools Gii Debug Level One Level Two 
Level Two Level Three Level Three Nome da empresa &COPY; 2018   Nome da 
empresa Software Versão 9.0 β string(1) "0" 
--> contains "Fulano".

Scenario Steps:

4. $I->see("Fulano") at tests/functional/FirstTryLoginCest.php:29
3. $I->amOnPage("gestor/mural") at 
tests/functional/FirstTryLoginCest.php:28

Thank you in advance!

    
asked by anonymous 22.05.2018 / 21:33

1 answer

0

You are testing your login page with a functional test class, but the correct one, according to the Codeception documentation, is to use the acceptance class ( \ AcceptanceTests ).

Site example:

<?php
class BasicCest
{
    // test
    public function tryToTest(\AcceptanceTester $I)
    {
        $I->amOnPage('/');
        $I->click('Login');
        $I->fillField('username', 'john');
        $I->fillField('password', 'coltrane');
        $I->click('Enter');
        $I->see('Hello, John');
        $I->seeInCurrentUrl('/account');
    }
}

Sources:

22.05.2018 / 21:46