我正在为我们的内部 CMS 设置大量自动化测试。
此时,我希望能够测试我们的测试页面中是否包含某些图像。
如果图像存在,我可以检查将显示的标题...
$I->see('Image Caption');
...但我真的希望能够检查图像本身的存在...
$I->seeImage('/path_to/image_file.jpg'); // I MADE THAT METHOD UP
...或者至少是 img 标签...
$I->seeSourceCode('<img src="/path_to/image_file.jpg"'); // I MADE THAT METHOD UP TOO
有人知道怎么做吗?
最佳答案
seeElement() 可能适合您的需要,例如:
$I->seeElement('//img[@src="/pixel.jpg"]');
请做see doc
而且,为了使测试更具可读性,我建议将对 seeElement() 的实际调用包装在 helper 中。在测试中有这样的东西
$I->seeImageWithSource('/pixel.jpg')
public function seeImageWithSource($image_url)
{
$phpBrowser = $this->getModule('PhpBrowser');
$phpBrowser->seeElement('//img[@src="'.$image_url.'"]');
}
关于image - 在 Codeception 验收测试中测试图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21095249/