0

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.

vijay pujar
  • 1,683
  • 4
  • 19
  • 32

1 Answers1

0

PhantomJS support in Behat is realised via the WebDriver protocol (selenium). WebDriver doesn't support inspecting status codes on purpose, as it falls out of scope of emulating user actions.

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
  • That's great. Thanks for confirming that Jakub. On a different note if I loop through different parts of the app, how can I make sure the pages are not broken. – vijay pujar Aug 21 '14 at 08:24