增加把测试结果推送到企业微信以及阿里钉钉的功能

This commit is contained in:
seagull 2020-09-17 20:13:34 +08:00
parent e00e4a813d
commit 5721cc4da7
11 changed files with 462 additions and 415 deletions

View File

@ -46,7 +46,7 @@
<p><b>自动构建状态: </b> 【<font color='#5CACEE'>${buildstatus}</font>】</p>
<p><b>自动重启TOMCAT状态 </b> 【<font color='#5CACEE'>${restartstatus}</font>】</p>
<br>
<p><b>本次任务预期执行用例共【<font color='#2828FF'>${casecount}</font>】条,耗時【${time}】</b></p>
<p><b>本次任务预期执行用例共【<font color='#2828FF'>${casecount}</font>】条,耗時【<font color='#2828FF'>${time}</font>】</b></p>
<p><b>用例执行成功: </b> 【<font color='#28FF28'>${casesuc}</font>】</p>
<p><b>用例执行失败: </b> 【<font color='#FF0000'>${casefail}</font>】</p>
<p><b>用例有可能由于脚本原因未成功解析被锁定:</b> 【<font color='#AE57A4'>${caselock}</font>】</p>

View File

@ -21,11 +21,6 @@ mail.smtp.username=xxxxx@xx.com
mail.smtp.password=xxxxx
#邮件模板路径
mail.freemarker.template=/email_template/
#==================向第三方应用推送任务执行结果(JSON)========================
#第三方平台推送开关 true打开 false关闭
task.push.switch=false
#第三方平台推送URL
task.push.url=localhost
#==================Jenkins API配置========================
#jenkins访问地址示例 http://192.168.100.100:8080/jenkins/
jenkins.url=http://localhost

View File

@ -168,7 +168,7 @@ public class AppTestControl {
LogUtil.APP.info("当前项目【{}】测试计划中的用例已经全部执行完成...",projectname);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskId, buildResult.toString(), restartstatus, testtime, jobname),
taskId, taskScheduling, tastcount);
taskId, taskScheduling, tastcount,testtime,buildResult.toString(),restartstatus);
// 关闭APP以及appium会话
if ("Android".equals(properties.getProperty("platformName"))) {
assert androiddriver != null;
@ -179,11 +179,11 @@ public class AppTestControl {
}
} else {
LogUtil.APP.warn("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskId, taskScheduling, null);
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskId, taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus);
}
} else {
LogUtil.APP.warn("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskId, taskScheduling, null);
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskId, taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus);
}
//关闭Appium服务的线程
if(as!=null){

View File

@ -153,18 +153,18 @@ public class TestControl {
String testtime = serverOperation.getTestTime(taskid);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildResult.toString(), restartstatus, testtime, jobname),
taskid, taskScheduling, tastcount);
taskid, taskScheduling, tastcount,testtime,buildResult.toString(),restartstatus);
threadExecute.shutdown();
LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
} else {
LogUtil.APP.warn("项目构建失败,自动化测试自动退出!请查看构建日志检查项目构建情况...");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败,自动化测试自动退出!请查看构建日志检查项目构建情况...", taskid,
taskScheduling, null);
taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus);
}
} else {
LogUtil.APP.warn("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid,
taskScheduling, null);
taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus);
}
}

View File

@ -135,19 +135,19 @@ public class WebTestControl {
LogUtil.APP.info("当前项目【{}】测试计划中的用例已经全部执行完成...",projectname);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildResult.toString(), restartstatus, testtime, jobname),
taskid, taskScheduling, tastcount);
taskid, taskScheduling, tastcount,testtime,buildResult.toString(),restartstatus);
// 关闭浏览器
assert wd != null;
wd.quit();
} else {
LogUtil.APP.warn("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid,
taskScheduling, null);
taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus);
}
} else {
LogUtil.APP.warn("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid,
taskScheduling, null);
taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus);
}
}

View File

