我如何在詹金斯电子邮件附件中发送故障测试用例的快照

时间:2019-03-08 13:03:21

标签: java selenium jenkins

1] 1我正在使用maven项目进行自动化,我想拍摄失败的测试用例的快照并发送附件,快照已成功捕获并保存,但是在Jenkins中附件无法正常工作,任何人都可以找出问题所在吗?  我正在使用Maven项目和Jenkins enter image description here图像代码的捕获工作正常,快照成功保存,但是在Jenkins附件中,快照未通过电子邮件发送

enter code here  public static void captureScreenshot(WebDriver driver, String screenshotname) throws Exception {
    String timeStamp;
    File screenShotName;
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    //The below method will save the screen shot in d drive with name "screenshot.png"
    timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()); 
    //screenShotName = new File("D:\\MyTest\\Screenshots\\"+timeStamp+".png");
    screenShotName = new File("D:\\Automation\\EclipseWorkSpace\\WebDriverTest1\\target\\snapshot\\"+timeStamp+".png");
    FileUtils.copyFile(scrFile, screenShotName);

    String filePath = screenShotName.toString();
    //String path = "<img src="\"file://"" alt="\"\"/" />";
    String path = "<img src=\"file://" + filePath + "\" alt=\"\"/>";
    Reporter.log(path);

    }

1 个答案:

答案 0 :(得分:0)

应该将屏幕快照存储在“ D:\ Automation \ XXX”中,而不要指定一个相对于项目目录的文件夹。如果Jenkins机器没有“ D:”驱动器,则硬编码路径将不起作用。