这是我第一次设置测试套件,所以我可能会犯一些愚蠢的错误。
我只是设置 Codeception 为 CodeIgniter 项目编写一些测试。我有一些简单的测试工作(耶!)但我现在正在编写验收测试以确保我的登录表单有效。填写表单并单击提交工作正常,但是当我尝试在提交后检查页面时,似乎没有遵循重定向。
- 页面内容为空(节点列表为空,日志文件为0字节)
- 页面的 url 是我提交的页面,而不是我应该重定向到的页面。
重定向是 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.