Codeception: [Yii2] Page not found in functional tests after update to 2.4.1

What are you trying to achieve?

Run this relatively simple test

        $user = $I->grabFixture('user', 'user1');
        $I->amOnPage('ru/user/login');
        $I->see('Авторизоваться', 'h2');
        $I->wantTo('ensure that login is successful');
        $I->submitForm('form#login-form', [
            'login-form[login]' => $user->username,
            'login-form[password]' => 'test',            
        ]);
        $I->seeElement('a.logout');
        $I->seeElement('.page_user_name');

What do you get instead?

Red test with error in output file <pre>Not found: Страница не найдена. </pre>. In 2.4.0 it was green. Interesting thing.

$I->amOnPage('ru/user/login');

This instruction executes successfully. But suddenly submitting on the same url says page not found. How this can be understandable?

Details

  • Codeception version: 2.4.1
  • PHP Version: 7.2
  • Operating System: Docker Alpine
  • Installation type: Composer
  • List of installed packages (composer show)
  • Suite configuration:
class_name: FunctionalTester
modules:
    enabled:
      - Filesystem
      - Yii2
      - REST
      - Asserts
    config:
        Yii2:
            configFile: 'tests/codeception/_config/functional.php'
            transaction: true
            cleanup: false
        REST:
            depends: Yii2

Debug execution:

