如何解决如何在Appium上使用Jithave和Junit来捕获失败的屏幕截图?
我在Appium上使用Jbehave和Junit。我需要拍摄失败的屏幕截图并将其添加到报告中。那么用Appium上的Jbehave在Junit上截屏的方式是什么?
谢谢:)
解决方法
将screenShot()
添加到失败的断言,异常或您要截图的任何其他语句中。
import java.io.File;
import org.apache.commons.io.FileUtils;
public void screenShot() {
String picSavedPath = "screenshot";
if (!(new File(picSavedPath).isDirectory())) {
new File(picSavedPath).mkdirs();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String time = sdf.format(new Date());
//---- Below are essential statements
WebDriver augmentedDriver = new Augmenter().augment(driver);
File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
//----
try {
FileUtils.copyFile(sourceFile,new File(picSavedPath + File.separator + time + ".png"));
} catch (IOException e) {
LogUtil.error(e);
}
}
,
您可以使用getScreenshotAs()方法。 例如:
public void takescreenshot(字符串消息,WebDriver驱动程序){ 尝试{
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File file = new File("GivethePathto savethescreenshot/screenshot"+message+".png");
FileUtils.copyFile(scrFile,file );
test.addScreenCaptureFromPath(file.getAbsolutePath(),message);
}
catch(Exception e) {
e.printStackTrace();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。