Behat - 检查图像链接是否损坏

时间:2015-07-26 11:00:30

标签: php testing behat

有没有办法检查Behat,如果在页面上没有包含损坏/损坏链接的图像?

1 个答案:

答案 0 :(得分:3)

我建议在页面上找到所有图片

$imageElements = $this->getSession()->getPage()->findAll('css','img');
foreach($imageElements as $image){
    $imgUrl = $image->getAttribute('src');
    $this->visit($imgUrl);
    //Here should be assertion of valid img,
    //F.e. if you are using goutte driver check that server response is not 500 or 404
    $this->assertResponseStatusIsNot(404);
}