diff --git a/src/main/Resources/email_template/task-body.ftl b/src/main/Resources/email_template/task-body.ftl index 2025d9b..f32d7b6 100644 --- a/src/main/Resources/email_template/task-body.ftl +++ b/src/main/Resources/email_template/task-body.ftl @@ -46,7 +46,7 @@
自动构建状态: 【${buildstatus}】
自动重启TOMCAT状态: 【${restartstatus}】
本次任务预期执行用例共【${casecount}】条,耗時【${time}】
+本次任务预期执行用例共【${casecount}】条,耗時【${time}】
用例执行成功: 【${casesuc}】
用例执行失败: 【${casefail}】
用例有可能由于脚本原因未成功解析被锁定: 【${caselock}】
diff --git a/src/main/Resources/sys_config.properties b/src/main/Resources/sys_config.properties index 9dbcfb1..c9da8d2 100644 --- a/src/main/Resources/sys_config.properties +++ b/src/main/Resources/sys_config.properties @@ -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 diff --git a/src/main/java/luckyclient/execution/appium/AppTestControl.java b/src/main/java/luckyclient/execution/appium/AppTestControl.java index 2c39ea0..8f0fd09 100644 --- a/src/main/java/luckyclient/execution/appium/AppTestControl.java +++ b/src/main/java/luckyclient/execution/appium/AppTestControl.java @@ -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){ diff --git a/src/main/java/luckyclient/execution/httpinterface/TestControl.java b/src/main/java/luckyclient/execution/httpinterface/TestControl.java index 4aa0fdb..c9bfd2c 100644 --- a/src/main/java/luckyclient/execution/httpinterface/TestControl.java +++ b/src/main/java/luckyclient/execution/httpinterface/TestControl.java @@ -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); } } diff --git a/src/main/java/luckyclient/execution/webdriver/WebTestControl.java b/src/main/java/luckyclient/execution/webdriver/WebTestControl.java index d4bb4b8..58e006c 100644 --- a/src/main/java/luckyclient/execution/webdriver/WebTestControl.java +++ b/src/main/java/luckyclient/execution/webdriver/WebTestControl.java @@ -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); } } diff --git a/src/main/java/luckyclient/remote/api/serverOperation.java b/src/main/java/luckyclient/remote/api/serverOperation.java index e7196e0..d30dcdf 100644 --- a/src/main/java/luckyclient/remote/api/serverOperation.java +++ b/src/main/java/luckyclient/remote/api/serverOperation.java @@ -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 = "" + hour + "小时" + min - + "分" + s + "秒"; + desTime = hour + "小时" + min + "分" + s + "秒"; } } catch (Exception e) { // TODO Auto-generated catch block diff --git a/src/main/java/luckyclient/remote/entity/TaskScheduling.java b/src/main/java/luckyclient/remote/entity/TaskScheduling.java index 3322104..743778f 100644 --- a/src/main/java/luckyclient/remote/entity/TaskScheduling.java +++ b/src/main/java/luckyclient/remote/entity/TaskScheduling.java @@ -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(); + } } \ No newline at end of file diff --git a/src/main/java/luckyclient/tool/mail/FreemarkerEmailTemplate.java b/src/main/java/luckyclient/tool/mail/FreemarkerEmailTemplate.java index 4608fc0..9bd7716 100644 --- a/src/main/java/luckyclient/tool/mail/FreemarkerEmailTemplate.java +++ b/src/main/java/luckyclient/tool/mail/FreemarkerEmailTemplate.java @@ -39,7 +39,7 @@ public class FreemarkerEmailTemplate { /** * 模板引擎配置 */ - public String getText(String templateId, Map