优化远程接口

This commit is contained in:
seagull 2019-04-23 14:53:15 +08:00
parent 9dbeaa8a95
commit 4092e3413a
21 changed files with 153 additions and 356 deletions

View File

@ -37,8 +37,7 @@ public class OneCaseExecute extends TestControl {
TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(Integer.valueOf(taskid));
if (taskScheduling.getTaskType() == 0) {
// ½Ó¿Ú²âÊÔ
TestCaseExecution.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), testCaseExternalId, version,
String.valueOf(task.getTaskId()));
TestCaseExecution.oneCaseExecuteForTask(taskScheduling.getProject().getProjectName(), testCaseExternalId, String.valueOf(task.getTaskId()));
} else if (taskScheduling.getTaskType() == 1) {
WebOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), testCaseExternalId, version,

View File

@ -143,7 +143,7 @@ public class AppTestControl {
LogOperation caselog = new LogOperation();
List<ProjectCase> cases = GetServerAPI.getCasesbyplanId(taskScheduling.getPlanId());
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogOperation.updateTastStatus(taskId, cases.size());
LogOperation.updateTaskExecuteStatus(taskId, cases.size());
for (ProjectCase testcase : cases) {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
@ -166,7 +166,7 @@ public class AppTestControl {
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
}
tastcount = LogOperation.updateTastdetail(taskId, cases.size());
tastcount = LogOperation.updateTaskExecuteData(taskId, cases.size());
String testtime = LogOperation.getTestTime(taskId);
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),

View File

@ -1,7 +1,6 @@
package luckyclient.caserun.exappium;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import io.appium.java_client.service.local.AppiumDriverLocalService;

View File

@ -57,14 +57,12 @@ public class AndroidBatchExecute {
.cgetParamsByProjectid(task.getProjectId().toString());
// 执行全部非成功状态用例
if (batchcase.indexOf("ALLFAIL") > -1) {
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp = casemore.split("\\#", -1);
for (int i = 0; i < temp.length; i++) {
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
for (int i = 0; i < caseIdList.size(); i++) {
ProjectCase testcase = GetServerAPI.cGetCaseByCaseId(caseIdList.get(i));
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
try {
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
} catch (InterruptedException e) {
@ -82,7 +80,7 @@ public class AndroidBatchExecute {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
try {
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
} catch (InterruptedException e) {
@ -92,7 +90,7 @@ public class AndroidBatchExecute {
}
}
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
ad.closeApp();
//关闭Appium服务的线程
if(as!=null){

View File

@ -52,8 +52,8 @@ public class AndroidOneCaseExecute {
}
LogOperation caselog = new LogOperation();
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testCaseExternalId + "】......");
try {
@ -64,7 +64,7 @@ public class AndroidOneCaseExecute {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
ad.closeApp();
//关闭Appium服务的线程
if(as!=null){

View File

@ -57,14 +57,12 @@ public class IosBatchExecute {
.cgetParamsByProjectid(task.getProjectId().toString());
// 执行全部非成功状态用例
if (batchcase.indexOf("ALLFAIL") > -1) {
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp = casemore.split("\\#", -1);
for (int i = 0; i < temp.length; i++) {
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
for (int i = 0; i < caseIdList.size(); i++) {
ProjectCase testcase = GetServerAPI.cGetCaseByCaseId(caseIdList.get(i));
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
try {
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
} catch (InterruptedException e) {
@ -82,7 +80,7 @@ public class IosBatchExecute {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
try {
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
} catch (InterruptedException e) {
@ -92,7 +90,7 @@ public class IosBatchExecute {
}
}
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
iosd.closeApp();
//关闭Appium服务的线程
if(as!=null){

View File

@ -51,9 +51,10 @@ public class IosOneCaseExecute {
e1.printStackTrace();
}
LogOperation caselog = new LogOperation();
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
// 删除旧的日志
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testCaseExternalId + "】......");
try {
@ -64,7 +65,7 @@ public class IosOneCaseExecute {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
iosd.closeApp();
//关闭Appium服务的线程
if(as!=null){

View File

@ -10,7 +10,6 @@ import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.caserun.publicdispose.ActionManageForSteps;
import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.InvokeMethod;
import luckyclient.publicclass.remoterinterface.HttpRequest;
import luckyclient.serverapi.api.GetServerAPI;
@ -226,22 +225,6 @@ public class ApiTestCaseDebug {
}
}
/**
* 获取指定任务名称以及用例号报错日志中的执行预期结果 casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogDetailExpectresult(String taskname, String caseno, int casestatus) {
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailExpectResult(taskid, caseno, casestatus);
}
/**
* 获取指定任务名称以及用例号报错日志中的执行测试结果 casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogDetailRunresult(String taskname, String caseno, int casestatus) {
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailTestResult(taskid, caseno, casestatus);
}
/**
* 更新系统中用例指定步骤的预期结果
*/

View File

@ -1,12 +1,13 @@
package luckyclient.caserun.exinterface;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import luckyclient.dblog.LogOperation;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.ProjectCase;
/**
* =================================================================
@ -36,21 +37,18 @@ public class BatchTestCaseExecution {
if(batchcase.indexOf("ALLFAIL")>-1){
//初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp=casemore.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()-1));
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
for(int i=0;i<caseIdList.size();i++){
ProjectCase testcase = GetServerAPI.cGetCaseByCaseId(caseIdList.get(i));
TestControl.THREAD_COUNT++; //多线程计数++用于检测线程是否全部执行完
threadExecute.execute(new ThreadForBatchCase(projectname,testCaseExternalId,version,taskid));
threadExecute.execute(new ThreadForBatchCase(projectname,testcase.getCaseSign(),taskid));
}
}else{ //批量执行用例
String[] temp=batchcase.split("\\#",-1);
for(int i=0;i<temp.length-1;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()));
TestControl.THREAD_COUNT++; //多线程计数++用于检测线程是否全部执行完
threadExecute.execute(new ThreadForBatchCase(projectname,testCaseExternalId,version,taskid));
threadExecute.execute(new ThreadForBatchCase(projectname,testCaseExternalId,taskid));
}
}
//多线程计数用于检测线程是否全部执行完

View File

@ -53,7 +53,7 @@ public class TestCaseExecution {
* @param version 用例版本号
* 用于单条用例调试并通过日志框架写日志到UTP上用做UTP上单条用例运行
*/
public static void oneCaseExecuteForTast(String projectname, String testCaseExternalId, int version, String taskid) {
public static void oneCaseExecuteForTask(String projectname, String testCaseExternalId, String taskid) {
TestControl.TASKID = taskid;
DbLink.exetype = 0;
// 初始化写用例结果以及日志模块
@ -65,9 +65,10 @@ public class TestCaseExecution {
Object[] getParameterValues = null;
String testnote = "初始化测试结果";
int k = 0;
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
// 删除旧的日志
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
// 把公共参数加入到MAP中
for (ProjectCaseParams pcp : pcplist) {
@ -178,7 +179,7 @@ public class TestCaseExecution {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "在执行过程中失败,请检查日志!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在执行过程中失败,请检查日志!", "error", "EXECUTECASESUC...", "");
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
}
/**

View File

@ -108,7 +108,7 @@ public class TestControl {
new ArrayBlockingQueue<Runnable>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
List<ProjectCase> cases = GetServerAPI.getCasesbyplanId(taskScheduling.getPlanId());
LogOperation.updateTastStatus(taskid, cases.size());
LogOperation.updateTaskExecuteStatus(taskid, cases.size());
int casepriority = 0;
for (int j = 0; j < cases.size(); j++) {
ProjectCase projectcase = cases.get(j);
@ -146,7 +146,7 @@ public class TestControl {
}
Thread.sleep(6000);
}
tastcount = LogOperation.updateTastdetail(taskid, cases.size());
tastcount = LogOperation.updateTaskExecuteData(taskid, cases.size());
String testtime = LogOperation.getTestTime(taskid);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),

View File

@ -15,19 +15,17 @@ public class ThreadForBatchCase extends Thread{
private String projectname;
private String testCaseExternalId;
private int version;
private String tastid;
private String taskid;
public ThreadForBatchCase(String projectname,String testCaseExternalId,int version,String tastid){
public ThreadForBatchCase(String projectname,String testCaseExternalId,String taskid){
this.projectname = projectname;
this.testCaseExternalId = testCaseExternalId;
this.version = version;
this.tastid = tastid;
this.taskid = taskid;
}
@Override
public void run(){
TestCaseExecution.oneCaseExecuteForTast(projectname, testCaseExternalId, version, tastid);
TestCaseExecution.oneCaseExecuteForTask(projectname, testCaseExternalId, taskid);
TestControl.THREAD_COUNT--; //多线程计数--用于检测线程是否全部执行完
}

View File

@ -1,35 +1,13 @@
package luckyclient.caserun.exwebdriver;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class TestGoogle {
public static void main(String[] args) throws InterruptedException, IOException {
// TODO Auto-generated method stub
WebDriver driver = WebDriverInitialization.setWebDriverForLocal();
driver.get("http://10.213.23.35:8080/ysuser_manager/login.do?method=login");
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
Thread.sleep(20000);
driver.findElement(By.xpath(".//*[@id='tt1']/li[1]/ul/li[2]/div/span[4]/a/span")).click();
WebElement we = driver.findElement(By.xpath(".//*[@src='/ysuser_manager/login.do?method=geturl&limitid=2014020511&homepath=http:']"));
driver.switchTo().frame(we);
// driver.switchTo().frame("mainForm");
WebElement element1 = driver.findElement(By.xpath(".//*[@id='mercId']"));
element1.sendKeys("m00000000000329");
WebElement element2 = driver.findElement(By.xpath("html/body/table[1]/tbody/tr/td[2]"));
String aaa = element2.getText();
String aaaa = element2.getTagName();
element2.getLocation();
/* driver.findElement(By.xpath("html/body/div[1]/div/span[2]/select")).click();
Select select = new Select(driver.findElement(By.xpath("html/body/div[1]/div/span[2]/select")));
List<WebElement> we= select.getAllSelectedOptions();
select.selectByIndex(2);*/
}
}

View File

@ -114,7 +114,7 @@ public class WebTestControl {
List<ProjectCase> cases = GetServerAPI.getCasesbyplanId(taskScheduling.getPlanId());
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogOperation.updateTastStatus(taskid, cases.size());
LogOperation.updateTaskExecuteStatus(taskid, cases.size());
for (ProjectCase testcase : cases) {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
@ -133,7 +133,7 @@ public class WebTestControl {
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
}
tastcount = LogOperation.updateTastdetail(taskid, cases.size());
tastcount = LogOperation.updateTaskExecuteData(taskid, cases.size());
String testtime = LogOperation.getTestTime(taskid);
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");

View File

@ -46,15 +46,12 @@ public class WebBatchExecute{
List<ProjectCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(task.getProjectId().toString());
//执行全部非成功状态用例
if(batchcase.indexOf("ALLFAIL")>-1){
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp=casemore.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
//int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()-1));
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
for(int i=0;i<caseIdList.size();i++){
ProjectCase testcase = GetServerAPI.cGetCaseByCaseId(caseIdList.get(i));
List<ProjectCaseSteps> steps=GetServerAPI.getStepsbycaseid(testcase.getCaseId());
//删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
try {
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
@ -71,7 +68,7 @@ public class WebBatchExecute{
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseSteps> steps=GetServerAPI.getStepsbycaseid(testcase.getCaseId());
//删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
try {
WebCaseExecution.caseExcution(testcase, steps,taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
@ -81,7 +78,7 @@ public class WebBatchExecute{
}
}
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
//关闭浏览器
wd.quit();
}

View File

@ -40,9 +40,10 @@ public class WebOneCaseExecute{
e1.printStackTrace();
}
LogOperation caselog = new LogOperation();
//删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
//删除旧的日志
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
try {
@ -53,7 +54,7 @@ public class WebOneCaseExecute{
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
LogOperation.updateTastdetail(taskid, 0);
LogOperation.updateTaskExecuteData(taskid, 0);
//关闭浏览器
wd.quit();
}

View File

@ -1,12 +1,15 @@
package luckyclient.dblog;
import luckyclient.publicclass.DBOperation;
import luckyclient.serverapi.api.PostServerAPI;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import luckyclient.publicclass.DBOperation;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.api.PostServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
/**
* =================================================================
@ -62,139 +65,66 @@ public class LogOperation {
/**
* 更新本次任务的执行统计情况
* 状态 0未执行 1执行中 2执行完成 3执行失败 4唤起客户端失败
*/
public static int[] updateTastdetail(String taskid, int casecount) {
public static int[] updateTaskExecuteData(String taskIdStr, int caseCount) {
int[] taskcount = null;
if (0 == exetype) {
try {
int id = Integer.parseInt(taskid);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Integer taskId = Integer.parseInt(taskIdStr);
String str = PostServerAPI.clientUpdateTaskExecuteData(taskId, caseCount,2);
JSONObject jsonObject = JSONObject.parseObject(str);
String casesucsql = dbt.executeQuery(
"select count(*) from test_casedetail where taskid = " + id + " and casestatus = 0");
String casefailsql = dbt.executeQuery(
"select count(*) from test_casedetail where taskid = " + id + " and casestatus = 1");
String caselocksql = dbt.executeQuery(
"select count(*) from test_casedetail where taskid = " + id + " and casestatus = 2");
String casenoexesql = dbt.executeQuery(
"select count(*) from test_casedetail where taskid = " + id + " and casestatus = 4");
// 返回本次任务执行情况
taskcount = new int[5];
taskcount[0] = jsonObject.getInteger("caseCount");
taskcount[1] = jsonObject.getInteger("caseSuc");
taskcount[2] = jsonObject.getInteger("caseFail");
taskcount[3] = jsonObject.getInteger("caseLock");
taskcount[4] = jsonObject.getInteger("caseNoExec");
int casesuc = Integer.parseInt(casesucsql.substring(0, casesucsql.indexOf("%")));
int casefail = Integer.parseInt(casefailsql.substring(0, casefailsql.indexOf("%")));
int caselock = Integer.parseInt(caselocksql.substring(0, caselocksql.indexOf("%")));
int casenoexec = Integer.parseInt(casenoexesql.substring(0, casenoexesql.indexOf("%")));
if (casecount == 0) {
casecount = casesuc + casefail + caselock + casenoexec;
}
// 返回本次任务执行情况
taskcount = new int[5];
taskcount[0] = casecount;
taskcount[1] = casesuc;
taskcount[2] = casefail;
taskcount[3] = caselock;
taskcount[4] = casenoexec;
String sql = "update test_taskexcute set casetotal_count = " + casecount + ",casesucc_count = "
+ casesuc + ",casefail_count = " + casefail + ",caselock_count = " + caselock
+ ",casenoexec_count = " + casenoexec + ",finishtime = str_to_date('" + df.format(new Date())
+ "','%Y-%m-%d %T'), " + "taskStatus = 2 where id = " + id;
dbt.executeSql(sql);
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行更新本次任务执行统计情况SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
}
}
return taskcount;
}
/**
* 更新本次任务的执行状态
* 状态 0未执行 1执行中 2执行完成 3执行失败 4唤起客户端失败
*/
public static void updateTastStatus(String taskid, int casecount) {
public static void updateTaskExecuteStatus(String taskIdStr, int caseCount) {
if (0 == exetype) {
try {
int id = Integer.parseInt(taskid);
String sql = "update test_taskexcute set casetotal_count= " + casecount + ",taskStatus = 1 where id = "
+ id;
dbt.executeSql(sql);
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行更新本次任务的执行状态SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
}
Integer taskId = Integer.parseInt(taskIdStr);
PostServerAPI.clientUpdateTaskExecuteData(taskId, caseCount,1);
}
}
/**
* 删除单次任务指定的用例日志明细
*/
public static void deleteCaseLogDetail(String caseno, String taskid) {
int inttaskid = Integer.parseInt(taskid);
String casesidsql;
try {
casesidsql = dbt.executeQuery(
"select id from test_casedetail t where caseno = '" + caseno + "' and taskid = " + inttaskid);
int casesid = Integer.parseInt(casesidsql.substring(0, casesidsql.lastIndexOf("%")));
// 删除原来的日志
dbt.executeSql("delete from test_logdetail where caseid = " + casesid + " and taskid = " + inttaskid);
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行删除单次任务指定的用例日志明细SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
}
public static void deleteTaskCaseLog(Integer caseId, String taskIdStr) {
Integer taskId = Integer.parseInt(taskIdStr);
PostServerAPI.clientDeleteTaskCaseLog(taskId, caseId);
}
/**
* 删除单次任务指定的用例明细
* 取出指定任务ID中的不属于成功状态的用例ID
*/
public static void deleteCaseDetail(String caseno, String taskid) {
int inttaskid = Integer.parseInt(taskid);
try {
// 删除原来的用例
dbt.executeSql("delete from test_casedetail where caseno = '" + caseno + "' and taskid = " + inttaskid);
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行删除单次任务指定的用例明细SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
}
public List<Integer> getCaseListForUnSucByTaskId(String taskIdStr) {
int taskId = Integer.parseInt(taskIdStr);
return GetServerAPI.clientGetCaseListForUnSucByTaskId(taskId);
}
/**
* 取出指定任务ID中的不属于成功状态的用例编写以及版本号
*/
public String unSucCaseUpdate(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
try {
casesidsql = dbt.executeQuery("select caseno,caseversion from test_casedetail t where t.taskid = "
+ inttaskid + " and t.casestatus <> 0");
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行取出指定任务ID中的不属于成功状态的用例编写以及版本号SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
}
return casesidsql;
}
/**
* 取出指定任务ID中所属的调度是否要发送邮件状态及收件人地址 isSendMail varchar(1) default(0); --0 不发送 1
* 取出指定任务ID中所属的调度是否要发送邮件状态及收件人地址 发送邮件通知时的具体逻辑, -1-不通知 0-全部1-成功2-失败
* 发送 eMailer varchar(100) ; --收件人
*/
public static String[] getEmailAddress(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
public static String[] getEmailAddress(String taskIdStr) {
Integer taskId = Integer.parseInt(taskIdStr);
String[] address = null;
try {
casesidsql = dbt.executeQuery(
"select t.issendmail,t.emailer from test_jobs t where id in (select jobid from test_taskexcute t where t.id = "
+ inttaskid + ")");
String status = casesidsql.substring(0, casesidsql.indexOf("%"));
if ("1".equals(status)) {
String temp = casesidsql.substring(casesidsql.indexOf("%") + 1, casesidsql.length() - 1);
TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(taskId);
if (taskScheduling.getEmailSendCondition()!=-1) {
String temp = taskScheduling.getEmailAddress();
// 清除最后一个;
if (temp.indexOf(";") > -1 && temp.substring(temp.length() - 1, temp.length()).indexOf(";") > -1) {
temp = temp.substring(0, temp.length() - 1);
@ -210,7 +140,6 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行取出指定任务ID中所属的调度是否要发送邮件状态及收件人地址SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return address;
}
@ -218,23 +147,17 @@ public class LogOperation {
}
/**
* 取出指定任务ID中所属的调度是否要自动构建以及构建的项目名称 isBuilding varchar(1) default(0); --0
* 不自动构建 1 自动构建 BuildName varchar(100) ; --构建项目名称
* 取出指定任务ID中所属的调度是否要自动构建以及构建的项目名称 为空时不构建
*/
public static String[] getBuildName(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
public static String[] getBuildName(String taskIdStr) {
Integer taskId = Integer.parseInt(taskIdStr);
String[] buildname = null;
try {
casesidsql = dbt.executeQuery(
"select t.isbuilding,t.buildname from test_jobs t where id in (select jobid from test_taskexcute t where t.id = "
+ inttaskid + ")");
if (null == casesidsql || "".equals(casesidsql)) {
TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(taskId);
if (null == taskScheduling.getBuildingLink() || "".equals(taskScheduling.getBuildingLink())) {
return buildname;
}
String status = casesidsql.substring(0, casesidsql.indexOf("%"));
if ("1".equals(status)) {
String temp = casesidsql.substring(casesidsql.indexOf("%") + 1, casesidsql.length() - 1);
}else{
String temp = taskScheduling.getBuildingLink();
// 清除最后一个;
if (temp.indexOf(";") > -1 && temp.substring(temp.length() - 1, temp.length()).indexOf(";") > -1) {
temp = temp.substring(0, temp.length() - 1);
@ -250,7 +173,6 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行取出指定任务ID中所属的调度是否要自动构建以及构建的项目名称SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return buildname;
}
@ -258,26 +180,21 @@ public class LogOperation {
}
/**
* 取出指定任务ID中所属的调度是否要自动重启TOMCAT isrestart varchar(1) default(0); --0 不自动重启 1
* 取出指定任务ID中所属的调度是否要自动重启TOMCAT
* 自动重启 restartcomm varchar(200) ; -- 格式服务器IP;服务器用户名;服务器密码;ssh端口;Shell命令;
* 192.168.222.22;pospsettle;pospsettle;22;cd
* /home/pospsettle/tomcat-7.0-7080/bin&&./restart.sh;
*/
public static String[] getrestartcomm(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
public static String[] getRestartComm(String taskIdStr) {
Integer taskId = Integer.parseInt(taskIdStr);
String[] command = null;
try {
casesidsql = dbt.executeQuery(
"select t.isrestart,t.restartcomm from test_jobs t where id in (select jobid from test_taskexcute t where t.id = "
+ inttaskid + ")");
if (null == casesidsql || "".equals(casesidsql)) {
TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(taskId);
if (null == taskScheduling.getRemoteShell() || "".equals(taskScheduling.getRemoteShell())) {
return command;
}
String status = casesidsql.substring(0, casesidsql.indexOf("%"));
if ("1".equals(status)) {
String temp = casesidsql.substring(casesidsql.indexOf("%") + 1, casesidsql.length() - 1);
}else{
String temp = taskScheduling.getRemoteShell();
// 清除最后一个;
if (temp.indexOf(";") > -1 && temp.substring(temp.length() - 1, temp.length()).indexOf(";") > -1) {
temp = temp.substring(0, temp.length() - 1);
@ -293,7 +210,6 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行取出指定任务ID中所属的调度是否要自动重启TOMCAT SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return command;
}
@ -301,42 +217,17 @@ public class LogOperation {
}
/**
* 获取测试计划名称
*/
public static String getTestPlanName(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String testplanname = "NULL";
try {
String sql = dbt.executeQuery(
"select t.testlinkname from test_jobs t where id in (select jobid from test_taskexcute t where t.id = "
+ inttaskid + ")");
testplanname = sql.substring(0, sql.lastIndexOf("%"));
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行获取测试计划名称SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return testplanname;
}
return testplanname;
}
/**
* 获取任务测试时长
*/
public static String getTestTime(String taskid) {
int inttaskid = Integer.parseInt(taskid);
public static String getTestTime(String taskIdStr) {
Integer taskId = Integer.parseInt(taskIdStr);
String desTime = "计算测试时长出错!";
try {
String sql = dbt.executeQuery(
"select date_format(t.createtime,'%Y-%m-%d %T'),date_format(t.finishtime,'%Y-%m-%d %T') from test_taskexcute t where t.id= "
+ inttaskid);
String starttime = sql.substring(0, sql.indexOf("%"));
String finishtime = sql.substring(sql.indexOf("%") + 1, sql.length() - 1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = df.parse(starttime);
if (StringUtils.isNotBlank(finishtime) && !StringUtils.equalsIgnoreCase(finishtime, "null")) {
Date finish = df.parse(finishtime);
TaskExecute taskExecute = GetServerAPI.cgetTaskbyid(taskId);
Date start = taskExecute.getCreateTime();
if (null!= taskExecute.getFinishTime()) {
Date finish = taskExecute.getFinishTime();
long l = finish.getTime() - start.getTime();
long day = l / (24 * 60 * 60 * 1000);
long hour = (l / (60 * 60 * 1000) - day * 24);
@ -347,7 +238,6 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行获取任务测试时长SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return desTime;
}
@ -355,88 +245,20 @@ public class LogOperation {
}
/**
* 查询web执行浏览器类型
* 查询web执行浏览器类型 UI自动化浏览器类型 0 IE 1 火狐 2 谷歌 3 Edge
*/
public static int querydrivertype(String taskid) {
int taskidtoint = Integer.parseInt(taskid);
int drivertype = 0;
public static int querydrivertype(String taskIdStr) {
Integer taskId = Integer.parseInt(taskIdStr);
Integer driverType = 0;
try {
String sqlresult = dbt.executeQuery(
"select browsertype from test_jobs where id = (select jobid from test_taskexcute where id = "
+ taskidtoint + ")");
drivertype = Integer.parseInt(sqlresult.substring(0, sqlresult.lastIndexOf("%")));
TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(taskId);
driverType = taskScheduling.getBrowserType();
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行查询web执行浏览器类型SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return drivertype;
return driverType;
}
return drivertype;
}
/**
* 查询任务中用例步骤日志执行实际结果
*/
public static String getLogDetailTestResult(int taskid, String caseno, int casestatus) {
String sqlresult = "";
try {
sqlresult = dbt.executeQuery(
"select detail from test_logdetail where logid=(select MIN(logid) from test_logdetail "
+ "where loggrade='error' and taskid=" + taskid
+ " and caseid=(select id from test_casedetail where taskid=" + taskid + " and caseno='"
+ caseno + "' and casestatus='" + casestatus + "'))");
if (sqlresult.indexOf("测试结果:") <= 0 || sqlresult.indexOf("%") <= 0) {
return sqlresult;
}
sqlresult = sqlresult.substring(sqlresult.indexOf("测试结果:") + 5, sqlresult.lastIndexOf("%"));
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行查询任务中用例步骤日志执行实际结果SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return sqlresult;
}
return sqlresult;
}
/**
* 根据任务名称查询任务ID
*/
public static int getTaskExcuteTaskid(String taskname) {
String sqlresult = "";
try {
sqlresult = dbt.executeQuery("select id from test_taskexcute t where t.taskid='" + taskname + "'");
sqlresult = sqlresult.substring(0, sqlresult.lastIndexOf("%"));
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行根据任务名称查询任务ID SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return Integer.parseInt(sqlresult);
}
return Integer.parseInt(sqlresult);
}
/**
* 查询任务中用例步骤日志预期结果 2017-09-16
*/
public static String getLogDetailExpectResult(int taskid, String caseno, int casestatus) {
String sqlresult = "";
try {
sqlresult = dbt.executeQuery(
"select detail from test_logdetail where logid=(select MIN(logid) from test_logdetail "
+ "where loggrade='error' and taskid=" + taskid
+ " and caseid=(select id from test_casedetail where taskid=" + taskid + " and caseno='"
+ caseno + "' and casestatus='" + casestatus + "'))");
if (sqlresult.indexOf("预期结果:") <= 0 || sqlresult.indexOf("%") <= 0) {
return sqlresult;
}
sqlresult = sqlresult.substring(sqlresult.indexOf("预期结果:") + 5, sqlresult.lastIndexOf("测试结果:") - 1);
} catch (Exception e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("执行查询任务中用例步骤日志预期结果 SQL出现异常请确认数据库链接是否正常", e);
e.printStackTrace();
return sqlresult;
}
return sqlresult;
return driverType;
}
public static void main(String[] args) throws Exception {

View File

@ -15,11 +15,10 @@ import luckyclient.dblog.LogOperation;
*/
public class RestartServerInitialization {
@SuppressWarnings("finally")
public static String restartServerRun(String tastid){
String result = "Status:true"+" 重启命令执行成功!";
try{
String[] command = LogOperation.getrestartcomm(tastid);
String[] command = LogOperation.getRestartComm(tastid);
if(command!=null){
luckyclient.publicclass.LogUtil.APP.info("准备重启指定的TOMCAT请稍等。。。参数个数"+command.length);
if(command.length==5){

View File

@ -2,6 +2,7 @@ package luckyclient.publicclass;
import java.io.File;
import java.util.Enumeration;
import java.util.jar.JarFile;
/**
* =================================================================
@ -42,7 +43,7 @@ public class JarClassFind {
} else {
if (filelist[i].endsWith("jar")) {
try {
java.util.jar.JarFile jarfile = new java.util.jar.JarFile(path + filelist[i]);
JarFile jarfile = new java.util.jar.JarFile(path + filelist[i]);
for (Enumeration e = jarfile.entries(); e.hasMoreElements();) {
String name = e.nextElement().toString();
if (name.equals(classname) || name.indexOf(classname) > -1) {

View File

@ -110,20 +110,20 @@ public class GetServerAPI {
* @return
*/
public static List<ProjectCaseParams> cgetParamsByProjectid(String projectid) {
String result = HttpRequest.loadJSON(prefix+"/cgetParamsByProjectid.do?projectId="+projectid);
String result = HttpRequest.loadJSON(prefix+"/clientUpdateTaskExecuteData.do?projectId="+projectid);
List<ProjectCaseParams> paramsList = JSONObject.parseArray(result, ProjectCaseParams.class);
return paramsList;
}
/**
* 供其他系统远程调用调度任务启动执行
* @param jobid
* 通过计划ID获取测试用例对象集
* @param planid
* @return
* @throws UnsupportedEncodingException
*/
public static String cRunJobForId(String jobid) throws UnsupportedEncodingException {
String result = HttpRequest.loadJSON("/testJobs/runJobForInterface.do?jobid=" + jobid);
return new String(result.getBytes("GBK"), "UTF-8");
public static List<Integer> clientGetCaseListForUnSucByTaskId(Integer taskId) {
String result = HttpRequest.loadJSON(prefix+"/clientGetCaseListForUnSucByTaskId.do?taskId=" + taskId);
List<Integer> caseIdList = JSONObject.parseArray(result, Integer.class);
return caseIdList;
}
public static void main(String[] args) throws UnsupportedEncodingException {

View File

@ -111,6 +111,30 @@ public class PostServerAPI {
HttpRequest.httpClientPostJson(prefix+"/clientPostTaskCaseLog", JSONObject.toJSONString(taskCaseLog));
}
/**
* 更新任务执行数据
* @param taskId
* @param casecount
* @author Seagull
* @date 2019年4月22日
*/
public static String clientUpdateTaskExecuteData(Integer taskId, Integer caseCount, Integer taskStatus){
String str = "{\"taskId\":"+taskId+",\"caseCount\":"+caseCount+",\"taskStatus\":"+taskStatus+"}";
return HttpRequest.httpClientPostJson(prefix+"/clientUpdateTaskExecuteData", JSONObject.toJSONString(str));
}
/**
* 更新任务执行数据
* @param taskId
* @param casecount
* @author Seagull
* @date 2019年4月22日
*/
public static String clientDeleteTaskCaseLog(Integer taskId, Integer caseId){
String str = "{\"taskId\":"+taskId+",\"caseId\":"+caseId+"}";
return HttpRequest.httpClientPostJson(prefix+"/clientDeleteTaskCaseLog", JSONObject.toJSONString(str));
}
public static void main(String[] args) throws UnsupportedEncodingException {
cPostDebugLog(3, 1, "info", "js a查%颗蜡&配电脑明显==人fdsa人",0);
}