我正在为我们的内部CMS设置一系列自动化测试.
在这个时刻,我希望能够测试我们的测试页面中是否有某些图像.
如果图像存在,我可以检查将显示的标题...
$I->see('Image Caption');
Run Code Online (Sandbox Code Playgroud)
...但我真的希望能够检查图像本身的存在......
$I->seeImage('/path_to/image_file.jpg'); // I MADE THAT METHOD UP
Run Code Online (Sandbox Code Playgroud)
......或者至少是img标签......
$I->seeSourceCode('<img src="/path_to/image_file.jpg"'); // I MADE THAT METHOD UP TOO
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做到这一点?
seeElement()可能符合你的需要,例如:
$I->seeElement('//img[@src="/pixel.jpg"]');
请看看doc
,为了让测试更具可读性,我建议在helper中包含对seeElement()的实际调用,并在测试中有类似这样的东西
$I->seeImageWithSource('/pixel.jpg')
public function seeImageWithSource($image_url)
{
$phpBrowser = $this->getModule('PhpBrowser');
$phpBrowser->seeElement('//img[@src="'.$image_url.'"]');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3104 次 |
| 最近记录: |