Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception with PhpBrowser seems to not be following redirects

This is my first time setting up a test suite, so I may be making some stupid blunder.

I just setup Codeception to write some tests for a CodeIgniter project. I have some simple tests working (yay!) but I'm now writing an acceptance test to make sure my login form works. Filling the form and clicking submit works fine, but then when I try to inspect the page after the submit, it appears the redirect is not being followed.

  • The content of the page is empty (node list is empty, log file is 0 bytes)
  • The url of the page is the page I submitted to, not the page I should be redirected to.

The redirect is a 301 header redirect. Edit: FALSE Turns out the auth library I use does a "Reload" header redirect. Using a real 301 fixes the problem.

I assume redirects should be being followed. Is there something I need to setup/configure to get 301 redirects working?

Code:

My acceptance test:

<?php
$I = new WebGuy($scenario);
$I->wantTo('Login');
$I->amOnPage('/');
$I->fillField('identity', '[email protected]');
$I->fillField('password', 'password');
$I->click('submit');
$I->see('Logged In Successfully');

The output when I run the test in debug mode. The InvalidArgumentException error is being thrown because the DOM of the page it's looking at is empty:

Codeception PHP Testing Framework v1.7.1
Powered by PHPUnit 3.7.27 by Sebastian Bergmann.

Acceptance Tests (1) -----------------------
Trying to login (LoginCept.php)
Scenario:
* I am on page "/"
* I fill field "identity","[email protected]"
* I fill field "password","password"
* I click "submit"
* I see "Logged In Successfully"
 ERROR

---------------------------------------------


Time: 3.96 seconds, Memory: 9.75Mb

There was 1 error:

---------
1) Failed to login in LoginCept.php
Sorry, I couldn't see "Logged In Successfully":
InvalidArgumentException: The current node list is empty.

Scenario Steps:
5. I see "Logged In Successfully"
4. I click "submit"
3. I fill field "password","password"
2. I fill field "identity","[email protected]"
1. I am on page "/"


  [InvalidArgumentException]

#1  phar:///Users/captbaritone/Projects/codeception/codecept.phar/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Crawler.php:494
#2  phar:///Users/captbaritone/Projects/codeception/codecept.phar/vendor/behat/mink-browserkit-driver/src/Behat/Mink/Driver/BrowserKitDriver.php:348
#3  phar:///Users/captbaritone/Projects/codeception/codecept.phar/vendor/behat/mink/src/Behat/Mink/Element/Element.php:101
#4  phar:///Users/captbaritone/Projects/codeception/codecept.phar/src/Codeception/Util/Mink.php:208
#5  phar:///Users/captbaritone/Projects/codeception/codecept.phar/src/Codeception/Util/Mink.php:181
#6  phar:///Users/captbaritone/Projects/codeception/codecept.phar/src/Codeception/Step.php:133
#7  phar:///Users/captbaritone/Projects/codeception/codecept.phar/src/Codeception/TestCase.php:31
#8  phar:///Users/captbaritone/Projects/codeception/codecept.phar/src/Codeception/Scenario.php:87
#9  /Users/captbaritone/Projects/codeception/tests/acceptance/WebGuy.php:571
#10 /Users/captbaritone/Projects/codeception/tests/acceptance/LoginCept.php:8

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
like image 502
Jordan Eldredge Avatar asked Oct 18 '13 22:10

Jordan Eldredge


1 Answers

Turns out this was caused by the fact that Ion Auth uses a "Reload" header instead of a "Location" header for it's redirects. For some reason Codeception (or perhaps the underlying PhpBrowser) is not obeying that form of redirect. If I change it to a "Location" header redirect, the test passes.

I've started another issue for figuring out why the "Reload" redirect does not work. You can find it here: Why doesn't Codeception's PhpBrowser follow a "Reload" header?

like image 53
Jordan Eldredge Avatar answered Sep 30 '22 08:09

Jordan Eldredge