@ -116,24 +116,26 @@ public class serverOperation {
* ·¢ËÍ eMailer varchar(100) ; --ÊÕ¼þÈË
*/
public static String[] getEmailAddress(String taskIdStr) {
int taskId = Integer.parseInt(taskIdStr);
public static String[] getEmailAddress(TaskScheduling taskScheduling,String taskIdStr) {
String[] address = null;
try {
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
if (!taskScheduling.getEmailSendCondition().equals(-1)) {
String temp = taskScheduling.getEmailAddress();
// 清除最后一个;
if (temp.contains(";") && temp.substring(temp.length() - 1).contains(";")) {
temp = temp.substring(0, temp.length() - 1);
}
// 多个地址
if (!temp.contains("null") && temp.contains(";")) {
address = temp.split(";", -1);
// 一个地址
} else if (!temp.contains("null") && !temp.contains(";")) {
address = new String[1];
address[0] = temp;
if(StrUtil.isNotBlank(temp)){
// 清除最后一个;
if (temp.contains(";") && temp.substring(temp.length() - 1).contains(";")) {
temp = temp.substring(0, temp.length() - 1);
}
// 多个地址
if (!temp.contains("null") && temp.contains(";")) {
address = temp.split(";", -1);
// 一个地址
} else if (!temp.contains("null") && !temp.contains(";")) {
address = new String[1];
address[0] = temp;
}
}else{
LogUtil.APP.warn("邮件地址配置为空,取消邮件发送...");
}
}
} catch (Exception e) {
@ -231,8 +233,7 @@ public class serverOperation {
long hour = (l / (60 * 60 * 1000) - day * 24);
long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
desTime = "<font color='#2828FF'>" + hour + "</font>小时<font color='#2828FF'>" + min
+ "</font>分<font color='#2828FF'>" + s + "</font>秒";
desTime = hour + "小时" + min + "" + s + "";
}
} catch (Exception e) {
// TODO Auto-generated catch block

View File

@ -1,254 +1,267 @@
package luckyclient.remote.entity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 任务调度实体
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论 QQ:1573584944 Seagull
* =================================================================
* @author Seagull
* @date 2019年4月13日
*/
public class TaskScheduling extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 预约调度ID */
private Integer schedulingId;
/** 预约调度名称 */
private String schedulingName;
/** 任务ID */
private Integer jobId;
/** 项目ID */
private Integer projectId;
/** 测试计划ID */
private Integer planId;
/** 客户端ID */
private Integer clientId;
/** 邮件通知地址 */
private String emailAddress;
/** 发送邮件通知时的具体逻辑, 0-全部1-成功,-1-失败 */
private Integer emailSendCondition;
/** jenkins构建链接 */
private String buildingLink;
/** 远程执行Shell脚本 */
private String remoteShell;
/** 客户端执行线程数 */
private Integer exThreadCount;
/** 任务类型 0 接口 1 Web UI 2 移动 */
private Integer taskType;
/** UI自动化浏览器类型 0 IE 1 火狐 2 谷歌 3 Edge */
private Integer browserType;
/** 任务超时时间(分钟) */
private Integer taskTimeout;
/** 客户端测试驱动桩路径 */
private String clientDriverPath;
/** 关联项目实体 */
private Project project;
/** 关联项目计划 */
private ProjectPlan projectPlan;
/** 任务名称 */
private String jobName;
/** cron执行表达式 */
private String cronExpression;
/** 任务状态0正常 1暂停 */
private String status;
public String getSchedulingName() {
return schedulingName;
}
public void setSchedulingName(String schedulingName) {
this.schedulingName = schedulingName;
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
public String getCronExpression() {
return cronExpression;
}
public void setCronExpression(String cronExpression) {
this.cronExpression = cronExpression;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public ProjectPlan getProjectPlan() {
return projectPlan;
}
public void setProjectPlan(ProjectPlan projectPlan) {
this.projectPlan = projectPlan;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public void setSchedulingId(Integer schedulingId)
{
this.schedulingId = schedulingId;
}
public Integer getSchedulingId()
{
return schedulingId;
}
public void setJobId(Integer jobId)
{
this.jobId = jobId;
}
public Integer getJobId()
{
return jobId;
}
public void setProjectId(Integer projectId)
{
this.projectId = projectId;
}
public Integer getProjectId()
{
return projectId;
}
public void setPlanId(Integer planId)
{
this.planId = planId;
}
public Integer getPlanId()
{
return planId;
}
public void setClientId(Integer clientId)
{
this.clientId = clientId;
}
public Integer getClientId()
{
return clientId;
}
public void setEmailAddress(String emailAddress)
{
this.emailAddress = emailAddress;
}
public String getEmailAddress()
{
return emailAddress;
}
public void setEmailSendCondition(Integer emailSendCondition)
{
this.emailSendCondition = emailSendCondition;
}
public Integer getEmailSendCondition()
{
return emailSendCondition;
}
public void setBuildingLink(String buildingLink)
{
this.buildingLink = buildingLink;
}
public String getBuildingLink()
{
return buildingLink;
}
public void setRemoteShell(String remoteShell)
{
this.remoteShell = remoteShell;
}
public String getRemoteShell()
{
return remoteShell;
}
public void setExThreadCount(Integer exThreadCount)
{
this.exThreadCount = exThreadCount;
}
public Integer getExThreadCount()
{
return exThreadCount;
}
public void setTaskType(Integer taskType)
{
this.taskType = taskType;
}
public Integer getTaskType()
{
return taskType;
}
public void setBrowserType(Integer browserType)
{
this.browserType = browserType;
}
public Integer getBrowserType()
{
return browserType;
}
public void setTaskTimeout(Integer taskTimeout)
{
this.taskTimeout = taskTimeout;
}
public Integer getTaskTimeout()
{
return taskTimeout;
}
public void setClientDriverPath(String clientDriverPath)
{
this.clientDriverPath = clientDriverPath;
}
public String getClientDriverPath()
{
return clientDriverPath;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("schedulingId", getSchedulingId())
.append("jobId", getJobId())
.append("projectId", getProjectId())
.append("planId", getPlanId())
.append("clientId", getClientId())
.append("emailAddress", getEmailAddress())
.append("emailSendCondition", getEmailSendCondition())
.append("buildingLink", getBuildingLink())
.append("remoteShell", getRemoteShell())
.append("exThreadCount", getExThreadCount())
.append("taskType", getTaskType())
.append("browserType", getBrowserType())
.append("taskTimeout", getTaskTimeout())
.append("clientDriverPath", getClientDriverPath())
.toString();
}
package luckyclient.remote.entity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 任务调度实体
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论 QQ:1573584944 Seagull
* =================================================================
* @author Seagull
* @date 2019年4月13日
*/
public class TaskScheduling extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 预约调度ID */
private Integer schedulingId;
/** 预约调度名称 */
private String schedulingName;
/** 任务ID */
private Integer jobId;
/** 项目ID */
private Integer projectId;
/** 测试计划ID */
private Integer planId;
/** 客户端ID */
private Integer clientId;
/** 邮件通知地址 */
private String emailAddress;
/** 第三方推送地址 */
private String pushUrl;
/** 发送邮件通知时的具体逻辑, 0-全部1-成功,-1-失败 */
private Integer emailSendCondition;
/** jenkins构建链接 */
private String buildingLink;
/** 远程执行Shell脚本 */
private String remoteShell;
/** 客户端执行线程数 */
private Integer exThreadCount;
/** 任务类型 0 接口 1 Web UI 2 移动 */
private Integer taskType;
/** UI自动化浏览器类型 0 IE 1 火狐 2 谷歌 3 Edge */
private Integer browserType;
/** 任务超时时间(分钟) */
private Integer taskTimeout;
/** 客户端测试驱动桩路径 */
private String clientDriverPath;
/** 关联项目实体 */
private Project project;
/** 关联项目计划 */
private ProjectPlan projectPlan;
/** 任务名称 */
private String jobName;
/** cron执行表达式 */
private String cronExpression;
/** 任务状态0正常 1暂停 */
private String status;
public String getSchedulingName() {
return schedulingName;
}
public void setSchedulingName(String schedulingName) {
this.schedulingName = schedulingName;
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
public String getCronExpression() {
return cronExpression;
}
public void setCronExpression(String cronExpression) {
this.cronExpression = cronExpression;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public ProjectPlan getProjectPlan() {
return projectPlan;
}
public void setProjectPlan(ProjectPlan projectPlan) {
this.projectPlan = projectPlan;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public void setSchedulingId(Integer schedulingId)
{
this.schedulingId = schedulingId;
}
public Integer getSchedulingId()
{
return schedulingId;
}
public void setJobId(Integer jobId)
{
this.jobId = jobId;
}
public Integer getJobId()
{
return jobId;
}
public void setProjectId(Integer projectId)
{
this.projectId = projectId;
}
public Integer getProjectId()
{
return projectId;
}
public void setPlanId(Integer planId)
{
this.planId = planId;
}
public Integer getPlanId()
{
return planId;
}
public void setClientId(Integer clientId)
{
this.clientId = clientId;
}
public Integer getClientId()
{
return clientId;
}
public void setEmailAddress(String emailAddress)
{
this.emailAddress = emailAddress;
}
public String getEmailAddress()
{
return emailAddress;
}
public void setPushUrl(String pushUrl)
{
this.pushUrl = pushUrl;
}
public String getPushUrl()
{
return pushUrl;
}
public void setEmailSendCondition(Integer emailSendCondition)
{
this.emailSendCondition = emailSendCondition;
}
public Integer getEmailSendCondition()
{
return emailSendCondition;
}
public void setBuildingLink(String buildingLink)
{
this.buildingLink = buildingLink;
}
public String getBuildingLink()
{
return buildingLink;
}
public void setRemoteShell(String remoteShell)
{
this.remoteShell = remoteShell;
}
public String getRemoteShell()
{
return remoteShell;
}
public void setExThreadCount(Integer exThreadCount)
{
this.exThreadCount = exThreadCount;
}
public Integer getExThreadCount()
{
return exThreadCount;
}
public void setTaskType(Integer taskType)
{
this.taskType = taskType;
}
public Integer getTaskType()
{
return taskType;
}
public void setBrowserType(Integer browserType)
{
this.browserType = browserType;
}
public Integer getBrowserType()
{
return browserType;
}
public void setTaskTimeout(Integer taskTimeout)
{
this.taskTimeout = taskTimeout;
}
public Integer getTaskTimeout()
{
return taskTimeout;
}
public void setClientDriverPath(String clientDriverPath)
{
this.clientDriverPath = clientDriverPath;
}
public String getClientDriverPath()
{
return clientDriverPath;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("schedulingId", getSchedulingId())
.append("jobId", getJobId())
.append("projectId", getProjectId())
.append("planId", getPlanId())
.append("clientId", getClientId())
.append("emailAddress", getEmailAddress())
.append("pushUrl", getPushUrl())
.append("emailSendCondition", getEmailSendCondition())
.append("buildingLink", getBuildingLink())
.append("remoteShell", getRemoteShell())
.append("exThreadCount", getExThreadCount())
.append("taskType", getTaskType())
.append("browserType", getBrowserType())
.append("taskTimeout", getTaskTimeout())
.append("clientDriverPath", getClientDriverPath())
.toString();
}
}

View File

@ -39,7 +39,7 @@ public class FreemarkerEmailTemplate {
/**
* Ä£°åÒýÇæÅäÖÃ
*/
public String getText(String templateId, Map<Object, Object> parameters) {
public String getText(String templateId, Map<String, Object> parameters) {
@SuppressWarnings("deprecation")
Configuration configuration = new Configuration();
configuration.setTemplateLoader(new ClassTemplateLoader(FreemarkerEmailTemplate.class, TEMPLATE_PATH));

View File

@ -1,9 +1,13 @@
package luckyclient.tool.mail;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import luckyclient.remote.entity.ProjectProtocolTemplate;
import luckyclient.utils.LogUtil;
import luckyclient.utils.config.SysConfig;
@ -22,53 +26,25 @@ import luckyclient.utils.httputils.HttpClientTools;
public class HtmlMail {
static FreemarkerEmailTemplate fet = new FreemarkerEmailTemplate();
public static String htmlContentFormat(int[] taskcount, String taskid, String buildstatus, String restartstatus, String time, String jobname) {
Map<Object, Object> parameters = new HashMap<>(0);
parameters.put("buildstatus", buildstatus);
parameters.put("restartstatus", restartstatus);
parameters.put("casecount", taskcount[0]);
parameters.put("casesuc", taskcount[1]);
parameters.put("casefail", taskcount[2]);
parameters.put("caselock", taskcount[3]);
parameters.put("caseunex", taskcount[4]);
public static String htmlContentFormat(int[] taskCount, String taskId, String buildStatus, String restartStatus, String time, String jobName) {
Map<String, Object> parameters = new HashMap<>(0);
parameters.put("buildstatus", buildStatus);
parameters.put("restartstatus", restartStatus);
parameters.put("casecount", taskCount[0]);
parameters.put("casesuc", taskCount[1]);
parameters.put("casefail", taskCount[2]);
parameters.put("caselock", taskCount[3]);
parameters.put("caseunex", taskCount[4]);
parameters.put("time", time);
parameters.put("taskid", taskid);
parameters.put("jobname", jobname);
try {
Map<String, String> headmsg = new HashMap<>(0);
Properties properties = SysConfig.getConfiguration();
if ("true".equals(properties.getProperty("task.push.switch").toLowerCase())) {
LogUtil.APP.info("开始向第三方平台推送任务执行情况...");
Map<String, Object> pushparameters = new HashMap<>(0);
pushparameters.put("buildstatus", buildstatus);
pushparameters.put("restartstatus", restartstatus);
pushparameters.put("casecount", taskcount[0]);
pushparameters.put("casesuc", taskcount[1]);
pushparameters.put("casefail", taskcount[2]);
pushparameters.put("caselock", taskcount[3]);
pushparameters.put("caseunex", taskcount[4]);
pushparameters.put("time", time);
pushparameters.put("taskid", taskid);
pushparameters.put("jobname", jobname);
parameters.put("taskid", taskId);
parameters.put("jobname", jobName);
String pushurl = properties.getProperty("task.push.url");
ProjectProtocolTemplate ppt=new ProjectProtocolTemplate();
ppt.setEncoding("utf-8");
ppt.setTimeout(60);
HttpClientTools hct = new HttpClientTools();
hct.httpClientPostJson(pushurl, pushparameters, headmsg,ppt);
}
} catch (Exception e) {
LogUtil.APP.error("向第三方平台推送任务执行情况出现异常,请检查!", e);
return fet.getText("task-body", parameters);
}
return fet.getText("task-body", parameters);
}
public static String htmlSubjectFormat(String jobname) {
Map<Object, Object> parameters = new HashMap<>(0);
Map<String, Object> parameters = new HashMap<>(0);
parameters.put("jobname", jobname);
return fet.getText("task-title", parameters);
}
}

View File

@ -1,89 +1,150 @@
package luckyclient.tool.mail;
import java.util.Properties;
import luckyclient.remote.api.serverOperation;
import luckyclient.remote.entity.TaskScheduling;
import luckyclient.utils.LogUtil;
import luckyclient.utils.config.SysConfig;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2018年3月1日
*/
public class MailSendInitialization {
public static void sendMailInitialization(String subject, String content, String taskid, TaskScheduling taskScheduling, int[] taskCount) {
boolean isSend = false;
if (null == taskCount) {
isSend = true;
} else {
if (taskCount.length == 5 && null != taskScheduling) {
Integer sendCondition = taskScheduling.getEmailSendCondition();
// 用例全部成功了发送, casecount != casesuc
if (null!=sendCondition&&1 == sendCondition) {
if (taskCount[0] == taskCount[1]) {
isSend = true;
}
}
// 用例部分失败了发送
if (null!=sendCondition&&2 == sendCondition) {
if (taskCount[2] > 0) {
isSend = true;
}
}
// 全发
if (null!=sendCondition&&0 == sendCondition) {
isSend = true;
}
}
}
if (!isSend) {
LogUtil.APP.info("当前任务不需要发送邮件通知!");
return;
}
String[] addresses = serverOperation.getEmailAddress(taskid);
Properties properties = SysConfig.getConfiguration();
if (addresses != null) {
LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等...");
//这个类主要是设置邮件
MailSenderInfo mailInfo = new MailSenderInfo();
//这个类主要来发送邮件
SimpleMailSender sms = new SimpleMailSender();
mailInfo.setMailServerHost(properties.getProperty("mail.smtp.ip"));
mailInfo.setMailServerPort(properties.getProperty("mail.smtp.port"));
mailInfo.setSslenable(properties.getProperty("mail.smtp.ssl.enable").equals("true"));
mailInfo.setValidate(true);
mailInfo.setUserName(properties.getProperty("mail.smtp.username"));
//您的邮箱密码
mailInfo.setPassword(properties.getProperty("mail.smtp.password"));
mailInfo.setFromAddress(properties.getProperty("mail.smtp.username"));
//标题
mailInfo.setSubject(subject);
//内容
mailInfo.setContent(content);
mailInfo.setToAddresses(addresses);
//sms.sendHtmlMail(mailInfo);
StringBuilder stringBuilder = new StringBuilder();
for (String address : addresses) {
stringBuilder.append(address).append(";");
}
String addressesmail = stringBuilder.toString();
if (sms.sendHtmlMail(mailInfo)) {
LogUtil.APP.info("给{}的测试结果通知邮件发送完成!",addressesmail);
} else {
LogUtil.APP.warn("给{}的测试结果通知邮件发送失败!",addressesmail);
}
} else {
LogUtil.APP.info("当前任务不需要发送邮件通知!");
}
}
}
package luckyclient.tool.mail;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import luckyclient.remote.api.serverOperation;
import luckyclient.remote.entity.ProjectProtocolTemplate;
import luckyclient.remote.entity.TaskScheduling;
import luckyclient.utils.LogUtil;
import luckyclient.utils.config.SysConfig;
import luckyclient.utils.httputils.HttpClientTools;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2018年3月1日
*/
public class MailSendInitialization {
public static void sendMailInitialization(String subject, String content, String taskid, TaskScheduling taskScheduling, int[] taskCount, String time, String buildStatus, String restartStatus) {
boolean isSend = false;
if (null == taskCount) {
isSend = true;
} else {
if (taskCount.length == 5 && null != taskScheduling) {
Integer sendCondition = taskScheduling.getEmailSendCondition();
// 用例全部成功了发送, casecount != casesuc
if (null != sendCondition && 1 == sendCondition) {
if (taskCount[0] == taskCount[1]) {
isSend = true;
}
}
// 用例部分失败了发送
if (null != sendCondition && 2 == sendCondition) {
if (taskCount[2] > 0) {
isSend = true;
}
}
// 全发
if (null != sendCondition && 0 == sendCondition) {
isSend = true;
}
}
}
if (!isSend) {
LogUtil.APP.info("当前任务不需要发送邮件或是推送通知!");
return;
}
//向第三方推送消息
MailSendInitialization msi= new MailSendInitialization();
msi.pushMessage(taskScheduling, content, taskCount, time, buildStatus, restartStatus);
String[] addresses = serverOperation.getEmailAddress(taskScheduling,taskid);
Properties properties = SysConfig.getConfiguration();
if (addresses != null) {
LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等...");
//这个类主要是设置邮件
MailSenderInfo mailInfo = new MailSenderInfo();
//这个类主要来发送邮件
SimpleMailSender sms = new SimpleMailSender();
mailInfo.setMailServerHost(properties.getProperty("mail.smtp.ip"));
mailInfo.setMailServerPort(properties.getProperty("mail.smtp.port"));
mailInfo.setSslenable(properties.getProperty("mail.smtp.ssl.enable").equals("true"));
mailInfo.setValidate(true);
mailInfo.setUserName(properties.getProperty("mail.smtp.username"));
//您的邮箱密码
mailInfo.setPassword(properties.getProperty("mail.smtp.password"));
mailInfo.setFromAddress(properties.getProperty("mail.smtp.username"));
//标题
mailInfo.setSubject(subject);
//内容
mailInfo.setContent(content);
mailInfo.setToAddresses(addresses);
//sms.sendHtmlMail(mailInfo);
StringBuilder stringBuilder = new StringBuilder();
for (String address : addresses) {
stringBuilder.append(address).append(";");
}
String addressesmail = stringBuilder.toString();
if (sms.sendHtmlMail(mailInfo)) {
LogUtil.APP.info("给{}的测试结果通知邮件发送完成!", addressesmail);
} else {
LogUtil.APP.warn("给{}的测试结果通知邮件发送失败!", addressesmail);
}
} else {
LogUtil.APP.info("当前任务不需要发送邮件通知!");
}
}
private void pushMessage(TaskScheduling taskScheduling, String content, int[] taskCount, String time, String buildStatus, String restartStatus) {
try {
Map<String, String> headmsg = new HashMap<>(0);
Properties properties = SysConfig.getConfiguration();
LogUtil.APP.info("准备初始化第三方消息推送的数据...");
String pushUrl = taskScheduling.getPushUrl();
if(StrUtil.isNotBlank(pushUrl)){
String ip = properties.getProperty("server.web.ip");
String port = properties.getProperty("server.web.port");
ProjectProtocolTemplate ppt = new ProjectProtocolTemplate();
ppt.setEncoding("utf-8");
ppt.setTimeout(60);
ppt.setIsResponseHead(1);
ppt.setIsResponseCode(1);
HttpClientTools hct = new HttpClientTools();
Map<String, Object> parameters = new HashMap<>(0);
if(null != taskCount){
content = "LuckyFrame自动化测试任务【" + taskScheduling.getSchedulingName() + "】执行结果\n" +
"自动构建状态:【" + buildStatus + "\n" +
"自动重启TOMCAT状态" + restartStatus + "\n" +
"本次任务预期执行用例共【" + taskCount[0] + "】条,耗時【" + time + "\n" +
"用例执行成功:【" + taskCount[1] + "\n" +
"用例执行失败:【" + taskCount[2] + "\n" +
"用例有可能由于脚本原因未成功解析被锁定:【" + taskCount[3] + "\n" +
"用例由于长时间未收到接口Response未执行完成" + taskCount[4] + "\n" +
"详情请前往自动化测试平台查看http://" + ip + ":" + port;
}
JSONObject contentJson = JSON.parseObject("{\"content\": \"" + content + "\"}");
JSONObject atJson = JSON.parseObject("{\"atMobiles\": [],\"isAtAll\":true}");
parameters.put("msgtype", "text");
parameters.put("text", contentJson);
parameters.put("at", atJson);
LogUtil.APP.info("开始向第三方平台推送任务执行情况...");
hct.httpClientPostJson(pushUrl, parameters, headmsg, ppt);
LogUtil.APP.info("向第三方平台推送任务执行数据成功...");
}else{
LogUtil.APP.warn("推送地址配置为空,取消第三方推送...");
}
} catch (Exception e) {
LogUtil.APP.error("向第三方平台推送任务执行情况出现异常,请检查!", e);
}
}
}

View File

@ -1,5 +1,6 @@
package luckyclient.utils.httputils;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import luckyclient.remote.entity.ProjectProtocolTemplate;
@ -1745,7 +1746,7 @@ public class HttpClientTools {
} else if (urlParam.startsWith("https://")) {
//采用绕过验证的方式处理https请求
SSLContext sslContext;
if (null == cerpath || "".equals(cerpath.trim())) {
if (StrUtil.isBlank(cerpath)) {
LogUtil.APP.info("开始构建HTTPS单向认证请求...");
TrustManager[] trustManagers = {new MyX509TrustManager()};
sslContext = SSLContext.getInstance("TLS");