From 17b5091e89663f236185c05d645b37a8d1710536 Mon Sep 17 00:00:00 2001 From: leo <1009518044@qq.com> Date: Wed, 24 Oct 2018 11:18:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E6=9B=B4=E5=8A=A0=E7=BB=86=E7=B2=92?= =?UTF-8?q?=E5=BA=A6=E7=9A=84=E6=8E=A7=E5=88=B6=E9=82=AE=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=80=BB=E8=BE=91=202.webUI=E5=9C=A8=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=AD=A5=E9=AA=A4=E5=A4=B1=E8=B4=A5=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6=E7=BB=A7?= =?UTF-8?q?=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../caserun/exappium/AppTestControl.java | 24 ++++++------- .../caserun/exinterface/TestControl.java | 29 +++++++-------- .../caserun/exwebdriver/WebTestControl.java | 17 +++++---- .../exwebdriver/ex/WebCaseExecution.java | 28 +++++++-------- .../mail/MailSendInitialization.java | 35 +++++++++++++++++-- .../planapi/entity/ProjectCasesteps.java | 11 +++++- .../luckyclient/planapi/entity/TestJobs.java | 9 +++++ 7 files changed, 99 insertions(+), 54 deletions(-) diff --git a/src/main/java/luckyclient/caserun/exappium/AppTestControl.java b/src/main/java/luckyclient/caserun/exappium/AppTestControl.java index 1e18c59..645e894 100644 --- a/src/main/java/luckyclient/caserun/exappium/AppTestControl.java +++ b/src/main/java/luckyclient/caserun/exappium/AppTestControl.java @@ -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 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); } } diff --git a/src/main/java/luckyclient/caserun/exinterface/TestControl.java b/src/main/java/luckyclient/caserun/exinterface/TestControl.java index a1045bb..cee9140 100644 --- a/src/main/java/luckyclient/caserun/exinterface/TestControl.java +++ b/src/main/java/luckyclient/caserun/exinterface/TestControl.java @@ -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 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(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); } } diff --git a/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java b/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java index b8f3110..3f74338 100644 --- a/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java +++ b/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java @@ -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); - // 判断是否要自动重启TOMCAT + 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); } } diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java index 1637d6c..894a6dd 100644 --- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java +++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java @@ -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,9 +75,10 @@ public class WebCaseExecution extends TestCaseExecution { // 判断结果 setresult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog); - if (0 != setresult) { - break; - } + // 失败,并且不在继续,直接终止 + if (0 != setresult && step.getFailcontinue() == 0) { + break; + } } variable.clear(); diff --git a/src/main/java/luckyclient/mail/MailSendInitialization.java b/src/main/java/luckyclient/mail/MailSendInitialization.java index 86e58c3..9e485b8 100644 --- a/src/main/java/luckyclient/mail/MailSendInitialization.java +++ b/src/main/java/luckyclient/mail/MailSendInitialization.java @@ -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) { diff --git a/src/main/java/luckyclient/planapi/entity/ProjectCasesteps.java b/src/main/java/luckyclient/planapi/entity/ProjectCasesteps.java index 20d9949..033e258 100644 --- a/src/main/java/luckyclient/planapi/entity/ProjectCasesteps.java +++ b/src/main/java/luckyclient/planapi/entity/ProjectCasesteps.java @@ -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; } @@ -108,5 +110,12 @@ public class ProjectCasesteps implements java.io.Serializable{ public void setRemark(String remark) { this.remark = remark; } - + + public Integer getFailcontinue() { + return failcontinue; + } + + public void setFailcontinue(Integer failcontinue) { + this.failcontinue = failcontinue; + } } diff --git a/src/main/java/luckyclient/planapi/entity/TestJobs.java b/src/main/java/luckyclient/planapi/entity/TestJobs.java index 1764e94..bdc2717 100644 --- a/src/main/java/luckyclient/planapi/entity/TestJobs.java +++ b/src/main/java/luckyclient/planapi/entity/TestJobs.java @@ -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; + } } From 58440c7c5f2bd2011c21f86c6b5862a2e75fb6fd Mon Sep 17 00:00:00 2001 From: leo <1009518044@qq.com> Date: Wed, 24 Oct 2018 14:03:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../caserun/exwebdriver/ex/WebCaseExecution.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java index 894a6dd..f24d2a9 100644 --- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java +++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java @@ -76,8 +76,13 @@ public class WebCaseExecution extends TestCaseExecution { // 判断结果 setresult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog); // 失败,并且不在继续,直接终止 - if (0 != setresult && step.getFailcontinue() == 0) { - break; + if (0 != setresult) { + if (step.getFailcontinue() == 0) { + luckyclient.publicclass.LogUtil.APP.error("用例【" + testcase.getSign() + "】步骤【" + step.getOperation() + "】执行过程中失败!本次步骤设置为了失败就终止:" + step.getFailcontinue()); + break; + } else { + luckyclient.publicclass.LogUtil.APP.error("用例【" + testcase.getSign() + "】步骤【" + step.getOperation() + "】执行过程中失败!本次步骤设置为了失败就继续:" + step.getFailcontinue()); + } } }