有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何使用Java、TestNG将失败的测试截图附加到Azure管道?

我正在使用Java+TestNG、Maven、Chromedriver和Azure Devops管道。 我有一个监听器,当测试失败时,它会截图显示 “/target/surefire报告/故障\屏幕截图/”。 但它们不会在Azure管道上显示为附件。 我是这方面的新手,尝试掌握自动化UI测试

我有这样的听众:

    @Override
public void onTestFailure(ITestResult result) {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
    String methodName = result.getName();
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        try {
            String reportDirectory = new File(System.getProperty("user.dir")).getAbsolutePath() + "/target/surefire-reports";
            File destFile = new File((String) reportDirectory+"/failure_screenshots/"+methodName+"_"+formater.format(calendar.getTime())+".png");
            FileUtils.copyFile(scrFile, destFile);
            Reporter.log("<a href='"+ destFile.getAbsolutePath() + "'> <img src='"+ destFile.getAbsolutePath() + "' height='100' width='100'/> </a>");
        } catch (IOException e) {
            e.printStackTrace();
        }
}

我做错了什么? 这些截图只拍摄了本地的


共 (0) 个答案