如果有人知道如何使用reportNG在selenium webdriver中拍摄失败的测试/方法的屏幕截图,那么请帮助。
如果你提供了代码,那么它是有帮助的,或者提供一些想法来解决这个问题。
提前谢谢。
发布于 2016-02-09 17:12:46
是的,这是可能的。
WebDriver firfoxDriver = new FirefoxDriver();
firfoxDriver.get("https://stackoverflow.com/");
File file = ((TakesScreenshot)firfoxDriver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(file, new File("E:\\Data\\ss.png"));发布于 2016-02-09 17:34:48
或者,您可以使用以下命令:
@AfterMethod(alwaysRun=true)
public void catchExceptions(ITestResult result){
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
String methodName = result.getName();
if(!result.isSuccess()){
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(scrFile, new File((String)     PathConverter.convert("failure_screenshots/"+methodName+"_"+formater.format(calendar.getTime())+".png")));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}发布于 2016-02-09 19:06:27
好的,这取决于你的框架,在方法失败后控件的去向。
假设在您的例子中是在catch异常块中,然后将代码复制到catch块中。
File file = ((TakesScreenshot)firfoxDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("YOUR PATH"+Filename+.JPG));https://stackoverflow.com/questions/35287622
复制相似问题