重定向后如何正确断言?
$crawler = $client->submit($form);
$client->followRedirect();
//$response = $client->getResponse()->getContent();
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);
调试器显示 $response
具有我期望的内容,带有 foo
单词,但断言失败。
最佳答案
将重定向分配给爬网程序。 尝试使用以下代码:
$crawler = $client->submit($form);
$this->assertTrue($client->getResponse()->isRedirect(),'Submit ok');
// Assign the redirect to the crawler
$crawler = $client->followRedirect();
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Correct redirect to page ok");
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);
希望这有帮助
关于symfony - 如何检查重定向后的站点?多姆·克劳勒。功能测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40224128/