Debugging tests can often be a pain, but using those snippets it's possible to get a lot of informations when using WebTestCase
or PantherTestCase
.
Sometimes you'll want to inspect the HTML of the page or a specific element. There is no official method for this yet but the following works:
$crawler = $client->request('GET', '/my-url/');
file_put_contents('public/debug.html', $client->getResponse());
Your test will now fail with an HTML page generated and accessible on http//app.test/debug.html.
If you want to see a screenshot to work out what is going on when your tests fails
/**
* @AfterStep
*/
public function takeScreenshotOnFailur(AfterStepScope $event) {
if ($event->getTestResult()->isPassed) {
return;
}
file_put_contents('public/debug.html', self::$pantherClient->getPageSource());
self::$patherClient->takeScreenshot('public/debug.png');
}
Your test will now fail with an HTML page generated and accessible on http//app.test/debug.html and http//app.test/debug.png.