1.更加细粒度的控制邮件发送逻辑

2.webUI在测试步骤失败时,可以控制是否继续
This commit is contained in:
leo 2018-10-24 11:18:26 +08:00
parent 843b7acbc8
commit 17b5091e89
7 changed files with 99 additions and 54 deletions

View File

@ -1,10 +1,5 @@
package luckyclient.caserun.exappium;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.ios.IOSDriver;
@ -19,10 +14,12 @@ import luckyclient.jenkinsapi.RestartServerInitialization;
import luckyclient.mail.HtmlMail;
import luckyclient.mail.MailSendInitialization;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.planapi.entity.TestTaskexcute;
import luckyclient.planapi.entity.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* =================================================================
@ -114,8 +111,10 @@ public class AppTestControl {
.cgetParamsByProjectid(task.getTestJob().getProjectid().toString());
String projectname = task.getTestJob().getPlanproj();
task = GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
TestJobs testJob = task.getTestJob();
String jobname = task.getTestJob().getTaskName();
// 判断是否要自动重启TOMCAT
int[] tastcount = null;
if (restartstatus.indexOf("Status:true") > -1) {
// 判断是否构建是否成功
if (buildstatus.indexOf("Status:true") > -1) {
@ -135,7 +134,6 @@ public class AppTestControl {
e.printStackTrace();
}
LogOperation caselog = new LogOperation();
int[] tastcount = null;
List<ProjectCase> cases = GetServerAPI.getCasesbyplanid(task.getTestJob().getPlanid());
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogOperation.updateTastStatus(taskid, cases.size());
@ -164,7 +162,7 @@ public class AppTestControl {
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime, jobname),
taskid);
taskid, testJob, tastcount);
// 关闭APP以及appium会话
if ("Android".equals(properties.getProperty("platformName"))) {
androiddriver.closeApp();
@ -173,11 +171,11 @@ public class AppTestControl {
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid);
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid, testJob, tastcount);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid);
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid, testJob, tastcount);
}
}

View File