LoginCest: Ensure that login is successful
Signature: LoginCest:successLogin
Test: tests/codeception/functional/LoginCest.php:successLogin
Scenario --
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [Fixtures] Done
 I have fixtures {"user":"tests\\codeception\\unit\\fixtures\\UserFixture"}
 I grab fixture "user","user1"
 I am on page "ru/user/login"
  [Request Headers] []
  [yii\web\Session::open] 'Session started'

  [Page] ru/user/login
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I see "Авторизоваться","h2"
 I submit form "form#login-form",{"login-form[login]":"test@test.test","login-form[password]":"...}
  [Uri] http://localhost/ru/user/login
  [Method] POST
  [Parameters] {"login-form[login]":"test@test.test","login-form[password]":"test"}
  [Request Headers] []
  [yii\web\HttpException:404] 'yii\\base\\InvalidRouteException: Unable to resolve the request "ru/user/login". in /app/vendor/yiisoft/yii2/base/Module.php:537
  Stack trace:
  #0 /app/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction(\'ru/user/login\', Array)
  #1 /app/vendor/codeception/codeception/src/Codeception/Lib/Connector/Yii2.php(135): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))
  #2 /app/vendor/symfony/browser-kit/Client.php(312): Codeception\\Lib\\Connector\\Yii2->doRequest(Object(Symfony\\Component\\BrowserKit\\Request))
  #3 /app/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(193): Symfony\\Component\\BrowserKit\\Client->request(\'POST\', \'http://localhos...\', Array, Array, Array, \'login-form%5Blo...\', true)
  #4 /app/vendor/codeception/codeception/src/Codeception/Module/Yii2.php(670): Codeception\\Lib\\InnerBrowser->clientRequest(\'POST\', \'http://localhos...\', Array, Array, Array, \'login-form%5Blo...\', true)
  #5 /app/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(857): Codeception\\Module\\Yii2->clientRequest(\'POST\', \'http://localhos...\', Array, Array)
  #6 /app/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(868): Codeception\\Lib\\InnerBrowser->proceedSubmitForm(Object(Symfony\\Component\\DomCrawler\\Crawler), Array, NULL)
  #7 [internal function]: Codeception\\Lib\\InnerBrowser->submitForm(\'form#login-form\', Array)
  #8 /app/vendor/codeception/codeception/src/Codeception/Step.php(264): call_user_func_array(Array, Array)
  #9 /app/vendor/codeception/codeception/src/Codeception/Scenario.php(72): Codeception\\Step->run(Object(Codeception\\Lib\\ModuleContainer))
  #10 /app/tests/codeception/_support/_generated/FunctionalTesterActions.php(2133): Codeception\\Scenario->runStep(Object(Codeception\\Step\\Action))
  #11 /app/tests/codeception/functional/LoginCest.php(26): FunctionalTester->submitForm(\'form#login-form\', Array)
  #12 [internal function]: LoginCest->successLogin(Object(FunctionalTester))
  #13 /app/vendor/codeception/codeception/src/Codeception/Lib/Di.php(127): ReflectionMethod->invokeArgs(Object(LoginCest), Array)
  #14 /app/vendor/codeception/codeception/src/Codeception/Test/Cest.php(138): Codeception\\Lib\\Di->injectDependencies(Object(LoginCest), \'successLogin\', Array)
  #15 /app/vendor/codeception/codeception/src/Codeception/Test/Cest.php(150): Codeception\\Test\\Cest->invoke(\'successLogin\', Array)
  #16 /app/vendor/codeception/codeception/src/Codeception/Test/Cest.php(82): Codeception\\Test\\Cest->executeTestMethod(Object(FunctionalTester))
  #17 /app/vendor/codeception/codeception/src/Codeception/Test/Test.php(89): Codeception\\Test\\Cest->test()
  #18 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(760): Codeception\\Test\\Test->run(Object(PHPUnit\\Framework\\TestResult))
  #19 /app/vendor/codeception/phpunit-wrapper/src/Runner.php(114): PHPUnit\\Framework\\TestSuite->run(Object(PHPUnit\\Framework\\TestResult))
  #20 /app/vendor/codeception/codeception/src/Codeception/SuiteManager.php(157): Codeception\\PHPUnit\\Runner->doEnhancedRun(Object(Codeception\\Suite), Object(PHPUnit\\Framework\\TestResult), Array)
  #21 /app/vendor/codeception/codeception/src/Codeception/Codecept.php(189): Codeception\\SuiteManager->run(Object(Codeception\\PHPUnit\\Runner), Object(PHPUnit\\Framework\\TestResult), Array)
  #22 /app/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception\\Codecept->runSuite(Array, \'functional\', \'LoginCest\')
  #23 /app/vendor/codeception/codeception/src/Codeception/Command/Run.php(355): Codeception\\Codecept->run(\'functional\', \'LoginCest\', Array)
  #24 /app/vendor/symfony/console/Command/Command.php(252): Codeception\\Command\\Run->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #25 /app/vendor/symfony/console/Application.php(865): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #26 /app/vendor/symfony/console/Application.php(241): Symfony\\Component\\Console\\Application->doRunCommand(Object(Codeception\\Command\\Run), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #27 /app/vendor/symfony/console/Application.php(143): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #28 /app/vendor/codeception/codeception/src/Codeception/Application.php(108): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #29 /app/vendor/codeception/codeception/codecept(42): Codeception\\Application->run()
  #30 {main}

  Next yii\\web\\NotFoundHttpException: Страница не найдена. in /app/vendor/yiisoft/yii2/web/Application.php:115
  Stack trace:
  #0 /app/vendor/codeception/codeception/src/Codeception/Lib/Connector/Yii2.php(135): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))
  #1 /app/vendor/symfony/browser-kit/Client.php(312): Codeception\\Lib\\Connector\\Yii2->doRequest(Object(Symfony\\Component\\BrowserKit\\Request))
  #2 /app/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(193): Symfony\\Component\\BrowserKit\\Client->request(\'POST\', \'http://localhos...\', Array, Array, Array, \'login-form%5Blo...\', true)
  #3 /app/vendor/codeception/codeception/src/Codeception/Module/Yii2.php(670): Codeception\\Lib\\InnerBrowser->clientRequest(\'POST\', \'http://localhos...\', Array, Array, Array, \'login-form%5Blo...\', true)
  #4 /app/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(857): Codeception\\Module\\Yii2->clientRequest(\'POST\', \'http://localhos...\', Array, Array)
  #5 /app/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(868): Codeception\\Lib\\InnerBrowser->proceedSubmitForm(Object(Symfony\\Component\\DomCrawler\\Crawler), Array, NULL)
  #6 [internal function]: Codeception\\Lib\\InnerBrowser->submitForm(\'form#login-form\', Array)
  #7 /app/vendor/codeception/codeception/src/Codeception/Step.php(264): call_user_func_array(Array, Array)
  #8 /app/vendor/codeception/codeception/src/Codeception/Scenario.php(72): Codeception\\Step->run(Object(Codeception\\Lib\\ModuleContainer))
  #9 /app/tests/codeception/_support/_generated/FunctionalTesterActions.php(2133): Codeception\\Scenario->runStep(Object(Codeception\\Step\\Action))
  #10 /app/tests/codeception/functional/LoginCest.php(26): FunctionalTester->submitForm(\'form#login-form\', Array)
  #11 [internal function]: LoginCest->successLogin(Object(FunctionalTester))
  #12 /app/vendor/codeception/codeception/src/Codeception/Lib/Di.php(127): ReflectionMethod->invokeArgs(Object(LoginCest), Array)
  #13 /app/vendor/codeception/codeception/src/Codeception/Test/Cest.php(138): Codeception\\Lib\\Di->injectDependencies(Object(LoginCest), \'successLogin\', Array)
  #14 /app/vendor/codeception/codeception/src/Codeception/Test/Cest.php(150): Codeception\\Test\\Cest->invoke(\'successLogin\', Array)
  #15 /app/vendor/codeception/codeception/src/Codeception/Test/Cest.php(82): Codeception\\Test\\Cest->executeTestMethod(Object(FunctionalTester))
  #16 /app/vendor/codeception/codeception/src/Codeception/Test/Test.php(89): Codeception\\Test\\Cest->test()
  #17 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(760): Codeception\\Test\\Test->run(Object(PHPUnit\\Framework\\TestResult))
  #18 /app/vendor/codeception/phpunit-wrapper/src/Runner.php(114): PHPUnit\\Framework\\TestSuite->run(Object(PHPUnit\\Framework\\TestResult))
  #19 /app/vendor/codeception/codeception/src/Codeception/SuiteManager.php(157): Codeception\\PHPUnit\\Runner->doEnhancedRun(Object(Codeception\\Suite), Object(PHPUnit\\Framework\\TestResult), Array)
  #20 /app/vendor/codeception/codeception/src/Codeception/Codecept.php(189): Codeception\\SuiteManager->run(Object(Codeception\\PHPUnit\\Runner), Object(PHPUnit\\Framework\\TestResult), Array)
  #21 /app/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception\\Codecept->runSuite(Array, \'functional\', \'LoginCest\')
  #22 /app/vendor/codeception/codeception/src/Codeception/Command/Run.php(355): Codeception\\Codecept->run(\'functional\', \'LoginCest\', Array)
  #23 /app/vendor/symfony/console/Command/Command.php(252): Codeception\\Command\\Run->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #24 /app/vendor/symfony/console/Application.php(865): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #25 /app/vendor/symfony/console/Application.php(241): Symfony\\Component\\Console\\Application->doRunCommand(Object(Codeception\\Command\\Run), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #26 /app/vendor/symfony/console/Application.php(143): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #27 /app/vendor/codeception/codeception/src/Codeception/Application.php(108): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
  #28 /app/vendor/codeception/codeception/codecept(42): Codeception\\Application->run()
  #29 {main}'
  [Page] http://localhost/ru/user/login
  [Response] 404
  [Request Cookies] {"_language":"9457c7cc6ba7cdebe752c3e019d54725c71b7b993a2dda03ec553019f8711243a:2:{i:0;s:9:"_language";i:1;s:2:"ru";}"}
  [Response Headers] {"content-type":["text/html; charset=UTF-8"]}
 I see element "a.logout"
 FAIL

  Destroying application
  Suite done, restoring $_SERVER to original
----------------------------------------------------------------------------------------------------------------


Time: 12.54 seconds, Memory: 10.00MB

There was 1 failure:

---------
1) LoginCest: Ensure that login is successful
 Test  tests/codeception/functional/LoginCest.php:successLogin
 Step  See element "a.logout"
 Fail  Element located either by name, CSS or XPath element with 'a.logout' was not found.

Scenario Steps:

 6. $I->seeElement("a.logout") at tests/codeception/functional/LoginCest.php:28
 5. $I->submitForm("form#login-form",{"login-form[login]":"test@test.test","login-form[password]":...}) at tests/codeception/functional/LoginCest.php:26
 4. $I->see("Авторизоваться","h2") at tests/codeception/functional/LoginCest.php:20
 3. $I->amOnPage("ru/user/login") at tests/codeception/functional/LoginCest.php:19
 2. $I->grabFixture("user","user1") at tests/codeception/functional/LoginCest.php:18
 1. $I->haveFixtures({"user":"tests\\codeception\\unit\\fixtures\\UserFixture"}) at tests/codeception/functional/LoginCest.php:10


FAILURES!
Tests: 1, Assertions: 2, Failures: 1.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 27

Most upvoted comments

Okay, I found the issue, but it seems to be related to that library. What happens is that the component changes its state internally; it sets a processed flag here.

This means that on the second request no processing happens which causes your error.

Still looking into where / how to best fix it.

@samdark it means it won’t be fixed? or what?

P.S. ok, I see PR is merged.