重定向后如何正确断言?
$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);
$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);
希望这有帮助