这是我第一次设置测试套件,所以我可能会犯一些愚蠢的错误。
我只是设置Codeception来为CodeIgniter项目编写一些测试。我有一些简单的测试工作(耶!)但我现在正在编写验收测试以确保我的登录表单有效。填写表单并单击提交工作正常,但是当我在提交后尝试检查页面时,似乎没有遵循重定向。
重定向是301标头重定向。 编辑:FALSE 关闭我使用的auth库执行“重新加载”标头重定向。使用真正的301解决了这个问题。
我认为应该遵循重定向。我需要设置/配置以使301重定向工作吗?
我的验收测试:
<?php
$I = new WebGuy($scenario);
$I->wantTo('Login');
$I->amOnPage('/');
$I->fillField('identity', 'manager@example.com');
$I->fillField('password', 'password');
$I->click('submit');
$I->see('Logged In Successfully');
我在调试模式下运行测试时的输出。抛出InvalidArgumentException
错误,因为它正在查看的页面的DOM是空的:
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","manager@example.com"
* 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","manager@example.com"
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.
答案 0 :(得分:4)
原来这是因为Ion Auth使用“重新加载”标题而不是“位置”标题进行重定向。由于某种原因,Codeception(或者可能是底层的PhpBrowser)不遵循这种形式的重定向。如果我将其更改为“Location”标题重定向,则测试通过。
我已经开始了另一个问题,弄清楚为什么“重新加载”重定向不起作用。您可以在此处找到它:Why doesn't Codeception's PhpBrowser follow a "Reload" header?