理想情况下,还可以在图像查看器中自动打开屏幕截图。
问问题
4385 次
2 回答
17
编辑:感谢 bishop 关于打开应用程序的提示。不过,仍然不确定如何在 Windows 上做到这一点。
/**
* This works for Selenium and other real browsers that support screenshots.
*
* @Then /^show me a screenshot$/
*/
public function show_me_a_screenshot() {
$image_data = $this->getSession()->getDriver()->getScreenshot();
$file_and_path = '/tmp/behat_screenshot.jpg';
file_put_contents($file_and_path, $image_data);
if (PHP_OS === "Darwin" && PHP_SAPI === "cli") {
exec('open -a "Preview.app" ' . $file_and_path);
}
}
/**
* This works for the Goutte driver and I assume other HTML-only ones.
*
* @Then /^show me the HTML page$/
*/
public function show_me_the_html_page_in_the_browser() {
$html_data = $this->getSession()->getDriver()->getContent();
$file_and_path = '/tmp/behat_page.html';
file_put_contents($file_and_path, $html_data);
if (PHP_OS === "Darwin" && PHP_SAPI === "cli") {
exec('open -a "Safari.app" ' . $file_and_path);
};
}
于 2014-03-25T10:04:41.003 回答
1
你可以在这里使用这个包https://github.com/forceedge01/behat-fail-aid。这将为您提供失败的屏幕截图等等。它将所有细节注入到现有的异常消息中,因此它将像通常的 behat 失败消息一样完美地放置在失败之下。最重要的是,您不必编写和维护任何代码,而且它适用于 javascript 和非 javascript 驱动程序!这是输出的样子:
您所要做的就是通过 composer 安装包
$ composer 需要 genesis/behat-fail-aid --dev
并将上下文添加到您的 behat.yml 文件中
behat.yml
default: suites: default: contexts: - FailAid\Context\FailureContext extensions: FailAid\Extension: ~
你可以用这个包做很多其他的事情,但这应该可以解决你的问题,快乐的测试!
于 2019-03-05T10:19:46.323 回答