将cucumber'index.html'报告发送至电子邮件

问题描述 投票:0回答:1

我使用cucumber + appium创建了一个测试自动化框架。但是在执行框架之后,我想通过电子邮件将报告(/target/cucumber/index.html)作为邮件正文发送,但无法执行相同操作。与'testng emailable-reports.html'一样,它就像魅力一样。我尝试过: - 1. Jenkins使用'扩展电子邮件插件'获取selenium .html报告它工作正常但黄瓜它不起作用。 2.使用java mail api(jsoup库)。

另外,当我右键点击黄瓜index.html报告时,它显示如下代码: -

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Cucumber Features</title>
    <link href="style.css" rel="stylesheet">
    <script src="jquery-1.8.2.min.js"></script>
    <script src="formatter.js"></script>
    <script src="report.js"></script>
  </head>
  <body>
    <div class="cucumber-report"></div>
  </body>
</html>

当我尝试使用java mail api时,首先我提取html然后尝试发送html但它发送空白报告。请帮助我如何发送完整的HTML报告作为电子邮件正文,此报告包含附加的“截图”,附加的是/ target / cucumber /文件夹的结构: - enter image description here

请帮忙!!

电子邮件发送代码: -

public class Email {


    public static void main(String[] args) throws IOException, SendGridException {

        FileInputStream fin=new FileInputStream(System.getProperty("user.dir")+"/src/main/resources/config.properties");
        Properties prop=new Properties();
        prop.load(fin);         



        StringBuilder path = new StringBuilder(); 

        try     
        { BufferedReader in = new BufferedReader(new FileReader(System.getProperty("user.dir")+prop.getProperty("reports"))); 
        String str; while ((str = in.readLine()) != null) 
        { path.append(str); } in.close(); } catch (IOException e) { } String content = path.toString();

        System.out.println("HTML IS :---" +path);



        SendGrid sendGrid = new SendGrid("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        SendGrid.Email email = new SendGrid.Email();

        try {
            String[] toList ={"[email protected]","[email protected]"};
            email.addTo(toList);
        } catch (Exception e) {

            String emailTo = "[email protected]";

            email.addTo(emailTo);
        }

        email.setFrom("[email protected]");


        try {
            SMTPAPI smtpapi = email.getSMTPAPI();

            String[] cc ={"[email protected]","[email protected]"};
            email.setCc(cc);
        } catch (Exception e) {

        }
        try {// for bcc
            String[] bcc = {"",""};
            email.setBcc(bcc);
        } catch (Exception e) {

        }


        email.setSubject("Cucumber Report");
        email.setHtml(path.toString());

        SendGrid.Response response =sendGrid.send(email);
        System.out.println("Response is " +response.toString());    




    }

通过电子邮件正文发送的预期电子邮件(附截图): - enter image description here

java jenkins selenium-webdriver cucumber cucumberjs
1个回答
0
投票

如您所见,目标下的cucumber文件夹除了要作为电子邮件附件发送的index.html文件外,还有js和CSS文件。 Html文件将这些文件作为依赖项使用,因此您无法单独发送HTML文件,这就是您获取空白文件的原因。一个解决方案是压缩整个黄瓜文件夹并作为附件发送,另一个解决方案是使用cucucmber.json文件编写自定义包装器以创建自己的独立HTML报告

© www.soinside.com 2019 - 2024. All rights reserved.