Java 如何在Appium上使用Junit和Jbehave拍摄失败截图?

Java 如何在Appium上使用Junit和Jbehave拍摄失败截图?,java,junit,automated-tests,appium,jbehave,Java,Junit,Automated Tests,Appium,Jbehave,我在Appium上使用Jbehave和Junit。我需要截图的失败,并添加到报告中。那么,在Junit上用Appium上的Jbehave截图的方法是什么呢 谢谢:)将screenShot()添加到失败的断言、异常或任何其他要截图的语句中 导入java.io.File; 导入org.apache.commons.io.FileUtils; 公共空间截图(){ 字符串picSavedPath=“屏幕截图”; if(!(新文件(picSavedPath).isDirectory()){ 新文件(pic

我在Appium上使用Jbehave和Junit。我需要截图的失败,并添加到报告中。那么,在Junit上用Appium上的Jbehave截图的方法是什么呢

谢谢:)

screenShot()
添加到失败的断言、异常或任何其他要截图的语句中

导入java.io.File;
导入org.apache.commons.io.FileUtils;
公共空间截图(){
字符串picSavedPath=“屏幕截图”;
if(!(新文件(picSavedPath).isDirectory()){
新文件(picSavedPath).mkdirs();
}
SimpleDataFormat sdf=新的SimpleDataFormat(“yyyyMMddHHmmss”);
字符串时间=sdf.format(newdate());
//----以下是重要的声明
WebDriver augmentedDriver=新的增强程序().augment(驱动程序);
文件sourceFile=((TakesScreenshot)augmentedDriver.getScreenshotAs(OutputType.File);
//----
试一试{
copyFile(sourceFile,新文件(picSavedPath+File.separator+time+“.png”);
}捕获(IOE异常){
LogUtil.error(e);
}
}
screenShot()
添加到失败的断言、异常或任何其他要截图的语句中

导入java.io.File;
导入org.apache.commons.io.FileUtils;
公共空间截图(){
字符串picSavedPath=“屏幕截图”;
if(!(新文件(picSavedPath).isDirectory()){
新文件(picSavedPath).mkdirs();
}
SimpleDataFormat sdf=新的SimpleDataFormat(“yyyyMMddHHmmss”);
字符串时间=sdf.format(newdate());
//----以下是重要的声明
WebDriver augmentedDriver=新的增强程序().augment(驱动程序);
文件sourceFile=((TakesScreenshot)augmentedDriver.getScreenshotAs(OutputType.File);
//----
试一试{
copyFile(sourceFile,新文件(picSavedPath+File.separator+time+“.png”);
}捕获(IOE异常){
LogUtil.error(e);
}
}

您可以使用getScreenshotAs()方法。 例如:

公共无效截图(字符串消息、WebDriver驱动程序){ 试一试{


您可以使用getScreenshotAs()方法。 例如:

公共无效截图(字符串消息、WebDriver驱动程序){ 试一试{

你好,@user3669148,如果这解决了你的问题,它将帮助别人和我:)你好,@user3669148,如果这解决了你的问题,它将帮助别人和我:)
        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();
    }
}