我最终循环并将失败的密钥存储在逗号分隔的字符串中,并设置一个布尔值来表示发现失败。
$I = new WebGuy($scenario);
$results = $I->getArrayFromDB('talkthrough', '`key`', array());
$failures = "Broken help files are: ";
$failures_found = false;
foreach ($results as $key => $r) {
$I->wantTo('Check helpfile '.$r['key'].'for broken images');
$I->amOnPage('/talkThrough.php?id='.$r['key']);
$allImagesFine = $I->checkAllImages();
if($allImagesFine != '1')
{
$fail = $r['key'].",";
$failures.= $fail;
$failures_found = true;
}
}
$I->seeBrokenImages($failures_found,$failures);
跟随我的网络助手
<?php
namespace Codeception\Module;
// here you can define custom functions for WebGuy
class WebHelper extends \Codeception\Module
{
function checkAllImages()
{
$result = $this->getModule('Selenium2')->session->evaluateScript("return (function(){ return Array.prototype.slice.call(document.images).every(function (img) {return img.complete && img.naturalWidth > 0;}); })()");
return $result;
}
function getArrayFromDB($table, $column, $criteria = array())
{
$dbh = $this->getModule('Db');
$query = $dbh->driver->select($column, $table, $criteria);
$dbh->debugSection('Query', $query, json_encode($criteria));
$sth = $dbh->driver->getDbh()->prepare($query);
if (!$sth) \PHPUnit_Framework_Assert::fail("Query '$query' can't be executed.");
$sth->execute(array_values($criteria));
return $sth->fetchAll();
}
function seeBrokenImages($bool,$failArray)
{
$this->assertFalse($bool,$failArray);
}
}
感谢提交的答案