2

重定向后如何正确断言?

$crawler = $client->submit($form);
$client->followRedirect();
//$response = $client->getResponse()->getContent();
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);

调试器显示$response有我期望的内容,foo一句话,但断言失败。

4

1 回答 1

3

将重定向分配给爬虫。试试这个代码:

    $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);

希望这有帮助

于 2016-10-24T18:24:00.537 回答