Search code examples
behatminkgoutte

Check HTTP status in cycle. Behat + Mink, Goutte driver


I try to check HTTP status in cycle:

foreach ($arrayOfLinks as $link) {

    $this->getMainContext()->getSubcontext('mink')->visit($link);
    $statusCode = $this->getSession()->getStatusCode();
    if ($statusCode < 200 || $statusCode > 299) {
        print 'Broken link ' . $href . ' status code is ' . $statusCode . "\n";
    }

}

In the cycle it does not work consistently. It successfully checks about 20-40 links and then fails with error

The current node list is empty.

How can I fix it and what means this error?


Solution

  • I resolved problem. When I looking for all links on page and check status in the same foreach - I get error. When I split cycle into two cycles - it works