From 3ef6e5e8c22fa8729c3612d5a6884107795719c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9F=BA=E7=BC=98?= Date: Tue, 25 Jan 2022 14:31:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E2=80=9C=E8=81=9A=E5=90=88?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E2=80=9D=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=B0=86=E5=A4=9A=E4=B8=AA=E6=B5=8B=E8=AF=95=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E8=81=9A=E5=90=88=E8=B5=B7=E6=9D=A5=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../execution/appium/AppTestControl.java | 110 ++++--- .../execution/appium/CaseLocalDebug.java | 2 +- .../appium/androidex/AndroidBatchExecute.java | 4 +- .../androidex/AndroidCaseExecution.java | 6 +- .../androidex/AndroidCaseLocalDebug.java | 2 +- .../androidex/AndroidOneCaseExecute.java | 2 +- .../appium/iosex/IosBatchExecute.java | 4 +- .../appium/iosex/IosCaseExecution.java | 6 +- .../appium/iosex/IosCaseLocalDebug.java | 2 +- .../appium/iosex/IosOneCaseExecute.java | 2 +- .../dispose/ParamsManageForSteps.java | 3 + .../execution/httpinterface/TestControl.java | 108 ++++--- .../httpinterface/ThreadForExecuteCase.java | 8 +- .../execution/webdriver/CaseLocalDebug.java | 2 +- .../execution/webdriver/WebTestControl.java | 116 ++++--- .../webdriver/ex/WebBatchExecute.java | 4 +- .../webdriver/ex/WebCaseExecution.java | 6 +- .../webdriver/ex/WebOneCaseExecute.java | 2 +- .../luckyclient/remote/api/GetServerApi.java | 10 + .../luckyclient/remote/api/PostServerApi.java | 23 ++ .../remote/api/serverOperation.java | 19 ++ .../remote/entity/ProjectSuite.java | 129 ++++++++ .../remote/entity/TaskCaseExecute.java | 9 + .../remote/entity/TaskScheduling.java | 296 +++++++++--------- 24 files changed, 572 insertions(+), 303 deletions(-) create mode 100644 src/main/java/luckyclient/remote/entity/ProjectSuite.java diff --git a/src/main/java/luckyclient/execution/appium/AppTestControl.java b/src/main/java/luckyclient/execution/appium/AppTestControl.java index 8f0fd09..39c6a56 100644 --- a/src/main/java/luckyclient/execution/appium/AppTestControl.java +++ b/src/main/java/luckyclient/execution/appium/AppTestControl.java @@ -16,11 +16,7 @@ import luckyclient.execution.appium.iosex.IosCaseExecution; import luckyclient.execution.httpinterface.TestControl; import luckyclient.remote.api.GetServerApi; import luckyclient.remote.api.serverOperation; -import luckyclient.remote.entity.ProjectCase; -import luckyclient.remote.entity.ProjectCaseParams; -import luckyclient.remote.entity.ProjectCaseSteps; -import luckyclient.remote.entity.TaskExecute; -import luckyclient.remote.entity.TaskScheduling; +import luckyclient.remote.entity.*; import luckyclient.tool.jenkins.BuildingInitialization; import luckyclient.tool.mail.HtmlMail; import luckyclient.tool.mail.MailSendInitialization; @@ -80,9 +76,9 @@ public class AppTestControl { LogUtil.APP.info("开始执行计划中的第{}条用例:【{}】......",i,testcase.getCaseSign()); try { if ("Android".equals(properties.getProperty("platformName"))) { - AndroidCaseExecution.caseExcution(testcase, steps, taskid, androiddriver, caselog, pcplist); + AndroidCaseExecution.caseExcution(testcase, steps, taskid,null, androiddriver, caselog, pcplist); } else if ("IOS".equals(properties.getProperty("platformName"))) { - IosCaseExecution.caseExcution(testcase, steps, taskid, iosdriver, caselog, pcplist); + IosCaseExecution.caseExcution(testcase, steps, taskid, null,iosdriver, caselog, pcplist); } } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出Exception异常!", e); @@ -127,56 +123,82 @@ public class AppTestControl { if (restartstatus.contains("Status:true")) { // 判断是否构建是否成功 if (BuildResult.SUCCESS.equals(buildResult)) { - try { - if ("Android".equals(properties.getProperty("platformName"))) { - androiddriver = AppiumInitialization.setAndroidAppium(properties); - LogUtil.APP.info("完成AndroidDriver初始化动作...APPIUM Server【http://{}/wd/hub】",properties.getProperty("appiumsever")); - } else if ("IOS".equals(properties.getProperty("platformName"))) { - iosdriver = AppiumInitialization.setIosAppium(properties); - LogUtil.APP.info("完成IOSDriver初始化动作...APPIUM Server【http://{}/wd/hub】",properties.getProperty("appiumsever")); - } - } catch (Exception e) { - LogUtil.APP.error("初始化AppiumDriver出错 !APPIUM Server【http://{}/wd/hub】",properties.getProperty("appiumsever"), e); + + List plans=new ArrayList<>(); + // 单计划执行 + if(taskScheduling.getPlanType()==1){ + ProjectPlan projectPlan=new ProjectPlan(); + projectPlan.setPlanId(taskScheduling.getPlanId()); + plans.add(projectPlan); } - serverOperation caselog = new serverOperation(); - List cases = GetServerApi.getCasesbyplanId(taskScheduling.getPlanId()); - LogUtil.APP.info("当前计划【{}】中共有【{}】条待测试用例...",task.getTaskName(),cases.size()); - serverOperation.updateTaskExecuteStatusIng(taskId, cases.size()); - int i = 0; - for (ProjectCase testcase : cases) { - i++; - LogUtil.APP.info("开始执行当前测试任务 {} 的第【{}】条测试用例:【{}】......",task.getTaskName(),i,testcase.getCaseSign()); - List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); - if (steps.size() == 0) { - continue; - } + // 聚合多计划执行 + else if(taskScheduling.getPlanType()==2){ + plans.addAll(GetServerApi.getPlansbysuiteId(taskScheduling.getSuiteId())); + } + LogUtil.APP.info("当前测试任务 {} 中共有【{}】条测试计划...",task.getTaskName(),plans.size()); + + int caseCount=0; + for(ProjectPlan pp:plans){ + List cases = GetServerApi.getCasesbyplanId(pp.getPlanId()); + caseCount+=cases.size(); + } + + for(ProjectPlan pp:plans){ + try { - //插入开始执行的用例 - caselog.insertTaskCaseExecute(taskId, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4); if ("Android".equals(properties.getProperty("platformName"))) { - AndroidCaseExecution.caseExcution(testcase, steps, taskId, androiddriver, caselog, pcplist); + androiddriver = AppiumInitialization.setAndroidAppium(properties); + LogUtil.APP.info("完成AndroidDriver初始化动作...APPIUM Server【http://{}/wd/hub】",properties.getProperty("appiumsever")); } else if ("IOS".equals(properties.getProperty("platformName"))) { - IosCaseExecution.caseExcution(testcase, steps, taskId, iosdriver, caselog, pcplist); + iosdriver = AppiumInitialization.setIosAppium(properties); + LogUtil.APP.info("完成IOSDriver初始化动作...APPIUM Server【http://{}/wd/hub】",properties.getProperty("appiumsever")); } } catch (Exception e) { - LogUtil.APP.error("用户执行过程中抛出异常!", e); + LogUtil.APP.error("初始化AppiumDriver出错 !APPIUM Server【http://{}/wd/hub】",properties.getProperty("appiumsever"), e); + } + serverOperation caselog = new serverOperation(); + List cases = GetServerApi.getCasesbyplanId(pp.getPlanId()); + LogUtil.APP.info("当前计划【{}】中共有【{}】条待测试用例...",pp.getPlanName(),cases.size()); + serverOperation.updateTaskExecuteStatusIng(taskId, caseCount); + int i = 0; + for (ProjectCase testcase : cases) { + i++; + LogUtil.APP.info("开始执行当前测试任务 {} 的第【{}】条测试用例:【{}】......",task.getTaskName(),i,testcase.getCaseSign()); + List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); + if (steps.size() == 0) { + continue; + } + try { + //插入开始执行的用例 + caselog.insertTaskCaseExecute(taskId, taskScheduling.getProjectId(),pp.getPlanId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4); + if ("Android".equals(properties.getProperty("platformName"))) { + AndroidCaseExecution.caseExcution(testcase, steps, taskId, pp.getPlanId(),androiddriver, caselog, pcplist); + } else if ("IOS".equals(properties.getProperty("platformName"))) { + IosCaseExecution.caseExcution(testcase, steps, taskId, pp.getPlanId(),iosdriver, caselog, pcplist); + } + } catch (Exception e) { + LogUtil.APP.error("用户执行过程中抛出异常!", e); + } + LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); + } + LogUtil.APP.info("当前【{}】测试计划中的用例已经全部执行完成...",pp.getPlanName()); + // 关闭APP以及appium会话 + if ("Android".equals(properties.getProperty("platformName"))) { + assert androiddriver != null; + androiddriver.closeApp(); + } else if ("IOS".equals(properties.getProperty("platformName"))) { + assert iosdriver != null; + iosdriver.closeApp(); } - LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } - tastcount = serverOperation.updateTaskExecuteData(taskId, cases.size(),2); + tastcount = serverOperation.updateTaskExecuteData(taskId, caseCount,2); + tastcount[0]=caseCount; String testtime = serverOperation.getTestTime(taskId); LogUtil.APP.info("当前项目【{}】测试计划中的用例已经全部执行完成...",projectname); MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname), HtmlMail.htmlContentFormat(tastcount, taskId, buildResult.toString(), restartstatus, testtime, jobname), taskId, taskScheduling, tastcount,testtime,buildResult.toString(),restartstatus); - // 关闭APP以及appium会话 - if ("Android".equals(properties.getProperty("platformName"))) { - assert androiddriver != null; - androiddriver.closeApp(); - } else if ("IOS".equals(properties.getProperty("platformName"))) { - assert iosdriver != null; - iosdriver.closeApp(); - } + } else { LogUtil.APP.warn("项目构建失败,自动化测试自动退出!请前往JENKINS中检查项目构建情况。"); MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败,自动化测试自动退出!请前去JENKINS查看构建情况!", taskId, taskScheduling, null,"0小时0分0秒",buildResult.toString(),restartstatus); diff --git a/src/main/java/luckyclient/execution/appium/CaseLocalDebug.java b/src/main/java/luckyclient/execution/appium/CaseLocalDebug.java index af5495b..1e00cde 100644 --- a/src/main/java/luckyclient/execution/appium/CaseLocalDebug.java +++ b/src/main/java/luckyclient/execution/appium/CaseLocalDebug.java @@ -41,7 +41,7 @@ public class CaseLocalDebug{ List pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId())); LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId); List steps=GetServerApi.getStepsbycaseid(testcase.getCaseId()); - AndroidCaseExecution.caseExcution(testcase, steps, "888888", appium, caselog, pcplist); + AndroidCaseExecution.caseExcution(testcase, steps, "888888", null,appium, caselog, pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); diff --git a/src/main/java/luckyclient/execution/appium/androidex/AndroidBatchExecute.java b/src/main/java/luckyclient/execution/appium/androidex/AndroidBatchExecute.java index 57e0aee..1288fbd 100644 --- a/src/main/java/luckyclient/execution/appium/androidex/AndroidBatchExecute.java +++ b/src/main/java/luckyclient/execution/appium/androidex/AndroidBatchExecute.java @@ -64,7 +64,7 @@ public class AndroidBatchExecute { // 删除旧的日志 serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); try { - AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist); + AndroidCaseExecution.caseExcution(testcase, steps, taskid,null, ad, caselog, pcplist); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); } @@ -77,7 +77,7 @@ public class AndroidBatchExecute { // 删除旧的日志 serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); try { - AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist); + AndroidCaseExecution.caseExcution(testcase, steps, taskid,null, ad, caselog, pcplist); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); } diff --git a/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseExecution.java b/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseExecution.java index 9971125..393fd3e 100644 --- a/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseExecution.java +++ b/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseExecution.java @@ -36,8 +36,8 @@ public class AndroidCaseExecution{ static Map variable = new HashMap<>(); private static String casenote = "备注初始化"; - public static void caseExcution(ProjectCase testcase, List steps,String taskid, AndroidDriver appium,serverOperation caselog,List pcplist) { - caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3); + public static void caseExcution(ProjectCase testcase, List steps,String taskid,Integer planId, AndroidDriver appium,serverOperation caselog,List pcplist) { + caselog.updateTaskCaseExecuteStatus(taskid,planId, testcase.getCaseId(), 3); // 把公共参数加入到MAP中 for (ProjectCaseParams pcp : pcplist) { variable.put(pcp.getParamsName(), pcp.getParamsValue()); @@ -106,7 +106,7 @@ public class AndroidCaseExecution{ } variable.clear(); - caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult); + caselog.updateTaskCaseExecuteStatus(taskid, planId,testcase.getCaseId(), setcaseresult); if(setcaseresult==0){ LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign()); caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending",""); diff --git a/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseLocalDebug.java b/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseLocalDebug.java index 39d0ce8..4416997 100644 --- a/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseLocalDebug.java +++ b/src/main/java/luckyclient/execution/appium/androidex/AndroidCaseLocalDebug.java @@ -38,7 +38,7 @@ public class AndroidCaseLocalDebug { .cgetParamsByProjectid(String.valueOf(testcase.getProjectId())); LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId); List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); - AndroidCaseExecution.caseExcution(testcase, steps, "888888", androiddriver, caselog, pcplist); + AndroidCaseExecution.caseExcution(testcase, steps, "888888",null, androiddriver, caselog, pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { diff --git a/src/main/java/luckyclient/execution/appium/androidex/AndroidOneCaseExecute.java b/src/main/java/luckyclient/execution/appium/androidex/AndroidOneCaseExecute.java index 5fa8358..e96eefa 100644 --- a/src/main/java/luckyclient/execution/appium/androidex/AndroidOneCaseExecute.java +++ b/src/main/java/luckyclient/execution/appium/androidex/AndroidOneCaseExecute.java @@ -58,7 +58,7 @@ public class AndroidOneCaseExecute { LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign()); try { List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); - AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist); + AndroidCaseExecution.caseExcution(testcase, steps, taskid,null, ad, caselog, pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); diff --git a/src/main/java/luckyclient/execution/appium/iosex/IosBatchExecute.java b/src/main/java/luckyclient/execution/appium/iosex/IosBatchExecute.java index f16c2fc..a45c2eb 100644 --- a/src/main/java/luckyclient/execution/appium/iosex/IosBatchExecute.java +++ b/src/main/java/luckyclient/execution/appium/iosex/IosBatchExecute.java @@ -63,7 +63,7 @@ public class IosBatchExecute { // 删除旧的日志 serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); try { - IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist); + IosCaseExecution.caseExcution(testcase, steps, taskid,null, iosd, caselog, pcplist); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); } @@ -76,7 +76,7 @@ public class IosBatchExecute { // 删除旧的日志 serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); try { - IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist); + IosCaseExecution.caseExcution(testcase, steps, taskid,null, iosd, caselog, pcplist); } catch (Exception e) { // TODO Auto-generated catch block LogUtil.APP.error("用户执行过程中抛出异常!", e); diff --git a/src/main/java/luckyclient/execution/appium/iosex/IosCaseExecution.java b/src/main/java/luckyclient/execution/appium/iosex/IosCaseExecution.java index b33d29a..c8a8344 100644 --- a/src/main/java/luckyclient/execution/appium/iosex/IosCaseExecution.java +++ b/src/main/java/luckyclient/execution/appium/iosex/IosCaseExecution.java @@ -37,8 +37,8 @@ public class IosCaseExecution{ static Map variable = new HashMap<>(); private static String casenote = "备注初始化"; - public static void caseExcution(ProjectCase testcase, List steps,String taskid, IOSDriver appium,serverOperation caselog,List pcplist) { - caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3); + public static void caseExcution(ProjectCase testcase, List steps,String taskid,Integer planId, IOSDriver appium,serverOperation caselog,List pcplist) { + caselog.updateTaskCaseExecuteStatus(taskid,planId, testcase.getCaseId(), 3); // 把公共参数加入到MAP中 for (ProjectCaseParams pcp : pcplist) { variable.put(pcp.getParamsName(), pcp.getParamsValue()); @@ -109,7 +109,7 @@ public class IosCaseExecution{ } variable.clear(); - caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult); + caselog.updateTaskCaseExecuteStatus(taskid, planId,testcase.getCaseId(), setcaseresult); if(setcaseresult==0){ LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign()); caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending",""); diff --git a/src/main/java/luckyclient/execution/appium/iosex/IosCaseLocalDebug.java b/src/main/java/luckyclient/execution/appium/iosex/IosCaseLocalDebug.java index a3a99fc..80c51f5 100644 --- a/src/main/java/luckyclient/execution/appium/iosex/IosCaseLocalDebug.java +++ b/src/main/java/luckyclient/execution/appium/iosex/IosCaseLocalDebug.java @@ -34,7 +34,7 @@ public class IosCaseLocalDebug { .cgetParamsByProjectid(String.valueOf(testcase.getProjectId())); LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId); List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); - IosCaseExecution.caseExcution(testcase, steps, "888888", iosdriver, caselog, pcplist); + IosCaseExecution.caseExcution(testcase, steps, "888888",null, iosdriver, caselog, pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { diff --git a/src/main/java/luckyclient/execution/appium/iosex/IosOneCaseExecute.java b/src/main/java/luckyclient/execution/appium/iosex/IosOneCaseExecute.java index b986d1d..119ede9 100644 --- a/src/main/java/luckyclient/execution/appium/iosex/IosOneCaseExecute.java +++ b/src/main/java/luckyclient/execution/appium/iosex/IosOneCaseExecute.java @@ -57,7 +57,7 @@ public class IosOneCaseExecute { LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign()); try { List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); - IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist); + IosCaseExecution.caseExcution(testcase, steps, taskid,null, iosd, caselog, pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); diff --git a/src/main/java/luckyclient/execution/dispose/ParamsManageForSteps.java b/src/main/java/luckyclient/execution/dispose/ParamsManageForSteps.java index e44a81f..ec6ee71 100644 --- a/src/main/java/luckyclient/execution/dispose/ParamsManageForSteps.java +++ b/src/main/java/luckyclient/execution/dispose/ParamsManageForSteps.java @@ -29,6 +29,9 @@ public class ParamsManageForSteps { * @date 2019年1月15日 */ public static String paramsManage(String params) { + if(null==params){ + return params; + } ParamsManageForSteps pmfs = new ParamsManageForSteps(); params = pmfs.replaceRandomInt(params); params = pmfs.replaceTimeNow(params); diff --git a/src/main/java/luckyclient/execution/httpinterface/TestControl.java b/src/main/java/luckyclient/execution/httpinterface/TestControl.java index c9bfd2c..22316f8 100644 --- a/src/main/java/luckyclient/execution/httpinterface/TestControl.java +++ b/src/main/java/luckyclient/execution/httpinterface/TestControl.java @@ -10,11 +10,7 @@ import com.offbytwo.jenkins.model.BuildResult; import luckyclient.remote.api.GetServerApi; import luckyclient.remote.api.serverOperation; -import luckyclient.remote.entity.ProjectCase; -import luckyclient.remote.entity.ProjectCaseParams; -import luckyclient.remote.entity.ProjectCaseSteps; -import luckyclient.remote.entity.TaskExecute; -import luckyclient.remote.entity.TaskScheduling; +import luckyclient.remote.entity.*; import luckyclient.tool.jenkins.BuildingInitialization; import luckyclient.tool.mail.HtmlMail; import luckyclient.tool.mail.MailSendInitialization; @@ -64,7 +60,7 @@ public class TestControl { continue; } THREAD_COUNT++; // 多线程计数++,用于检测线程是否全部执行完 - threadExecute.execute(new ThreadForExecuteCase(testcase, steps, taskid, pcplist, caselog)); + threadExecute.execute(new ThreadForExecuteCase(testcase, steps, taskid,null, pcplist, caselog)); } // 多线程计数,用于检测线程是否全部执行完 int i = 0; @@ -105,50 +101,72 @@ public class TestControl { ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy()); - List cases = GetServerApi.getCasesbyplanId(taskScheduling.getPlanId()); - LogUtil.APP.info("当前测试任务 {} 中共有【{}】条待测试用例...",task.getTaskName(),cases.size()); - serverOperation.updateTaskExecuteStatusIng(taskid, cases.size()); - int casepriority = 0; - for (int j = 0; j < cases.size(); j++) { - ProjectCase projectcase = cases.get(j); - List steps = GetServerApi.getStepsbycaseid(projectcase.getCaseId()); - if (steps.size() == 0) { - caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),projectcase.getCaseId(),projectcase.getCaseSign(), projectcase.getCaseName(), 2); - LogUtil.APP.warn("用例【{}】没有找到步骤,直接跳过,请检查!",projectcase.getCaseSign()); - caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(), "在用例中没有找到步骤,请检查", "error", "1", ""); - continue; - } - // 多线程计数,如果用例设置了优先级,必须等优先级高的用例执行完成,才继续后面的用例 - if (casepriority < projectcase.getPriority()) { - LogUtil.APP.info("用例编号:{} 上条用例优先级:{} 当前用例优先级:{}",projectcase.getCaseSign(),casepriority,projectcase.getPriority()); - int i = 0; - while (THREAD_COUNT != 0) { - i++; - if (i > timeout * 60 * 5 / cases.size()) { - LogUtil.APP.warn("用例编号:{} 上条用例优先级:{} 当前用例优先级:{} 等待时间已经超过设置的用例平均超时间{}秒(计算公式:任务超时时间*5/用例总数),现在继续往下执行...",projectcase.getCaseSign(),casepriority,projectcase.getPriority(),i); - break; + List plans=new ArrayList<>(); + + // 单计划执行 + if(taskScheduling.getPlanType()==1){ + ProjectPlan projectPlan=new ProjectPlan(); + projectPlan.setPlanId(taskScheduling.getPlanId()); + plans.add(projectPlan); + } + // 聚合多计划执行 + else if(taskScheduling.getPlanType()==2){ + plans.addAll(GetServerApi.getPlansbysuiteId(taskScheduling.getSuiteId())); + } + LogUtil.APP.info("当前测试任务 {} 中共有【{}】条测试计划...",task.getTaskName(),plans.size()); + + int caseCount=0; + int taskStatus = 2; + for(ProjectPlan pp:plans){ + List cases = GetServerApi.getCasesbyplanId(pp.getPlanId()); + caseCount+=cases.size(); + } + + for(ProjectPlan pp:plans) { + List cases = GetServerApi.getCasesbyplanId(pp.getPlanId()); + LogUtil.APP.info("当前测试计划 {} 中共有【{}】条待测试用例...", pp.getPlanName(), cases.size()); + serverOperation.updateTaskExecuteStatusIng(taskid, caseCount); + int casepriority = 0; + for (int j = 0; j < cases.size(); j++) { + ProjectCase projectcase = cases.get(j); + List steps = GetServerApi.getStepsbycaseid(projectcase.getCaseId()); + if (steps.size() == 0) { + caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),pp.getPlanId(), projectcase.getCaseId(), projectcase.getCaseSign(), projectcase.getCaseName(), 2); + LogUtil.APP.warn("用例【{}】没有找到步骤,直接跳过,请检查!", projectcase.getCaseSign()); + caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(), "在用例中没有找到步骤,请检查", "error", "1", ""); + continue; + } + // 多线程计数,如果用例设置了优先级,必须等优先级高的用例执行完成,才继续后面的用例 + if (casepriority < projectcase.getPriority()) { + LogUtil.APP.info("用例编号:{} 上条用例优先级:{} 当前用例优先级:{}", projectcase.getCaseSign(), casepriority, projectcase.getPriority()); + int i = 0; + while (THREAD_COUNT != 0) { + i++; + if (i > timeout * 60 * 5 / cases.size()) { + LogUtil.APP.warn("用例编号:{} 上条用例优先级:{} 当前用例优先级:{} 等待时间已经超过设置的用例平均超时间{}秒(计算公式:任务超时时间*5/用例总数),现在继续往下执行...", projectcase.getCaseSign(), casepriority, projectcase.getPriority(), i); + break; + } + Thread.sleep(1000); } - Thread.sleep(1000); } + casepriority = projectcase.getPriority(); + THREAD_COUNT++; // 多线程计数++,用于检测线程是否全部执行完 + LogUtil.APP.info("开始执行当前测试任务 {} 的第【{}】条测试用例...", task.getTaskName(), j + 1); + threadExecute.execute(new ThreadForExecuteCase(projectcase, steps, taskid,pp.getPlanId(), pcplist, caselog)); } - casepriority = projectcase.getPriority(); - THREAD_COUNT++; // 多线程计数++,用于检测线程是否全部执行完 - LogUtil.APP.info("开始执行当前测试任务 {} 的第【{}】条测试用例...",task.getTaskName(),j+1); - threadExecute.execute(new ThreadForExecuteCase(projectcase, steps, taskid, pcplist, caselog)); - } - // 多线程计数,用于检测线程是否全部执行完 - int i = 0; - int taskStatus=2; - while (THREAD_COUNT != 0) { - i++; - if (i > timeout * 10) { - taskStatus=3; - LogUtil.APP.warn("当前测试任务 {} 执行已经超过设置的最大任务超时时间【{}】分钟,现在即将停止任务执行...",task.getTaskName(),timeout); - break; + // 多线程计数,用于检测线程是否全部执行完 + int i = 0; + while (THREAD_COUNT != 0) { + i++; + if (i > timeout * 10) { + taskStatus = 3; + LogUtil.APP.warn("当前测试任务 {} 执行已经超过设置的最大任务超时时间【{}】分钟,现在即将停止任务执行...", task.getTaskName(), timeout); + break; + } + Thread.sleep(6000); } - Thread.sleep(6000); } - tastcount = serverOperation.updateTaskExecuteData(taskid, cases.size(),taskStatus); + tastcount = serverOperation.updateTaskExecuteData(taskid, caseCount,taskStatus); String testtime = serverOperation.getTestTime(taskid); MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname), diff --git a/src/main/java/luckyclient/execution/httpinterface/ThreadForExecuteCase.java b/src/main/java/luckyclient/execution/httpinterface/ThreadForExecuteCase.java index 9598343..97518f7 100644 --- a/src/main/java/luckyclient/execution/httpinterface/ThreadForExecuteCase.java +++ b/src/main/java/luckyclient/execution/httpinterface/ThreadForExecuteCase.java @@ -36,17 +36,19 @@ public class ThreadForExecuteCase extends Thread { private String caseSign; private ProjectCase testcase; private String taskid; + private Integer planId; private Integer projectId; private List steps; private List pcplist; private serverOperation caselog; - public ThreadForExecuteCase(ProjectCase projectcase, List steps, String taskid, List pcplist, serverOperation caselog) { + public ThreadForExecuteCase(ProjectCase projectcase, List steps, String taskid,Integer planId, List pcplist, serverOperation caselog) { this.caseId = projectcase.getCaseId(); this.testcase = projectcase; this.projectId = projectcase.getProjectId(); this.caseSign = projectcase.getCaseSign(); this.taskid = taskid; + this.planId=planId; this.steps = steps; this.pcplist = pcplist; this.caselog = caselog; @@ -71,7 +73,7 @@ public class ThreadForExecuteCase extends Thread { int stepJumpNo=0; // 进入循环,解析单个用例所有步骤 // 插入开始执行的用例 - caselog.insertTaskCaseExecute(taskid, projectId, caseId, caseSign, testcase.getCaseName(), 3); + caselog.insertTaskCaseExecute(taskid, projectId, planId,caseId, caseSign, testcase.getCaseName(), 3); for (int i = 0; i < steps.size(); i++) { //处理步骤跳转语法 if(stepJumpNo!=0&&setcaseresult!=0){ @@ -274,7 +276,7 @@ public class ThreadForExecuteCase extends Thread { caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....", "error", "SETCASERESULT...", ""); setcaseresult = 2; } - caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult); + caselog.updateTaskCaseExecuteStatus(taskid, planId,caseId, setcaseresult); if (0 == setcaseresult) { LogUtil.APP.info("用例:{}执行结果成功......",testcase.getCaseSign()); caselog.insertTaskCaseLog(taskid, caseId, "用例步骤执行全部成功......", "info", "ending", ""); diff --git a/src/main/java/luckyclient/execution/webdriver/CaseLocalDebug.java b/src/main/java/luckyclient/execution/webdriver/CaseLocalDebug.java index f28854b..38c1be9 100644 --- a/src/main/java/luckyclient/execution/webdriver/CaseLocalDebug.java +++ b/src/main/java/luckyclient/execution/webdriver/CaseLocalDebug.java @@ -41,7 +41,7 @@ public class CaseLocalDebug{ List pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId())); LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId); List steps=GetServerApi.getStepsbycaseid(testcase.getCaseId()); - WebCaseExecution.caseExcution(testcase,steps, "888888",wd,caselog,pcplist); + WebCaseExecution.caseExcution(testcase,steps, "888888",null,wd,caselog,pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); diff --git a/src/main/java/luckyclient/execution/webdriver/WebTestControl.java b/src/main/java/luckyclient/execution/webdriver/WebTestControl.java index 58e006c..3b457dd 100644 --- a/src/main/java/luckyclient/execution/webdriver/WebTestControl.java +++ b/src/main/java/luckyclient/execution/webdriver/WebTestControl.java @@ -1,39 +1,33 @@ package luckyclient.execution.webdriver; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebDriverException; - import com.offbytwo.jenkins.model.BuildResult; - import luckyclient.execution.httpinterface.TestControl; import luckyclient.execution.webdriver.ex.WebCaseExecution; import luckyclient.remote.api.GetServerApi; import luckyclient.remote.api.serverOperation; -import luckyclient.remote.entity.ProjectCase; -import luckyclient.remote.entity.ProjectCaseParams; -import luckyclient.remote.entity.ProjectCaseSteps; -import luckyclient.remote.entity.TaskExecute; -import luckyclient.remote.entity.TaskScheduling; +import luckyclient.remote.entity.*; import luckyclient.tool.jenkins.BuildingInitialization; import luckyclient.tool.mail.HtmlMail; import luckyclient.tool.mail.MailSendInitialization; import luckyclient.tool.shell.RestartServerInitialization; import luckyclient.utils.LogUtil; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * ================================================================= * 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。 * 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985 * ================================================================= - * + * * @author: seagull - * + * * @date 2017年12月1日 上午9:29:40 - * + * */ public class WebTestControl { @@ -68,7 +62,7 @@ public class WebTestControl { i++; LogUtil.APP.info("开始执行第{}条用例:【{}】......",i,testcase.getCaseSign()); try { - WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist); + WebCaseExecution.caseExcution(testcase, steps, taskid, null,wd, caselog, pcplist); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); } @@ -87,58 +81,82 @@ public class WebTestControl { TestControl.TASKID = taskid; String restartstatus = RestartServerInitialization.restartServerRun(taskid); BuildResult buildResult = BuildingInitialization.buildingRun(taskid); - List pcplist = GetServerApi.cgetParamsByProjectid(task.getProjectId().toString()); TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(task.getTaskId()); + List pcplist = GetServerApi.cgetParamsByProjectid(task.getProjectId().toString()); String projectname = taskScheduling.getProject().getProjectName(); task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskid)); String jobname = taskScheduling.getSchedulingName(); int drivertype = serverOperation.querydrivertype(taskid); - int[] tastcount; + int[] tastcount=new int[5]; // 判断是否要自动重启TOMCAT if (restartstatus.contains("Status:true")) { // 判断是否构建是否成功 if (BuildResult.SUCCESS.equals(buildResult)) { - WebDriver wd = null; - try { - wd = WebDriverInitialization.setWebDriverForTask(drivertype); - } catch (WebDriverException e1) { - LogUtil.APP.error("初始化WebDriver出错 WebDriverException!", e1); - } catch (IOException e2) { - LogUtil.APP.error("初始化WebDriver出错 IOException!", e2); + + List plans=new ArrayList<>(); + // 单计划执行 + if(taskScheduling.getPlanType()==1){ + ProjectPlan projectPlan=new ProjectPlan(); + projectPlan.setPlanId(taskScheduling.getPlanId()); + plans.add(projectPlan); + } + // 聚合多计划执行 + else if(taskScheduling.getPlanType()==2){ + plans.addAll(GetServerApi.getPlansbysuiteId(taskScheduling.getSuiteId())); } - serverOperation caselog = new serverOperation(); + LogUtil.APP.info("当前测试任务 {} 中共有【{}】条测试计划...",task.getTaskName(),plans.size()); - List cases = GetServerApi.getCasesbyplanId(taskScheduling.getPlanId()); - LogUtil.APP.info("当前测试任务 {} 中共有【{}】条待测试用例...",task.getTaskName(),cases.size()); - serverOperation.updateTaskExecuteStatusIng(taskid, cases.size()); - int i = 0; - for (ProjectCase testcase : cases) { - i++; - LogUtil.APP.info("开始执行当前测试任务 {} 的第【{}】条测试用例:【{}】......",task.getTaskName(),i,testcase.getCaseSign()); - List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); - if (steps.size() == 0) { - continue; - } + int caseCount=0; + for(ProjectPlan pp:plans){ + List cases = GetServerApi.getCasesbyplanId(pp.getPlanId()); + caseCount+=cases.size(); + } + + for(ProjectPlan pp:plans){ + WebDriver wd = null; try { - // 插入开始执行的用例 - caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4); - WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist); - } catch (Exception e) { - // TODO Auto-generated catch block - LogUtil.APP.error("用户执行过程中抛出异常!", e); + wd = WebDriverInitialization.setWebDriverForTask(drivertype); + } catch (WebDriverException e1) { + LogUtil.APP.error("初始化WebDriver出错 WebDriverException!", e1); + } catch (IOException e2) { + LogUtil.APP.error("初始化WebDriver出错 IOException!", e2); + } + + serverOperation caselog = new serverOperation(); + List cases = GetServerApi.getCasesbyplanId(pp.getPlanId()); + LogUtil.APP.info("当前测试计划 {} 中共有【{}】条待测试用例...",pp.getPlanName(),cases.size()); + LogUtil.APP.info("开始执行当前测试计划 {} ......",pp.getPlanName()); + serverOperation.updateTaskExecuteStatusIng(taskid, caseCount); + int i = 0; + for (ProjectCase testcase : cases) { + i++; + LogUtil.APP.info("开始执行当前测试任务 {} 的第【{}】条测试用例:【{}】......",task.getTaskName(),i,testcase.getCaseSign()); + List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); + if (steps.size() == 0) { + continue; + } + try { + // 插入开始执行的用例 + caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),pp.getPlanId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4); + WebCaseExecution.caseExcution(testcase, steps, taskid,pp.getPlanId(),wd, caselog, pcplist); + } catch (Exception e) { + // TODO Auto-generated catch block + LogUtil.APP.error("用户执行过程中抛出异常!", e); + } + LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } - LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); + LogUtil.APP.info("当前【{}】测试计划中的用例已经全部执行完成...",pp.getPlanName()); + assert wd != null; + wd.quit(); } - tastcount = serverOperation.updateTaskExecuteData(taskid, cases.size(),2); + tastcount = serverOperation.updateTaskExecuteData(taskid, caseCount,2); + tastcount[0]=caseCount; String testtime = serverOperation.getTestTime(taskid); LogUtil.APP.info("当前项目【{}】测试计划中的用例已经全部执行完成...",projectname); MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname), HtmlMail.htmlContentFormat(tastcount, taskid, buildResult.toString(), restartstatus, testtime, jobname), taskid, taskScheduling, tastcount,testtime,buildResult.toString(),restartstatus); - // 关闭浏览器 - assert wd != null; - wd.quit(); } else { LogUtil.APP.warn("项目构建失败,自动化测试自动退出!请前往JENKINS中检查项目构建情况。"); MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败,自动化测试自动退出!请前去JENKINS查看构建情况!", taskid, diff --git a/src/main/java/luckyclient/execution/webdriver/ex/WebBatchExecute.java b/src/main/java/luckyclient/execution/webdriver/ex/WebBatchExecute.java index bdf544d..076c0d2 100644 --- a/src/main/java/luckyclient/execution/webdriver/ex/WebBatchExecute.java +++ b/src/main/java/luckyclient/execution/webdriver/ex/WebBatchExecute.java @@ -52,7 +52,7 @@ public class WebBatchExecute{ //删除旧的日志 serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); try { - WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist); + WebCaseExecution.caseExcution(testcase, steps, taskid,null, wd, caselog, pcplist); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); } @@ -65,7 +65,7 @@ public class WebBatchExecute{ //删除旧的日志 serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); try { - WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist); + WebCaseExecution.caseExcution(testcase, steps, taskid,null, wd, caselog, pcplist); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); } diff --git a/src/main/java/luckyclient/execution/webdriver/ex/WebCaseExecution.java b/src/main/java/luckyclient/execution/webdriver/ex/WebCaseExecution.java index d822903..2534268 100644 --- a/src/main/java/luckyclient/execution/webdriver/ex/WebCaseExecution.java +++ b/src/main/java/luckyclient/execution/webdriver/ex/WebCaseExecution.java @@ -39,8 +39,8 @@ public class WebCaseExecution{ private static Map variable = new HashMap<>(); private static String casenote = "备注初始化"; - public static void caseExcution(ProjectCase testcase, List steps, String taskid, WebDriver wd, serverOperation caselog, List pcplist) { - caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3); + public static void caseExcution(ProjectCase testcase, List steps, String taskid,Integer planId, WebDriver wd, serverOperation caselog, List pcplist) { + caselog.updateTaskCaseExecuteStatus(taskid,planId, testcase.getCaseId(), 3); // 把公共参数加入到MAP中 for (ProjectCaseParams pcp : pcplist) { variable.put(pcp.getParamsName(), pcp.getParamsValue()); @@ -109,7 +109,7 @@ public class WebCaseExecution{ } variable.clear(); - caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult); + caselog.updateTaskCaseExecuteStatus(taskid,planId, testcase.getCaseId(), setcaseresult); if (setcaseresult == 0) { LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign()); caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功", "info", "ending", ""); diff --git a/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java b/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java index 904ed17..60f6669 100644 --- a/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java +++ b/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java @@ -47,7 +47,7 @@ public class WebOneCaseExecute{ LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign()); try { List steps=GetServerApi.getStepsbycaseid(testcase.getCaseId()); - WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist); + WebCaseExecution.caseExcution(testcase, steps, taskid,null,wd,caselog,pcplist); LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign()); } catch (Exception e) { LogUtil.APP.error("用户执行过程中抛出异常!", e); diff --git a/src/main/java/luckyclient/remote/api/GetServerApi.java b/src/main/java/luckyclient/remote/api/GetServerApi.java index fdeba09..091eed1 100644 --- a/src/main/java/luckyclient/remote/api/GetServerApi.java +++ b/src/main/java/luckyclient/remote/api/GetServerApi.java @@ -34,6 +34,16 @@ public class GetServerApi { return JSONObject.parseArray(result, ProjectCase.class); } + /** + * 通过计划ID获取测试用例对象集 + * @param suiteId 测试计划ID + * @return 返回用例List + */ + public static List getPlansbysuiteId(int suiteId) { + String result = HttpRequest.loadJSON(PREFIX+"/clientGetPlanListBySuiteId.do?suiteId=" + suiteId); + return JSONObject.parseArray(result, ProjectPlan.class); + } + /** * 通过计划名称获取测试用例对象集 * @param name 测试计划名称 diff --git a/src/main/java/luckyclient/remote/api/PostServerApi.java b/src/main/java/luckyclient/remote/api/PostServerApi.java index 780bd0b..8c4c47f 100644 --- a/src/main/java/luckyclient/remote/api/PostServerApi.java +++ b/src/main/java/luckyclient/remote/api/PostServerApi.java @@ -63,6 +63,19 @@ public class PostServerApi { HttpRequest.httpClientPostJson(PREFIX+"/clientPostTaskCaseExecute", JSONObject.toJSONString(taskCaseExecute)); } + + public static void clientPostInsertTaskCaseExecute(Integer taskId, Integer projectId,Integer planId, Integer caseId, String caseSign, String caseName, Integer caseStatus){ + TaskCaseExecute taskCaseExecute = new TaskCaseExecute(); + taskCaseExecute.setTaskId(taskId); + taskCaseExecute.setPlanId(planId); + taskCaseExecute.setProjectId(projectId); + taskCaseExecute.setCaseId(caseId); + taskCaseExecute.setCaseSign(caseSign); + taskCaseExecute.setCaseName(caseName); + taskCaseExecute.setCaseStatus(caseStatus); + + HttpRequest.httpClientPostJson(PREFIX+"/clientPostTaskCaseExecute", JSONObject.toJSONString(taskCaseExecute)); + } /** * 修改用例执行状态 @@ -80,6 +93,16 @@ public class PostServerApi { HttpRequest.httpClientPostJson(PREFIX+"/clientUpdateTaskCaseExecuteStatus", JSONObject.toJSONString(taskCaseExecute)); } + + public static void clientUpdateTaskCaseExecuteStatus(Integer taskId,Integer planId, Integer caseId, Integer caseStatus){ + TaskCaseExecute taskCaseExecute = new TaskCaseExecute(); + taskCaseExecute.setTaskId(taskId); + taskCaseExecute.setPlanId(planId); + taskCaseExecute.setCaseId(caseId); + taskCaseExecute.setCaseStatus(caseStatus); + + HttpRequest.httpClientPostJson(PREFIX+"/clientUpdateTaskCaseExecuteStatus", JSONObject.toJSONString(taskCaseExecute)); + } /** * 插入用例执行明细到数据库 diff --git a/src/main/java/luckyclient/remote/api/serverOperation.java b/src/main/java/luckyclient/remote/api/serverOperation.java index d30dcdf..7aa9d1e 100644 --- a/src/main/java/luckyclient/remote/api/serverOperation.java +++ b/src/main/java/luckyclient/remote/api/serverOperation.java @@ -35,6 +35,16 @@ public class serverOperation { } } + /** + * 插入用例执行状态 0通过 1失败 2锁定 3执行中 4未执行 + */ + public void insertTaskCaseExecute(String taskIdStr, Integer projectId,Integer planId,Integer caseId, String caseSign,String caseName, Integer caseStatus) { + if (0 == exetype) { + Integer taskId=Integer.valueOf(taskIdStr); + PostServerApi.clientPostInsertTaskCaseExecute(taskId, projectId,planId, caseId, caseSign, caseName, caseStatus); + } + } + /** * 更新用例执行状态 0通过 1失败 2锁定 3执行中 4未执行 */ @@ -45,6 +55,15 @@ public class serverOperation { } } + public void updateTaskCaseExecuteStatus(String taskIdStr,Integer planId, Integer caseId, Integer caseStatus) { + if (0 == exetype) { + Integer taskId=Integer.valueOf(taskIdStr); + PostServerApi.clientUpdateTaskCaseExecuteStatus(taskId,planId, caseId, caseStatus); + } + } + + + /** * 插入用例执行日志 */ diff --git a/src/main/java/luckyclient/remote/entity/ProjectSuite.java b/src/main/java/luckyclient/remote/entity/ProjectSuite.java new file mode 100644 index 0000000..38ad1f2 --- /dev/null +++ b/src/main/java/luckyclient/remote/entity/ProjectSuite.java @@ -0,0 +1,129 @@ +package luckyclient.remote.entity; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +public class ProjectSuite extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** 鑱氬悎璁″垝ID */ + private Integer suiteId; + /** 鑱氬悎璁″垝鍚嶇О */ + private String suiteName; + /** 鑱氬悎涓殑璁″垝鎬绘暟 */ + private Integer suitePlanCount; + /** 椤圭洰ID */ + private Integer projectId; + /** 鍒涘缓鑰 */ + private String createBy; + /** 鍒涘缓鏃堕棿 */ + private Date createTime; + /** 鏇存柊鑰 */ + private String updateBy; + /** 鏇存柊鏃堕棿 */ + private Date updateTime; + /** 澶囨敞 */ + private String remark; + /** 鍏宠仈椤圭洰瀹炰綋 */ + private Project project; + + public Integer getSuiteId() { + return suiteId; + } + + public void setSuiteId(Integer suiteId) { + this.suiteId = suiteId; + } + + public String getSuiteName() { + return suiteName; + } + + public void setSuiteName(String suiteName) { + this.suiteName = suiteName; + } + + public Integer getSuitePlanCount() { + return suitePlanCount; + } + + public void setSuitePlanCount(Integer suitePlanCount) { + this.suitePlanCount = suitePlanCount; + } + + public Integer getProjectId() { + return projectId; + } + + public void setProjectId(Integer projectId) { + this.projectId = projectId; + } + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getUpdateBy() { + return updateBy; + } + + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public String toString(){ + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("suiteId", getSuiteId()) + .append("suiteName", getSuiteName()) + .append("suitePlanCount", getSuitePlanCount()) + .append("projectId", getProjectId()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("project", getProject()) + .toString(); + } + +} + diff --git a/src/main/java/luckyclient/remote/entity/TaskCaseExecute.java b/src/main/java/luckyclient/remote/entity/TaskCaseExecute.java index 4e33192..4e77e7e 100644 --- a/src/main/java/luckyclient/remote/entity/TaskCaseExecute.java +++ b/src/main/java/luckyclient/remote/entity/TaskCaseExecute.java @@ -19,6 +19,8 @@ public class TaskCaseExecute extends BaseEntity private Integer taskCaseId; /** 任务ID */ private Integer taskId; + /** 计划ID */ + private Integer planId; /** 项目ID */ private Integer projectId; /** 用例ID */ @@ -58,6 +60,13 @@ public class TaskCaseExecute extends BaseEntity { return taskId; } + public Integer getPlanId() { + return planId; + } + + public void setPlanId(Integer planId) { + this.planId = planId; + } public void setProjectId(Integer projectId) { this.projectId = projectId; diff --git a/src/main/java/luckyclient/remote/entity/TaskScheduling.java b/src/main/java/luckyclient/remote/entity/TaskScheduling.java index 9d6effc..f1bc722 100644 --- a/src/main/java/luckyclient/remote/entity/TaskScheduling.java +++ b/src/main/java/luckyclient/remote/entity/TaskScheduling.java @@ -15,7 +15,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; public class TaskScheduling extends BaseEntity { private static final long serialVersionUID = 1L; - + /** 预约调度ID */ private Integer schedulingId; /** 预约调度名称 */ @@ -26,6 +26,8 @@ public class TaskScheduling extends BaseEntity private Integer projectId; /** 测试计划ID */ private Integer planId; + /** 聚合计划ID */ + private Integer suiteId; /** 客户端ID */ private Integer clientId; /** 环境 */ @@ -46,6 +48,8 @@ public class TaskScheduling extends BaseEntity private Integer taskType; /** UI自动化浏览器类型 0 IE 1 火狐 2 谷歌 3 Edge */ private Integer browserType; + /** 计划类型 1 单计划 2 聚合计划 */ + private Integer planType; /** 任务超时时间(分钟) */ private Integer taskTimeout; /** 客户端测试驱动桩路径 */ @@ -54,12 +58,22 @@ public class TaskScheduling extends BaseEntity private Project project; /** 关联项目计划 */ private ProjectPlan projectPlan; + /** 关联聚合计划 */ + private ProjectSuite projectSuite; /** 任务名称 */ - private String jobName; - /** cron执行表达式 */ - private String cronExpression; - /** 任务状态(0正常 1暂停) */ - private String status; + private String jobName; + /** cron执行表达式 */ + private String cronExpression; + /** 任务状态(0正常 1暂停) */ + private String status; + + public Integer getSchedulingId() { + return schedulingId; + } + + public void setSchedulingId(Integer schedulingId) { + this.schedulingId = schedulingId; + } public String getSchedulingName() { return schedulingName; @@ -69,210 +83,212 @@ public class TaskScheduling extends BaseEntity this.schedulingName = schedulingName; } - public String getJobName() { - return jobName; + public Integer getJobId() { + return jobId; } - public void setJobName(String jobName) { - this.jobName = jobName; + public void setJobId(Integer jobId) { + this.jobId = jobId; } - public String getCronExpression() { - return cronExpression; + public Integer getProjectId() { + return projectId; } - public void setCronExpression(String cronExpression) { - this.cronExpression = cronExpression; + public void setProjectId(Integer projectId) { + this.projectId = projectId; } - public String getStatus() { - return status; + public Integer getPlanId() { + return planId; } - public void setStatus(String status) { - this.status = status; + public void setPlanId(Integer planId) { + this.planId = planId; } - public ProjectPlan getProjectPlan() { - return projectPlan; + public Integer getSuiteId() { + return suiteId; } - public void setProjectPlan(ProjectPlan projectPlan) { - this.projectPlan = projectPlan; + public void setSuiteId(Integer suiteId) { + this.suiteId = suiteId; } - public Project getProject() { - return project; + public Integer getClientId() { + return clientId; } - public void setProject(Project project) { - this.project = project; + public void setClientId(Integer clientId) { + this.clientId = clientId; } - public void setSchedulingId(Integer schedulingId) - { - this.schedulingId = schedulingId; + public String getEnvName() { + return envName; } - public Integer getSchedulingId() - { - return schedulingId; + public void setEnvName(String envName) { + this.envName = envName; } - public void setJobId(Integer jobId) - { - this.jobId = jobId; + + public String getEmailAddress() { + return emailAddress; } - public Integer getJobId() - { - return jobId; + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; } - public void setProjectId(Integer projectId) - { - this.projectId = projectId; + + public String getPushUrl() { + return pushUrl; } - public Integer getProjectId() - { - return projectId; + public void setPushUrl(String pushUrl) { + this.pushUrl = pushUrl; } - public void setPlanId(Integer planId) - { - this.planId = planId; + + public Integer getEmailSendCondition() { + return emailSendCondition; } - public Integer getPlanId() - { - return planId; + public void setEmailSendCondition(Integer emailSendCondition) { + this.emailSendCondition = emailSendCondition; } - public void setClientId(Integer clientId) - { - this.clientId = clientId; + + public String getBuildingLink() { + return buildingLink; } - public Integer getClientId() - { - return clientId; + public void setBuildingLink(String buildingLink) { + this.buildingLink = buildingLink; } - public void setEmailAddress(String emailAddress) - { - this.emailAddress = emailAddress; + + public String getRemoteShell() { + return remoteShell; } - public String getEnvName() { - return envName; + public void setRemoteShell(String remoteShell) { + this.remoteShell = remoteShell; } - public void setEnvName(String envName) { - this.envName = envName; + public Integer getExThreadCount() { + return exThreadCount; } - public String getEmailAddress() - { - return emailAddress; + public void setExThreadCount(Integer exThreadCount) { + this.exThreadCount = exThreadCount; } - public void setPushUrl(String pushUrl) - { - this.pushUrl = pushUrl; + public Integer getTaskType() { + return taskType; } - public String getPushUrl() - { - return pushUrl; + + public void setTaskType(Integer taskType) { + this.taskType = taskType; } - public void setEmailSendCondition(Integer emailSendCondition) - { - this.emailSendCondition = emailSendCondition; + public Integer getBrowserType() { + return browserType; } - public Integer getEmailSendCondition() - { - return emailSendCondition; + public void setBrowserType(Integer browserType) { + this.browserType = browserType; } - public void setBuildingLink(String buildingLink) - { - this.buildingLink = buildingLink; + + public Integer getPlanType() { + return planType; } - public String getBuildingLink() - { - return buildingLink; + public void setPlanType(Integer planType) { + this.planType = planType; } - public void setRemoteShell(String remoteShell) - { - this.remoteShell = remoteShell; + + public Integer getTaskTimeout() { + return taskTimeout; } - public String getRemoteShell() - { - return remoteShell; + public void setTaskTimeout(Integer taskTimeout) { + this.taskTimeout = taskTimeout; } - public void setExThreadCount(Integer exThreadCount) - { - this.exThreadCount = exThreadCount; + + public String getClientDriverPath() { + return clientDriverPath; } - public Integer getExThreadCount() - { - return exThreadCount; + public void setClientDriverPath(String clientDriverPath) { + this.clientDriverPath = clientDriverPath; } - public void setTaskType(Integer taskType) - { - this.taskType = taskType; + + public Project getProject() { + return project; } - public Integer getTaskType() - { - return taskType; + public void setProject(Project project) { + this.project = project; } - public void setBrowserType(Integer browserType) - { - this.browserType = browserType; + + public ProjectPlan getProjectPlan() { + return projectPlan; } - public Integer getBrowserType() - { - return browserType; + public void setProjectPlan(ProjectPlan projectPlan) { + this.projectPlan = projectPlan; } - public void setTaskTimeout(Integer taskTimeout) - { - this.taskTimeout = taskTimeout; + + public ProjectSuite getProjectSuite() { + return projectSuite; } - public Integer getTaskTimeout() - { - return taskTimeout; + public void setProjectSuite(ProjectSuite projectSuite) { + this.projectSuite = projectSuite; } - public void setClientDriverPath(String clientDriverPath) - { - this.clientDriverPath = clientDriverPath; + + public String getJobName() { + return jobName; } - public String getClientDriverPath() - { - return clientDriverPath; + 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; + } + + @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("envName", getEnvName()) - .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(); - } + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("schedulingId", getSchedulingId()) + .append("jobId", getJobId()) + .append("projectId", getProjectId()) + .append("planId", getPlanId()) + .append("suiteId", getSuiteId()) + .append("clientId", getClientId()) + .append("envName", getEnvName()) + .append("emailAddress", getEmailAddress()) + .append("pushUrl", getPushUrl()) + .append("emailSendCondition", getEmailSendCondition()) + .append("buildingLink", getBuildingLink()) + .append("remoteShell", getRemoteShell()) + .append("exThreadCount", getExThreadCount()) + .append("taskType", getTaskType()) + .append("planType", getPlanType()) + .append("browserType", getBrowserType()) + .append("taskTimeout", getTaskTimeout()) + .append("clientDriverPath", getClientDriverPath()) + .toString(); + } } \ No newline at end of file -- Gitee