首页 > 解决方案 > 如何在 Appium 上使用 Jbehave 和 Junit 截屏失败?

问题描述

我在 Appium 上使用 Jbehave 和 Junit。我需要截取失败的屏幕截图并将它们添加到报告中。那么在Appium上使用Jbehave在Junit上截屏的方法是什么?

谢谢 :)

标签: javajunitautomated-testsappiumjbehave

解决方案


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

public void takescreenshot(String message, WebDriver driver) { try {

        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();
    }
}

推荐阅读