【问题标题】:Send cucumber 'index.html' report to email将 cucumber 'index.html' 报告发送到电子邮件
【发布时间】:2018-10-29 07:59:13
【问题描述】:

我使用 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 邮件 api 时,首先我提取 html,然后尝试发送 html,但它发送空白报告。 请帮助我如何将完整的 html 报告作为电子邮件正文发送,此报告还包含附加的“屏幕截图”,附件是 /target/cucumber/ 文件夹的结构:-

请帮忙!!

电子邮件发送代码:-

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 ={"suresh.s@gmail.in","suresh98714@gmail.com"};
            email.addTo(toList);
        } catch (Exception e) {

            String emailTo = "suresh98714@gmail.com";

            email.addTo(emailTo);
        }

        email.setFrom("suresh98714@gmail.com");


        try {
            SMTPAPI smtpapi = email.getSMTPAPI();

            String[] cc ={"suresh.s@cashify.in","suresh98714@gmail.com"};
            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());    




    }

电子邮件正文中的预期电子邮件(附加屏幕截图):-

【问题讨论】:

  • 你能给出代码示例和/或例外情况
  • 电子邮件结束代码?
  • 是的,您如何将html报告发送到电子邮件等代码示例
  • @Infern0:- 添加了我的电子邮件发送代码,请帮助!!

标签: java jenkins selenium-webdriver cucumber cucumberjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 2012-05-07
    • 2019-04-17
    相关资源
    最近更新 更多