Codeception see() method with Yii2 does not display all page content

Asked

Viewed 29 times

0

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

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

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

Following the functional test code 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!

1 answer

0

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

Example of the site:

<?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:

  • Yes, I am doing this because successively I want to test other more complex features. By default comes functional login tests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.