@ -1,11 +1,5 @@
package luckyclient.caserun.exinterface;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import br.eti.kinoshita.testlinkjavaapi.model.TestCase;
import luckyclient.caserun.exinterface.testlink.ThreadForTestLinkExecuteCase;
import luckyclient.dblog.DbLink;
@ -15,13 +9,16 @@ import luckyclient.jenkinsapi.RestartServerInitialization;
import luckyclient.mail.HtmlMail;
import luckyclient.mail.MailSendInitialization;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.planapi.entity.TestTaskexcute;
import luckyclient.planapi.entity.*;
import luckyclient.testlinkapi.TestBuildApi;
import luckyclient.testlinkapi.TestCaseApi;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -139,10 +136,12 @@ public class TestControl {
String jobname = task.getTestJob().getTaskName();
String projectname=task.getTestJob().getPlanproj();
int timeout = task.getTestJob().getTimeout();
TestJobs testJob = task.getTestJob();
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(task.getTestJob().getProjectid().toString());
// 初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
// 判断是否要自动重启TOMCAT
int[] tastcount=null;
if (restartstatus.indexOf("Status:true") > -1) {
// 判断是否构建是否成功
if (buildstatus.indexOf("Status:true") > -1) {
@ -151,7 +150,6 @@ public class TestControl {
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
int[] tastcount=null;
if(task.getTestJob().getProjecttype()==1){
TestBuildApi.getBuild(projectname);
TestCase[] testCases= TestCaseApi.getplantestcase(projectname, taskid, "");
@ -206,18 +204,21 @@ public class TestControl {
String testtime = LogOperation.getTestTime(taskid);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid);
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid, testJob,
tastcount);
threadExecute.shutdown();
luckyclient.publicclass.LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname,
"构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid);
"构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid, testJob,
tastcount);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname,
"项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid);
"项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid, testJob,
tastcount);
}
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import luckyclient.planapi.entity.*;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
@ -19,10 +20,6 @@ import luckyclient.jenkinsapi.RestartServerInitialization;
import luckyclient.mail.HtmlMail;
import luckyclient.mail.MailSendInitialization;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.planapi.entity.TestTaskexcute;
import luckyclient.testlinkapi.TestBuildApi;
import luckyclient.testlinkapi.TestCaseApi;
@ -96,7 +93,9 @@ public class WebTestControl{
task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
String jobname = task.getTestJob().getTaskName();
int drivertype = LogOperation.querydrivertype(taskid);
TestJobs testJob = task.getTestJob();
// 判断是否要自动重启TOMCAT
int[] tastcount=null;
if (restartstatus.indexOf("Status:true") > -1) {
// 判断是否构建是否成功
if (buildstatus.indexOf("Status:true") > -1) {
@ -111,7 +110,7 @@ public class WebTestControl{
e2.printStackTrace();
}
LogOperation caselog = new LogOperation();
int[] tastcount=null;
if(task.getTestJob().getProjecttype()==1){
TestBuildApi.getBuild(projectname);
TestCase[] testCases = TestCaseApi.getplantestcase(projectname, taskid,"");
@ -158,18 +157,18 @@ public class WebTestControl{
String testtime = LogOperation.getTestTime(taskid);
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid);
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid, testJob, tastcount);
// 关闭浏览器
wd.quit();
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname,
"构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid);
"构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid, testJob, tastcount);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname,
"项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid);
"项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid, testJob, tastcount);
}
}

View File

@ -1,16 +1,5 @@
package luckyclient.caserun.exwebdriver.ex;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import luckyclient.caserun.exinterface.TestCaseExecution;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.caserun.exwebdriver.BaseWebDrive;
@ -21,6 +10,16 @@ import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.publicclass.ChangString;
import luckyclient.publicclass.LogUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* =================================================================
@ -76,7 +75,8 @@ public class WebCaseExecution extends TestCaseExecution {
// ÅÐϽá¹û
setresult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog);
if (0 != setresult) {
// 失败并且不在继续,直接终止
if (0 != setresult && step.getFailcontinue() == 0) {
break;
}
}

View File

@ -1,8 +1,9 @@
package luckyclient.mail;
import java.util.Properties;
import luckyclient.dblog.LogOperation;
import luckyclient.planapi.entity.TestJobs;
import java.util.Properties;
/**
* =================================================================
@ -16,7 +17,35 @@ import luckyclient.dblog.LogOperation;
*/
public class MailSendInitialization {
public static void sendMailInitialization(String subject, String content, String taskid) {
public static void sendMailInitialization(String subject, String content, String taskid, TestJobs testJob, int[] taskCount) {
boolean isSend = false;
if (null == taskCount) {
isSend = true;
} else {
if (taskCount.length == 5 && null != testJob) {
Integer sendCondition = testJob.getSendCondition();
// 成功了发送, casecount != casesuc
if (1 == sendCondition) {
if (taskCount[0] == taskCount[1]) {
isSend = true;
}
}
// 失败了发送
if (-1 == sendCondition) {
if (taskCount[2] > 0) {
isSend = true;
}
}
// 全发
if (0 == sendCondition) {
isSend = true;
}
}
}
if (!isSend) {
luckyclient.publicclass.LogUtil.APP.info("当前任务不需要发送邮件通知! taskCount:" + taskCount);
return;
}
String[] addresses = LogOperation.getEmailAddress(taskid);
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
if (addresses != null) {

View File

@ -29,6 +29,8 @@ public class ProjectCasesteps implements java.io.Serializable{
private String time;
private String operationer;
private String remark;
// 失败了是否继续
private Integer failcontinue;
public int getId() {
return id;
}
@ -109,4 +111,11 @@ public class ProjectCasesteps implements java.io.Serializable{
this.remark = remark;
}
public Integer getFailcontinue() {
return failcontinue;
}
public void setFailcontinue(Integer failcontinue) {
this.failcontinue = failcontinue;
}
}

View File

@ -96,6 +96,8 @@ public class TestJobs implements java.io.Serializable {
private String endTimestr;
private String createTime;
private String noEndDate;
// 发送条件
private Integer sendCondition;
public Integer getProjecttype() {
return projecttype;
@ -385,4 +387,11 @@ public class TestJobs implements java.io.Serializable {
this.showRun = showRun;
}
public Integer getSendCondition() {
return sendCondition;
}
public void setSendCondition(Integer sendCondition) {
this.sendCondition = sendCondition;
}
}