【发布时间】: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