I am testing a web app with loads and loads of web pages and I would like to verify that none of the URLs are broken on every commit. Here is a code snippet.
$page = $this->getSession()->getPage();
$page_URLs = $page->findAll('css', 'header nav ul a');
assertEquals(16, count($page_URLs));
foreach($page_URLs as $pageUrl){
try{
$pageUrl->click();
$statusCode = $this->getSession()->getStatusCode();
echo $pageUrl->getText();
assertEquals(200, $statusCode, "The webpage is not available");
} catch (Exception $ex) {
echo 'Caught exception: ', $ex->getMessage(), "\n";
}
$this->getSession()->back();
}
I was using the Behat, MINK with Goutte driver (as a headless browser) for CI integration (and getStatusCode() was working fine). But most of the functionality on the web app is java script driven therefore I have to move on to PhantomJS which support javascript. But I didn't realise that getStatusCode() doesn't work with PhantomJS.
Has anyone got any idea if I can replace this with something and get the similar result.