重构客户端日志模块,重新定义日志打印

This commit is contained in:
seagull 2019-05-24 14:55:51 +08:00
parent 01f83d0a02
commit 751bfe0d25
55 changed files with 969 additions and 909 deletions

View File

@ -235,21 +235,18 @@
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId>
<version>1.2.17</version> </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>

View File

@ -1,12 +1,9 @@
log4j.rootLogger=INFO,stdout,app,error
log4j.rootLogger=INFO,stdout,info,warn,error
log4j.logger.app=info,error
log4j.logger.info=info
log4j.logger.warn=warn
log4j.logger.error=error
log4j.additivity.msg=false
log4j.additivity.monitor=false
log4j.additivity.error=false
log4j.logger.org.springframework=warn
log4j.logger.org.apache=info,error
log4j.logger.org.aspectj.weaver=warn
@ -23,25 +20,36 @@ log4j.logger.java.sql.PreparedStatement=info
#log4j.logger.org.apache.commons.httpclient.Wire=off
################
################打印到控制台
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH\:mm\:ss\:SSS}\:%l - \n%p\: %m%n
################
log4j.appender.app=org.apache.log4j.DailyRollingFileAppender
log4j.appender.app.File=bootlog/APP.log
log4j.appender.app.layout=org.apache.log4j.PatternLayout
log4j.appender.app.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.app.DatePattern = '.'yyyy-MM-dd
log4j.appender.app.encoding=UTF-8
#log4j.appender.app.encoding=UTF-8
################记录系统日志,监控客户端运行情况
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
log4j.appender.info.File=bootlog/INFO.log
log4j.appender.info.layout=org.apache.log4j.PatternLayout
log4j.appender.info.Threshold = INFO
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.info.DatePattern = '.'yyyy-MM-dd
log4j.appender.info.encoding=UTF-8
################
################error
################记录系统告警日志
log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender
log4j.appender.warn.File=bootlog/WARN.log
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
log4j.appender.warn.Threshold = WARN
log4j.appender.warn.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.warn.DatePattern = '.'yyyy-MM-dd
log4j.appender.warn.encoding=UTF-8
################
################记录系统错误,监控程序是否出错
log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File=bootlog/ERROR.log
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.Threshold = ERROR
log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.error.DatePattern = '.'yyyy-MM-dd
log4j.appender.error.encoding=UTF-8

View File

@ -1,12 +1,9 @@
log4j.rootLogger=INFO,stdout,app,error
log4j.rootLogger=INFO,stdout,info,warn,error
log4j.logger.app=info,error
log4j.logger.info=info
log4j.logger.warn=warn
log4j.logger.error=error
log4j.additivity.msg=false
log4j.additivity.monitor=false
log4j.additivity.error=false
log4j.logger.org.springframework=warn
log4j.logger.org.apache=info,error
log4j.logger.org.aspectj.weaver=warn
@ -23,25 +20,36 @@ log4j.logger.java.sql.PreparedStatement=info
#log4j.logger.org.apache.commons.httpclient.Wire=off
################
################打印到控制台
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH\:mm\:ss\:SSS}\:%l - \n%p\: %m%n
################
log4j.appender.app=org.apache.log4j.DailyRollingFileAppender
log4j.appender.app.File=log/APP.log
log4j.appender.app.layout=org.apache.log4j.PatternLayout
log4j.appender.app.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.app.DatePattern = '.'yyyy-MM-dd
log4j.appender.app.encoding=UTF-8
#log4j.appender.app.encoding=UTF-8
################记录系统日志,监控客户端运行情况
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
log4j.appender.info.File=log/INFO.log
log4j.appender.info.layout=org.apache.log4j.PatternLayout
log4j.appender.info.Threshold = INFO
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.info.DatePattern = '.'yyyy-MM-dd
log4j.appender.info.encoding=UTF-8
################
################error
################记录系统告警日志
log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender
log4j.appender.warn.File=log/WARN.log
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
log4j.appender.warn.Threshold = WARN
log4j.appender.warn.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.warn.DatePattern = '.'yyyy-MM-dd
log4j.appender.warn.encoding=UTF-8
################
################记录系统错误,监控程序是否出错
log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File=log/ERROR.log
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.Threshold = ERROR
log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
log4j.appender.error.DatePattern = '.'yyyy-MM-dd
log4j.appender.error.encoding=UTF-8

View File

@ -10,6 +10,7 @@ import luckyclient.caserun.exappium.iosex.IosBatchExecute;
import luckyclient.caserun.exinterface.BatchTestCaseExecution;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.ex.WebBatchExecute;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
@ -44,7 +45,7 @@ public class BatchCaseExecute extends TestControl {
String.valueOf(task.getTaskId()), batchcase);
} else if (taskScheduling.getTaskType() == 2) {
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
if ("Android".equals(properties.getProperty("platformName"))) {
AndroidBatchExecute.batchCaseExecuteForTast(taskScheduling.getProject().getProjectName(),

View File

@ -10,6 +10,7 @@ import luckyclient.caserun.exappium.iosex.IosOneCaseExecute;
import luckyclient.caserun.exinterface.TestCaseExecution;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.ex.WebOneCaseExecute;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
@ -44,7 +45,7 @@ public class OneCaseExecute extends TestControl {
String.valueOf(task.getTaskId()));
} else if (taskScheduling.getTaskType() == 2) {
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
if ("Android".equals(properties.getProperty("platformName"))) {
AndroidOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId),

View File

@ -6,6 +6,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseSteps;
/**
@ -45,7 +46,7 @@ public class AppDriverAnalyticCase {
params.put("property", property.trim().toLowerCase());
//set属性值
params.put("property_value", propertyValue.trim());
luckyclient.publicclass.LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+propertyValue.trim());
LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+propertyValue.trim());
}
//set操作方法
params.put("operation", step.getStepOperation().toLowerCase());
@ -53,7 +54,7 @@ public class AppDriverAnalyticCase {
//set属性值
params.put("operation_value", step.getStepParameters());
}
luckyclient.publicclass.LogUtil.APP.info("对象操作解析结果operation:"+step.getStepOperation().toLowerCase()+"; operation_value:"+step.getStepParameters());
LogUtil.APP.info("对象操作解析结果operation:"+step.getStepOperation().toLowerCase()+"; operation_value:"+step.getStepParameters());
//获取预期结果字符串
resultstr = step.getExpectedResult();
@ -69,19 +70,18 @@ public class AppDriverAnalyticCase {
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
}
params.put("ExpectedResults", expectedResults);
luckyclient.publicclass.LogUtil.APP.info("预期结果解析ExpectedResults:"+expectedResults);
LogUtil.APP.info("预期结果解析ExpectedResults:"+expectedResults);
}
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
LogUtil.APP.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!",e);
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
return params;
}

View File

@ -1,5 +1,10 @@
package luckyclient.caserun.exappium;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.ios.IOSDriver;
@ -13,13 +18,14 @@ import luckyclient.jenkinsapi.BuildingInitialization;
import luckyclient.jenkinsapi.RestartServerInitialization;
import luckyclient.mail.HtmlMail;
import luckyclient.mail.MailSendInitialization;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
import luckyclient.serverapi.entity.ProjectCaseSteps;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
/**
* =================================================================
@ -46,7 +52,7 @@ public class AppTestControl {
String taskid = "888888";
AndroidDriver<AndroidElement> androiddriver = null;
IOSDriver<IOSElement> iosdriver = null;
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
try {
if ("Android".equals(properties.getProperty("platformName"))) {
androiddriver = AppiumInitialization.setAndroidAppium(properties);
@ -64,7 +70,7 @@ public class AppTestControl {
if (testCases.size() != 0) {
pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
}
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + testCases.size() + "");
LogUtil.APP.info("当前计划中读取到用例共 " + testCases.size() + "");
int i = 0;
for (ProjectCase testcase : testCases) {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
@ -72,7 +78,7 @@ public class AppTestControl {
continue;
}
i++;
luckyclient.publicclass.LogUtil.APP.info("开始执行第" + i + "条用例:【" + testcase.getCaseSign() + "】......");
LogUtil.APP.info("开始执行第" + i + "条用例:【" + testcase.getCaseSign() + "】......");
try {
if ("Android".equals(properties.getProperty("platformName"))) {
AndroidCaseExecution.caseExcution(testcase, steps, taskid, androiddriver, caselog, pcplist);
@ -81,15 +87,15 @@ public class AppTestControl {
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
LogUtil.APP.error("用户执行过程中抛出InterruptedException异常!", e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LogUtil.APP.error("用户执行过程中抛出IOException异常", e);
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
}
luckyclient.publicclass.LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
// 关闭APP以及appium会话
if ("Android".equals(properties.getProperty("platformName"))) {
androiddriver.closeApp();
@ -105,7 +111,7 @@ public class AppTestControl {
TestControl.TASKID = taskId;
AndroidDriver<AndroidElement> androiddriver = null;
IOSDriver<IOSElement> iosdriver = null;
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
AppiumService as=null;
//根据配置自动启动Appiume服务
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
@ -128,21 +134,20 @@ public class AppTestControl {
try {
if ("Android".equals(properties.getProperty("platformName"))) {
androiddriver = AppiumInitialization.setAndroidAppium(properties);
luckyclient.publicclass.LogUtil.APP.info("完成AndroidDriver初始化动作...APPIUM Server【http://"
LogUtil.APP.info("完成AndroidDriver初始化动作...APPIUM Server【http://"
+ properties.getProperty("appiumsever") + "/wd/hub】");
} else if ("IOS".equals(properties.getProperty("platformName"))) {
iosdriver = AppiumInitialization.setIosAppium(properties);
luckyclient.publicclass.LogUtil.APP.info("完成IOSDriver初始化动作...APPIUM Server【http://"
LogUtil.APP.info("完成IOSDriver初始化动作...APPIUM Server【http://"
+ properties.getProperty("appiumsever") + "/wd/hub】");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("初始化AppiumDriver出错 APPIUM Server【http://"
LogUtil.APP.error("初始化AppiumDriver出错 APPIUM Server【http://"
+ properties.getProperty("appiumsever") + "/wd/hub】", e);
e.printStackTrace();
}
LogOperation caselog = new LogOperation();
List<ProjectCase> cases = GetServerAPI.getCasesbyplanId(taskScheduling.getPlanId());
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogOperation.updateTaskExecuteStatus(taskId, cases.size());
for (ProjectCase testcase : cases) {
@ -150,7 +155,7 @@ public class AppTestControl {
if (steps.size() == 0) {
continue;
}
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
try {
//插入开始执行的用例
caselog.insertTaskCaseExecute(taskId, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4);
@ -161,14 +166,13 @@ public class AppTestControl {
}
} catch (InterruptedException | IOException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
LogUtil.APP.error("用户执行过程中抛出异常!", e);
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
}
tastcount = LogOperation.updateTaskExecuteData(taskId, cases.size());
String testtime = LogOperation.getTestTime(taskId);
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskId, buildstatus, restartstatus, testtime, jobname),
taskId, taskScheduling, tastcount);
@ -179,11 +183,11 @@ public class AppTestControl {
iosdriver.closeApp();
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
LogUtil.APP.warn("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskId, taskScheduling, tastcount);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
LogUtil.APP.warn("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskId, taskScheduling, tastcount);
}
//关闭Appium服务的线程

View File

@ -6,12 +6,14 @@ import java.util.Properties;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.publicclass.LogUtil;
public class AppiumService extends Thread{
public void run(){
try{
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
File mainjsFile = new File(properties.getProperty("mainjsPath"));
String ip=properties.getProperty("appiumsever");
AppiumServiceBuilder builder =
@ -24,12 +26,12 @@ public class AppiumService extends Thread{
service.start();
if (service == null || !service.isRunning()){
luckyclient.publicclass.LogUtil.APP.error("自动启动Appium服务失败请检查");
LogUtil.APP.warn("自动启动Appium服务失败请检查");
}else{
luckyclient.publicclass.LogUtil.APP.info("自动启动Appium服务成功监听IP:"+ip.split(":")[0].trim()+" 监听端口:"+ip.split(":")[1].trim());
LogUtil.APP.info("自动启动Appium服务成功监听IP:"+ip.split(":")[0].trim()+" 监听端口:"+ip.split(":")[1].trim());
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.APP.error("自动启动Appium服务抛出异常请检查",e);
LogUtil.APP.error("自动启动Appium服务抛出异常请检查",e);
}
}

View File

@ -16,6 +16,7 @@ import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.android.AndroidTouchAction;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
@ -32,6 +33,7 @@ public class AndroidBaseAppium {
/**
* 安卓手机报错截图
*
* @param appium
* @param imagname
* @throws IOException
@ -39,7 +41,8 @@ public class AndroidBaseAppium {
public static void screenShot(AndroidDriver<AndroidElement> appium, String imagname) {
imagname = imagname + ".png";
String relativelyPath = System.getProperty("user.dir");
String pngpath=relativelyPath +File.separator+ "log"+File.separator+"ScreenShot" +File.separator+ imagname;
String pngpath = relativelyPath + File.separator + "log" + File.separator + "ScreenShot" + File.separator
+ imagname;
try {
try {
@ -52,8 +55,7 @@ public class AndroidBaseAppium {
File screenFile = new File(pngpath);
FileUtils.copyFile(imageFile, screenFile);
imageFile.deleteOnExit();
luckyclient.publicclass.LogUtil.APP
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【" + pngpath + "");
LogUtil.APP.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【" + pngpath + "");
} catch (IOException e) {
e.printStackTrace();
}
@ -74,8 +76,8 @@ public class AndroidBaseAppium {
* @param args
* js webview 支持4.14.4
*/
public static void webViewSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY, Double duration)
throws Exception {
public static void webViewSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY,
Double duration) throws Exception {
JavascriptExecutor js;
HashMap<String, Double> swipeObject;
try {
@ -102,7 +104,8 @@ public class AndroidBaseAppium {
* @param args
* 调用 ADB直接滑动 支持4.14.4
*/
public static void adbSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY) throws Exception {
public static void adbSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY)
throws Exception {
int xLine;
int yLine;
int sX2;
@ -146,9 +149,12 @@ public class AndroidBaseAppium {
/**
* 拖住页面按屏幕比例向上滑动(手指向下页面向上)
*
* @param driver
* @param second 持续时间
* @param num 滚动次数
* @param second
* 持续时间
* @param num
* 滚动次数
*/
public static void swipePageUp(AndroidDriver<AndroidElement> driver, Double second, int num) {
int nanos = (int) (second * 1000);
@ -165,6 +171,7 @@ public class AndroidBaseAppium {
/**
* 拖住页面按屏幕比例向下滑动(手指向上页面向下)
*
* @param driver
* @param second
* @param num
@ -183,6 +190,7 @@ public class AndroidBaseAppium {
/**
* 拖住页面按屏幕比例向左滑动(手指向左页面向左滚动)
*
* @param driver
* @param second
* @param num
@ -201,6 +209,7 @@ public class AndroidBaseAppium {
/**
* 拖住页面按屏幕比例向右滑动(手指向右页面向右)
*
* @param driver
* @param second
* @param num

View File

@ -12,6 +12,8 @@ import luckyclient.caserun.exappium.AppiumService;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -38,7 +40,7 @@ public class AndroidBatchExecute {
AndroidDriver<AndroidElement> ad = null;
AppiumService as=null;
try {
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
//¸ù¾ÝÅäÖÃ×Ô¯Æô¯Appiume·þÎñ
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
as =new AppiumService();
@ -67,7 +69,7 @@ public class AndroidBatchExecute {
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}
@ -82,7 +84,7 @@ public class AndroidBatchExecute {
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}

View File

@ -80,10 +80,10 @@ public class AndroidCaseExecution extends TestCaseExecution{
if (0 != stepresult) {
setcaseresult = stepresult;
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -91,10 +91,10 @@ public class AndroidCaseExecution extends TestCaseExecution{
variable.clear();
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
if(setcaseresult==0){
luckyclient.publicclass.LogUtil.APP.info("用例【"+testcase.getCaseSign()+"】全部步骤执行结果成功...");
LogUtil.APP.info("用例【"+testcase.getCaseSign()+"】全部步骤执行结果成功...");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending","");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】步骤执行过程中失败或是锁定...请查看具体原因!"+casenote);
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】步骤执行过程中失败或是锁定...请查看具体原因!"+casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
}
//LogOperation.UpdateTastdetail(taskid, 0);
@ -119,11 +119,11 @@ public class AndroidCaseExecution extends TestCaseExecution{
operation=ChangString.changparams(operation, variable,"操作");
operationValue=ChangString.changparams(operationValue, variable,"操作参数");
luckyclient.publicclass.LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("二次解析用例过程抛出异常!---"+e.getMessage());
LogUtil.APP.error("二次解析用例过程抛出异常!---"+e.getMessage());
return "步骤执行失败:解析用例失败!";
}
@ -145,7 +145,7 @@ public class AndroidCaseExecution extends TestCaseExecution{
ae = isElementExist(appium, property, propertyValue);
// 判断此元素是否存在
if (null==ae) {
luckyclient.publicclass.LogUtil.APP.error("定位对象失败isElementExist为null!");
LogUtil.APP.warn("定位对象失败isElementExist为null!");
return "步骤执行失败isElementExist定位元素过程失败";
}
@ -165,11 +165,11 @@ public class AndroidCaseExecution extends TestCaseExecution{
result = AndroidEncapsulateOperation.driverOperation(appium, operation, operationValue);
}
}else{
luckyclient.publicclass.LogUtil.APP.error("元素操作过程失败!");
LogUtil.APP.warn("元素操作过程失败!");
result = "步骤执行失败:元素操作过程失败!";
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("元素定位过程或是操作过程失败或异常!"+e.getMessage());
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!"+e.getMessage());
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
caselog.insertTaskCaseLog(taskid, caseId, result,"info", String.valueOf(stepno),"");
@ -221,7 +221,7 @@ public class AndroidCaseExecution extends TestCaseExecution{
return ae;
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("当前对象定位失败:"+e.getMessage());
LogUtil.APP.error("当前对象定位失败:"+e.getMessage());
return null;
}
@ -236,19 +236,19 @@ public class AndroidCaseExecution extends TestCaseExecution{
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("期望结果为【" + expect + "");
LogUtil.APP.info("期望结果为【" + expect + "");
// 赋值传参模式
if (expect.length() > ASSIGNMENT_SIGN.length() && expect.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expect.substring(ASSIGNMENT_SIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 赋值全局变量
else if (expect.length() > ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(ASSIGNMENT_GLOBALSIGN)) {
variable.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 移动端 UI检查模式
@ -258,13 +258,13 @@ public class AndroidCaseExecution extends TestCaseExecution{
AndroidElement ae = isElementExist(appium, checkproperty, checkPropertyValue);
if (null != ae) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
AndroidBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -273,13 +273,13 @@ public class AndroidCaseExecution extends TestCaseExecution{
// 模糊匹配预期结果模式
if (expect.length() > FUZZY_MATCHING_SIGN.length() && expect.startsWith(FUZZY_MATCHING_SIGN)) {
if (result.contains(expect.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
AndroidBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -288,26 +288,26 @@ public class AndroidCaseExecution extends TestCaseExecution{
Pattern pattern = Pattern.compile(expect.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(result);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
AndroidBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
// 精确匹配预期结果模式
else {
if (expect.equals(result)) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
AndroidBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -317,15 +317,11 @@ public class AndroidCaseExecution extends TestCaseExecution{
casenote = (null != result) ? result : "";
setresult = 2;
AndroidBaseAppium.screenShot(appium, imagname);
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
return setresult;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -7,6 +7,7 @@ import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -33,13 +34,13 @@ public class AndroidCaseLocalDebug {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseParams> pcplist = GetServerAPI
.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testCaseExternalId + "】......");
LogUtil.APP.info("开始执行用例:【" + testCaseExternalId + "】......");
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
AndroidCaseExecution.caseExcution(testcase, steps, "888888", androiddriver, caselog, pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}
@ -57,7 +58,7 @@ public class AndroidCaseLocalDebug {
System.out.println("当前调试用例总共:"+addtestcase.size());
for(String testCaseExternalId:addtestcase) {
try {
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("开始调用方法,项目名:" + projectname + ",用例编号:" + testCaseExternalId);
oneCasedebug(androiddriver, testCaseExternalId);
} catch (Exception e) {

View File

@ -17,6 +17,7 @@ import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
@ -38,20 +39,20 @@ public class AndroidEncapsulateOperation {
switch (operation) {
case "selectbyvisibletext":
select.selectByVisibleText(operationValue);
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operationValue + "");
break;
case "selectbyvalue":
select.selectByValue(operationValue);
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "");
LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "");
break;
case "selectbyindex":
select.selectByIndex(Integer.valueOf(operationValue));
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "");
LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "");
break;
case "isselect":
result = "获取到的值是【" + ae.isSelected() + "";
luckyclient.publicclass.LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + ae.isSelected() + "");
LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + ae.isSelected() + "");
break;
default:
break;
@ -65,20 +66,20 @@ public class AndroidEncapsulateOperation {
switch (operation) {
case "gettext":
result = "获取到的值是【" + ae.getText() + "";
luckyclient.publicclass.LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
break; // 获取输入框内容
case "gettagname":
result = "获取到的值是【" + ae.getTagName() + "";
luckyclient.publicclass.LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
break;
case "getattribute":
result = "获取到的值是【" + ae.getAttribute(value) + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("getAttribute获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
break;
case "getcssvalue":
result = "获取到的值是【" + ae.getCssValue(value) + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("getCssValue获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
break;
default:
@ -97,35 +98,35 @@ public class AndroidEncapsulateOperation {
case "click":
ae.click();
result = "click点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("click点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "");
break;
case "sendkeys":
ae.sendKeys(operationValue);
result = "sendKeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 操作值:" + operationValue
+ "";
luckyclient.publicclass.LogUtil.APP.info("sendkeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue
LogUtil.APP.info("sendkeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue
+ "; 操作值:" + operationValue + "");
break;
case "clear":
ae.clear();
result = "clear清空输入框...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("clear清空输入框...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "");
break; // 清空输入框
case "isenabled":
result = "获取到的值是【" + ae.isEnabled() + "";
luckyclient.publicclass.LogUtil.APP.info("当前对象判断是否可用布尔值为【" + ae.isEnabled() + "");
LogUtil.APP.info("当前对象判断是否可用布尔值为【" + ae.isEnabled() + "");
break;
case "isdisplayed":
result = "获取到的值是【" + ae.isDisplayed() + "";
luckyclient.publicclass.LogUtil.APP.info("当前对象判断是否可见布尔值为【" + ae.isDisplayed() + "");
LogUtil.APP.info("当前对象判断是否可见布尔值为【" + ae.isDisplayed() + "");
break;
case "exjsob":
JavascriptExecutor jse = (JavascriptExecutor) appium;
jse.executeScript(operationValue, ae);
result = "执行JS...【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【" + operationValue + "");
LogUtil.APP.info("执行JS...【" + operationValue + "");
break;
case "longpresselement":
LongPressOptions lpoptions = new LongPressOptions();
@ -138,7 +139,7 @@ public class AndroidEncapsulateOperation {
action.longPress(lpoptions).release().perform();
result = "longpresselement在屏幕指定元素上按住" + operationValue + "秒...【对象定位属性:" + property + "; 定位属性值:"
+ propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
default:
break;
@ -152,15 +153,15 @@ public class AndroidEncapsulateOperation {
switch (operation) {
case "alertaccept":
alert.accept();
luckyclient.publicclass.LogUtil.APP.info("弹出框对象点击同意...");
LogUtil.APP.info("弹出框对象点击同意...");
break;
case "alertdismiss":
alert.dismiss();
luckyclient.publicclass.LogUtil.APP.info("弹出框对象点击取消...");
LogUtil.APP.info("弹出框对象点击取消...");
break;
case "alertgettext":
result = "获取到的值是【" + alert.getText() + "";
luckyclient.publicclass.LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
break;
default:
break;
@ -188,25 +189,25 @@ public class AndroidEncapsulateOperation {
}
handlenum++;
}
luckyclient.publicclass.LogUtil.APP.info("getContext获取窗口句柄..." + result);
LogUtil.APP.info("getContext获取窗口句柄..." + result);
break;
case "exjs":
JavascriptExecutor jse = (JavascriptExecutor) appium;
jse.executeScript(operationValue);
result = "执行JS...【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【" + operationValue + "");
LogUtil.APP.info("执行JS...【" + operationValue + "");
break;
case "exAdbShell":
Runtime.getRuntime().exec(operationValue);
result = "执行安卓adb命令...【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info("执行安卓adb命令...【" + operationValue + "");
LogUtil.APP.info("执行安卓adb命令...【" + operationValue + "");
break;
case "keycode":
// 模拟手机键盘
if (ChangString.isNumeric(operationValue)) {
appium.pressKeyCode(Integer.valueOf(operationValue));
result = "模拟手机键盘发送指令...keycode【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
}
@ -215,7 +216,7 @@ public class AndroidEncapsulateOperation {
case "hidekeyboard":
appium.hideKeyboard();
result = "隐藏手机键盘...【hideKeyboard】";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "gotocontext":
Set<String> ctNames = appium.getContextHandles();
@ -229,19 +230,19 @@ public class AndroidEncapsulateOperation {
}
if (flag == 1) {
result = "切换context至【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "切换context失败未找到contextName值为【" + operationValue + "】的对象";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "getcontext":
result = "获取到的值是【" + appium.getContext() + "";
luckyclient.publicclass.LogUtil.APP.info("获取页面Context...【" + appium.getContext() + "");
LogUtil.APP.info("获取页面Context...【" + appium.getContext() + "");
break;
case "gettitle":
result = "获取到的值是【" + appium.getTitle() + "";
luckyclient.publicclass.LogUtil.APP.info("获取页面gettitle...【" + appium.getTitle() + "");
LogUtil.APP.info("获取页面gettitle...【" + appium.getTitle() + "");
break;
case "swipeup":
String[] tempup = operationValue.split("\\|", -1);
@ -251,14 +252,14 @@ public class AndroidEncapsulateOperation {
int num = Integer.valueOf(tempup[1]);
AndroidBaseAppium.swipePageUp(appium, second, num);
result = "swipeup页面向上滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipeup页面向上滑动参数判断次数出现异常【" + tempup[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipeup页面向上滑动参数判断时间出现异常【" + tempup[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "swipedown":
@ -269,14 +270,14 @@ public class AndroidEncapsulateOperation {
int num = Integer.valueOf(tempdown[1]);
AndroidBaseAppium.swipePageDown(appium, second, num);
result = "swipedown页面向下滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipedown页面向下滑动参数判断次数出现异常【" + tempdown[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipedown页面向下滑动参数判断时间出现异常【" + tempdown[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "swipleft":
@ -287,14 +288,14 @@ public class AndroidEncapsulateOperation {
int num = Integer.valueOf(templeft[1]);
AndroidBaseAppium.swipePageLeft(appium, second, num);
result = "swipleft页面向左滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipleft页面向左滑动参数判断次数出现异常【" + templeft[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipleft页面向左滑动参数判断时间出现异常【" + templeft[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "swipright":
@ -305,14 +306,14 @@ public class AndroidEncapsulateOperation {
int num = Integer.valueOf(tempright[1]);
AndroidBaseAppium.swipePageRight(appium, second, num);
result = "swipright页面向右滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipright页面向右滑动参数判断次数出现异常【" + tempright[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipright页面向右滑动参数判断时间出现异常【" + tempright[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "longpressxy":
@ -330,19 +331,19 @@ public class AndroidEncapsulateOperation {
action.longPress(lpoptions).release().perform();
result = "longpressxy在屏幕指定XY坐标上按住" + longpressxy[2] + "秒...X|Y【" + longpressx + "|" + longpressy
+ "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
action.longPress(PointOption.point(longpressx, longpressy)).release().perform();
result = "longpressxy在屏幕指定XY坐标上长按...X|Y【" + longpressx + "|" + longpressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "longpressxy参数指定的Y坐标处理出现异常【" + longpressxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "longpressxy参数指定的X坐标处理出现异常【" + longpressxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "pressxy":
@ -353,14 +354,14 @@ public class AndroidEncapsulateOperation {
int pressy = Integer.valueOf(pressxy[1]);
action.press(PointOption.point(pressx, pressy)).release().perform();
result = "pressxy在屏幕指定XY坐标上点击...X|Y【" + pressx + "|" + pressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "pressxy参数指定的Y坐标处理出现异常【" + pressxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "pressxy参数指定的X坐标处理出现异常【" + pressxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "tapxy":
@ -371,14 +372,14 @@ public class AndroidEncapsulateOperation {
int tapy = Integer.valueOf(tapxy[1]);
action.tap(PointOption.point(tapx, tapy)).release().perform();
result = "tapxy在屏幕指定XY坐标上轻击...X|Y【" + tapx + "|" + tapy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "tapxy参数指定的Y坐标处理出现异常【" + tapxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "tapxy参数指定的X坐标处理出现异常【" + tapxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "jspressxy":
@ -390,19 +391,19 @@ public class AndroidEncapsulateOperation {
if (null != jspressxy[2] && ChangString.isNumeric(jspressxy[2])) {
AndroidBaseAppium.clickScreenForJs(appium, jspressx, jspressy, Integer.valueOf(jspressxy[2]));
result = "jspressxy在屏幕指定XY坐标上按" + jspressxy[2] + "秒...X|Y【" + jspressx + "|" + jspressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
AndroidBaseAppium.clickScreenForJs(appium, jspressx, jspressy, 2);
result = "jspressxy在屏幕指定XY坐标上按2秒(持续时间判断异常使用默认2秒时间)...X|Y【" + jspressx + "|" + jspressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "jspressxy参数指定的Y坐标处理出现异常【" + jspressxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "jspressxy参数指定的X坐标处理出现异常【" + jspressxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "moveto":
@ -421,34 +422,34 @@ public class AndroidEncapsulateOperation {
action.press(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(Duration.ofNanos(1500)))
.moveTo(PointOption.point(endx, endy));
luckyclient.publicclass.LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
+ "】拖动至坐标【" + endxy[0] + "," + endxy[1] + "");
} else {
if (movexyi == 1) {
action.press(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(Duration.ofNanos(1500)))
.moveTo(PointOption.point(endx - startx, endy - starty));
luckyclient.publicclass.LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
+ "】拖动至坐标【" + endxy[0] + "," + endxy[1] + "");
} else {
action.waitAction(WaitOptions.waitOptions(Duration.ofNanos(1500)))
.moveTo(PointOption.point(endx - startx, endy - starty));
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("" + movexyi + "次拖动至坐标【" + endxy[0] + "," + endxy[1] + "");
}
startx = endx;
starty = endy;
}
} else {
luckyclient.publicclass.LogUtil.APP.error("判断结束坐标位置出现异常,结束坐标参数【" + movexy[movexyi] + "");
LogUtil.APP.warn("判断结束坐标位置出现异常,结束坐标参数【" + movexy[movexyi] + "");
}
}
action.release().perform();
result = "moveto全部拖动释放并完成发送...开始位置【" + startxy[0] + "," + startxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "moveto参数指定的起始坐标处理出现异常【" + movexy[0] + "】,请检查!";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "timeout":
@ -458,10 +459,10 @@ public class AndroidEncapsulateOperation {
// 设置元素出现最大时长30秒
appium.manage().timeouts().implicitlyWait(Integer.valueOf(operationValue), TimeUnit.SECONDS);
result = "设置全局页面加载&元素出现最大等待时间【" + operationValue + "】秒...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "【等待时间转换出错,请检查参数】";
luckyclient.publicclass.LogUtil.APP.info(result + "原因是因为判断你的等待时间不是数字...");
LogUtil.APP.info(result + "原因是因为判断你的等待时间不是数字...");
}
break;
case "screenshot":
@ -469,7 +470,7 @@ public class AndroidEncapsulateOperation {
String imagname = "FunctionScreenShot_" + timeformat.format(new Date());
AndroidBaseAppium.screenShot(appium, imagname);
result = "截图名称【" + imagname + "】...";
luckyclient.publicclass.LogUtil.APP.info("使用方法主动截取当前屏幕..." + result);
LogUtil.APP.info("使用方法主动截取当前屏幕..." + result);
break;
default:
break;

View File

@ -11,6 +11,8 @@ import luckyclient.caserun.exappium.AppiumService;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -37,7 +39,7 @@ public class AndroidOneCaseExecute {
AndroidDriver<AndroidElement> ad = null;
AppiumService as=null;
try {
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
//¸ù¾ÝÅäÖÃ×Ô¯Æô¯Appiume·þÎñ
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
as =new AppiumService();
@ -47,7 +49,7 @@ public class AndroidOneCaseExecute {
ad = AppiumInitialization.setAndroidAppium(properties);
} catch (IOException e1) {
luckyclient.publicclass.LogUtil.APP.error("初始化AndroidDriver出错", e1);
LogUtil.APP.error("初始化AndroidDriver出错", e1);
e1.printStackTrace();
}
LogOperation caselog = new LogOperation();
@ -55,13 +57,13 @@ public class AndroidOneCaseExecute {
ProjectCase testcase = GetServerAPI.cGetCaseByCaseId(caseId);
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
try {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
} catch (InterruptedException e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
LogOperation.updateTaskExecuteData(taskid, 0);

View File

@ -16,15 +16,14 @@ import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.ios.IOSTouchAction;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
*
* @date 2018年2月2日
*
*/
@ -51,7 +50,7 @@ public class IosBaseAppium {
File screenFile = new File(pngpath);
FileUtils.copyFile(imageFile, screenFile);
imageFile.deleteOnExit();
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【" + pngpath + "");
} catch (IOException e) {
e.printStackTrace();

View File

@ -12,6 +12,8 @@ import luckyclient.caserun.exappium.AppiumService;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -23,9 +25,7 @@ import luckyclient.serverapi.entity.TaskExecute;
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
*
* @date 2018年2月2日
*
*/
@ -38,7 +38,7 @@ public class IosBatchExecute {
IOSDriver<IOSElement> iosd = null;
AppiumService as=null;
try {
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
//根据配置自动启动Appiume服务
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
as =new AppiumService();
@ -67,7 +67,7 @@ public class IosBatchExecute {
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}
@ -82,7 +82,7 @@ public class IosBatchExecute {
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}

View File

@ -81,10 +81,10 @@ public class IosCaseExecution extends TestCaseExecution{
if (0 != stepresult) {
setcaseresult = stepresult;
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
@ -93,10 +93,10 @@ public class IosCaseExecution extends TestCaseExecution{
variable.clear();
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
if(setcaseresult==0){
luckyclient.publicclass.LogUtil.APP.info("用例【"+testcase.getCaseSign()+"】全部步骤执行结果成功...");
LogUtil.APP.info("用例【"+testcase.getCaseSign()+"】全部步骤执行结果成功...");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending","");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】步骤执行过程中失败或是锁定...请查看具体原因!"+casenote);
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】步骤执行过程中失败或是锁定...请查看具体原因!"+casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
}
//LogOperation.UpdateTastdetail(taskid, 0);
@ -121,11 +121,11 @@ public class IosCaseExecution extends TestCaseExecution{
operation=ChangString.changparams(operation, variable,"操作");
operationValue=ChangString.changparams(operationValue, variable,"操作参数");
luckyclient.publicclass.LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("二次解析用例过程抛出异常!---"+e.getMessage());
LogUtil.APP.error("二次解析用例过程抛出异常!---"+e.getMessage());
return "步骤执行失败:解析用例失败!";
}
@ -147,7 +147,7 @@ public class IosCaseExecution extends TestCaseExecution{
ae = isElementExist(appium, property, propertyValue);
// 判断此元素是否存在
if (null==ae) {
luckyclient.publicclass.LogUtil.APP.error("定位对象失败isElementExist为null!");
LogUtil.APP.warn("定位对象失败isElementExist为null!");
return "步骤执行失败isElementExist定位元素过程失败";
}
@ -167,11 +167,11 @@ public class IosCaseExecution extends TestCaseExecution{
result = IosEncapsulateOperation.driverOperation(appium, operation, operationValue);
}
}else{
luckyclient.publicclass.LogUtil.APP.error("元素操作过程失败!");
LogUtil.APP.warn("元素操作过程失败!");
result = "步骤执行失败:元素操作过程失败!";
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("元素定位过程或是操作过程失败或异常!"+e.getMessage());
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!"+e.getMessage());
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
caselog.insertTaskCaseLog(taskid, caseId, result,"info", String.valueOf(stepno),"");
@ -229,7 +229,7 @@ public class IosCaseExecution extends TestCaseExecution{
return ae;
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("当前对象定位失败:"+e.getMessage());
LogUtil.APP.error("当前对象定位失败:"+e.getMessage());
return null;
}
@ -244,19 +244,19 @@ public class IosCaseExecution extends TestCaseExecution{
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("期望结果为【" + expect + "");
LogUtil.APP.info("期望结果为【" + expect + "");
// 赋值传参模式
if (expect.length() > ASSIGNMENT_SIGN.length() && expect.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expect.substring(ASSIGNMENT_SIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 赋值全局变量
else if (expect.length() > ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(ASSIGNMENT_GLOBALSIGN)) {
variable.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 移动端 UI检查模式
@ -266,13 +266,13 @@ public class IosCaseExecution extends TestCaseExecution{
IOSElement ae = isElementExist(appium, checkproperty, checkPropertyValue);
if (null != ae) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
IosBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -281,13 +281,13 @@ public class IosCaseExecution extends TestCaseExecution{
// 模糊匹配预期结果模式
if (expect.length() > FUZZY_MATCHING_SIGN.length() && expect.startsWith(FUZZY_MATCHING_SIGN)) {
if (result.contains(expect.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
IosBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -296,26 +296,26 @@ public class IosCaseExecution extends TestCaseExecution{
Pattern pattern = Pattern.compile(expect.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(result);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
IosBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
// 精确匹配预期结果模式
else {
if (expect.equals(result)) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
IosBaseAppium.screenShot(appium, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -325,7 +325,7 @@ public class IosCaseExecution extends TestCaseExecution{
casenote = (null != result) ? result : "";
setresult = 2;
IosBaseAppium.screenShot(appium, imagname);
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}

View File

@ -7,6 +7,7 @@ import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -33,13 +34,13 @@ public class IosCaseLocalDebug {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseParams> pcplist = GetServerAPI
.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testCaseExternalId + "】......");
LogUtil.APP.info("开始执行用例:【" + testCaseExternalId + "】......");
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
IosCaseExecution.caseExcution(testcase, steps, "888888", iosdriver, caselog, pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}
@ -55,7 +56,7 @@ public class IosCaseLocalDebug {
System.out.println("当前调试用例总共:"+addtestcase.size());
for(String testCaseExternalId:addtestcase) {
try {
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("开始调用方法,项目名:" + projectname + ",用例编号:" + testCaseExternalId);
oneCasedebug(iosdriver, testCaseExternalId);
} catch (Exception e) {

View File

@ -17,6 +17,7 @@ import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
@ -38,20 +39,20 @@ public class IosEncapsulateOperation {
switch (operation) {
case "selectbyvisibletext":
select.selectByVisibleText(operationValue);
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operationValue + "");
break;
case "selectbyvalue":
select.selectByValue(operationValue);
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "");
LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "");
break;
case "selectbyindex":
select.selectByIndex(Integer.valueOf(operationValue));
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "");
LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "");
break;
case "isselect":
result = "获取到的值是【" + ie.isSelected() + "";
luckyclient.publicclass.LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + ie.isSelected() + "");
LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + ie.isSelected() + "");
break;
default:
break;
@ -65,20 +66,20 @@ public class IosEncapsulateOperation {
switch (operation) {
case "gettext":
result = "获取到的值是【" + ie.getText() + "";
luckyclient.publicclass.LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
break; // 获取输入框内容
case "gettagname":
result = "获取到的值是【" + ie.getTagName() + "";
luckyclient.publicclass.LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
break;
case "getattribute":
result = "获取到的值是【" + ie.getAttribute(value) + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("getAttribute获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
break;
case "getcssvalue":
result = "获取到的值是【" + ie.getCssValue(value) + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("getCssValue获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
break;
default:
@ -96,35 +97,35 @@ public class IosEncapsulateOperation {
case "click":
ie.click();
result = "click点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("click点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "");
break;
case "sendkeys":
ie.sendKeys(operationValue);
result = "sendKeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 操作值:" + operationValue
+ "";
luckyclient.publicclass.LogUtil.APP.info("sendkeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue
LogUtil.APP.info("sendkeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue
+ "; 操作值:" + operationValue + "");
break;
case "clear":
ie.clear();
result = "clear清空输入框...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("clear清空输入框...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "");
break; // 清空输入框
case "isenabled":
result = "获取到的值是【" + ie.isEnabled() + "";
luckyclient.publicclass.LogUtil.APP.info("当前对象判断是否可用布尔值为【" + ie.isEnabled() + "");
LogUtil.APP.info("当前对象判断是否可用布尔值为【" + ie.isEnabled() + "");
break;
case "isdisplayed":
result = "获取到的值是【" + ie.isDisplayed() + "";
luckyclient.publicclass.LogUtil.APP.info("当前对象判断是否可见布尔值为【" + ie.isDisplayed() + "");
LogUtil.APP.info("当前对象判断是否可见布尔值为【" + ie.isDisplayed() + "");
break;
case "exjsob":
JavascriptExecutor jse = (JavascriptExecutor) appium;
jse.executeScript(operationValue, ie);
result = "执行JS...【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【" + operationValue + "");
LogUtil.APP.info("执行JS...【" + operationValue + "");
break;
case "longpresselement":
LongPressOptions lpoptions = new LongPressOptions();
@ -137,7 +138,7 @@ public class IosEncapsulateOperation {
action.longPress(lpoptions).release().perform();
result = "longpresselement在屏幕指定元素上按住" + operationValue + "秒...【对象定位属性:" + property + "; 定位属性值:"
+ propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
default:
break;
@ -151,15 +152,15 @@ public class IosEncapsulateOperation {
switch (operation) {
case "alertaccept":
alert.accept();
luckyclient.publicclass.LogUtil.APP.info("弹出框对象点击同意...");
LogUtil.APP.info("弹出框对象点击同意...");
break;
case "alertdismiss":
alert.dismiss();
luckyclient.publicclass.LogUtil.APP.info("弹出框对象点击取消...");
LogUtil.APP.info("弹出框对象点击取消...");
break;
case "alertgettext":
result = "获取到的值是【" + alert.getText() + "";
luckyclient.publicclass.LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
break;
default:
break;
@ -187,19 +188,19 @@ public class IosEncapsulateOperation {
}
handlenum++;
}
luckyclient.publicclass.LogUtil.APP.info("getContext获取窗口句柄..." + result);
LogUtil.APP.info("getContext获取窗口句柄..." + result);
break;
case "exjs":
JavascriptExecutor jse = (JavascriptExecutor) appium;
jse.executeScript(operationValue);
result = "执行JS...【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【" + operationValue + "");
LogUtil.APP.info("执行JS...【" + operationValue + "");
break;
// 隐藏手机键盘
case "hideKeyboard":
appium.hideKeyboard();
result = "隐藏手机键盘...【hideKeyboard】";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "gotocontext":
Set<String> ctNames = appium.getContextHandles();
@ -213,19 +214,19 @@ public class IosEncapsulateOperation {
}
if (flag == 1) {
result = "切换context至【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "切换context失败未找到contextName值为【" + operationValue + "】的对象";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "getcontext":
result = "获取到的值是【" + appium.getContext() + "";
luckyclient.publicclass.LogUtil.APP.info("获取页面Context...【" + appium.getContext() + "");
LogUtil.APP.info("获取页面Context...【" + appium.getContext() + "");
break;
case "gettitle":
result = "获取到的值是【" + appium.getTitle() + "";
luckyclient.publicclass.LogUtil.APP.info("获取页面gettitle...【" + appium.getTitle() + "");
LogUtil.APP.info("获取页面gettitle...【" + appium.getTitle() + "");
break;
case "swipeup":
String[] tempup = operationValue.split("\\|", -1);
@ -235,14 +236,14 @@ public class IosEncapsulateOperation {
int num = Integer.valueOf(tempup[1]);
IosBaseAppium.swipePageUp(appium, second, num);
result = "swipeup页面向上滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipeup页面向上滑动参数判断次数出现异常【" + tempup[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipeup页面向上滑动参数判断时间出现异常【" + tempup[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "swipedown":
@ -253,14 +254,14 @@ public class IosEncapsulateOperation {
int num = Integer.valueOf(tempdown[1]);
IosBaseAppium.swipePageDown(appium, second, num);
result = "swipedown页面向下滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipedown页面向下滑动参数判断次数出现异常【" + tempdown[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipedown页面向下滑动参数判断时间出现异常【" + tempdown[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "swipleft":
@ -271,14 +272,14 @@ public class IosEncapsulateOperation {
int num = Integer.valueOf(templeft[1]);
IosBaseAppium.swipePageLeft(appium, second, num);
result = "swipleft页面向左滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipleft页面向左滑动参数判断次数出现异常【" + templeft[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipleft页面向左滑动参数判断时间出现异常【" + templeft[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "swipright":
@ -289,14 +290,14 @@ public class IosEncapsulateOperation {
int num = Integer.valueOf(tempright[1]);
IosBaseAppium.swipePageRight(appium, second, num);
result = "swipright页面向右滑动参数...秒|次数【" + second + "|" + num + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "swipright页面向右滑动参数判断次数出现异常【" + tempright[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "swipright页面向右滑动参数判断时间出现异常【" + tempright[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "longpressxy":
@ -314,19 +315,19 @@ public class IosEncapsulateOperation {
action.longPress(lpoptions).release().perform();
result = "longpressxy在屏幕指定XY坐标上按住" + longpressxy[2] + "秒...X|Y【" + longpressx + "|" + longpressy
+ "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
action.longPress(PointOption.point(longpressx, longpressy)).release().perform();
result = "longpressxy在屏幕指定XY坐标上长按...X|Y【" + longpressx + "|" + longpressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "longpressxy参数指定的Y坐标处理出现异常【" + longpressxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "longpressxy参数指定的X坐标处理出现异常【" + longpressxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "pressxy":
@ -337,14 +338,14 @@ public class IosEncapsulateOperation {
int pressy = Integer.valueOf(pressxy[1]);
action.press(PointOption.point(pressx, pressy)).release().perform();
result = "pressxy在屏幕指定XY坐标上点击...X|Y【" + pressx + "|" + pressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "pressxy参数指定的Y坐标处理出现异常【" + pressxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "pressxy参数指定的X坐标处理出现异常【" + pressxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "tapxy":
@ -355,14 +356,14 @@ public class IosEncapsulateOperation {
int tapy = Integer.valueOf(tapxy[1]);
action.tap(PointOption.point(tapx, tapy)).release().perform();
result = "tapxy在屏幕指定XY坐标上轻击...X|Y【" + tapx + "|" + tapy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "tapxy参数指定的Y坐标处理出现异常【" + tapxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "tapxy参数指定的X坐标处理出现异常【" + tapxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "jspressxy":
@ -374,19 +375,19 @@ public class IosEncapsulateOperation {
if (null != jspressxy[2] && ChangString.isNumeric(jspressxy[2])) {
IosBaseAppium.clickScreenForJs(appium, jspressx, jspressy, Integer.valueOf(jspressxy[2]));
result = "jspressxy在屏幕指定XY坐标上按" + jspressxy[2] + "秒...X|Y【" + jspressx + "|" + jspressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
IosBaseAppium.clickScreenForJs(appium, jspressx, jspressy, 2);
result = "jspressxy在屏幕指定XY坐标上按2秒(持续时间判断异常使用默认2秒时间)...X|Y【" + jspressx + "|" + jspressy + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "jspressxy参数指定的Y坐标处理出现异常【" + jspressxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
} else {
result = "jspressxy参数指定的X坐标处理出现异常【" + jspressxy[0] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "moveto":
@ -405,34 +406,34 @@ public class IosEncapsulateOperation {
action.press(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(Duration.ofNanos(1500)))
.moveTo(PointOption.point(endx, endy));
luckyclient.publicclass.LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
+ "】拖动至坐标【" + endxy[0] + "," + endxy[1] + "");
} else {
if (movexyi == 1) {
action.press(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(Duration.ofNanos(1500)))
.moveTo(PointOption.point(endx - startx, endy - starty));
luckyclient.publicclass.LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
LogUtil.APP.info("从开始坐标【" + startxy[0] + "," + startxy[1]
+ "】拖动至坐标【" + endxy[0] + "," + endxy[1] + "");
} else {
action.waitAction(WaitOptions.waitOptions(Duration.ofNanos(1500)))
.moveTo(PointOption.point(endx - startx, endy - starty));
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("" + movexyi + "次拖动至坐标【" + endxy[0] + "," + endxy[1] + "");
}
startx = endx;
starty = endy;
}
} else {
luckyclient.publicclass.LogUtil.APP.error("判断结束坐标位置出现异常,结束坐标参数【" + movexy[movexyi] + "");
LogUtil.APP.warn("判断结束坐标位置出现异常,结束坐标参数【" + movexy[movexyi] + "");
}
}
action.release().perform();
result = "moveto全部拖动释放并完成发送...开始位置【" + startxy[0] + "," + startxy[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "moveto参数指定的起始坐标处理出现异常【" + movexy[0] + "】,请检查!";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
}
break;
case "timeout":
@ -442,10 +443,10 @@ public class IosEncapsulateOperation {
// 设置元素出现最大时长30秒
appium.manage().timeouts().implicitlyWait(Integer.valueOf(operationValue), TimeUnit.SECONDS);
result = "设置全局页面加载&元素出现最大等待时间【" + operationValue + "】秒...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
} else {
result = "【等待时间转换出错,请检查参数】";
luckyclient.publicclass.LogUtil.APP.info(result + "原因是因为判断你的等待时间不是数字...");
LogUtil.APP.info(result + "原因是因为判断你的等待时间不是数字...");
}
break;
case "screenshot":
@ -453,7 +454,7 @@ public class IosEncapsulateOperation {
String imagname = "FunctionScreenShot_" + timeformat.format(new Date());
IosBaseAppium.screenShot(appium, imagname);
result = "截图名称【" + imagname + "】...";
luckyclient.publicclass.LogUtil.APP.info("使用方法主动截取当前屏幕..." + result);
LogUtil.APP.info("使用方法主动截取当前屏幕..." + result);
break;
default:
break;

View File

@ -11,6 +11,8 @@ import luckyclient.caserun.exappium.AppiumService;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.AppiumConfig;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -21,9 +23,7 @@ import luckyclient.serverapi.entity.ProjectCaseSteps;
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
*
* @date 2018年2月2日
*
*/
@ -37,7 +37,7 @@ public class IosOneCaseExecute {
IOSDriver<IOSElement> iosd = null;
AppiumService as=null;
try {
Properties properties = luckyclient.publicclass.AppiumConfig.getConfiguration();
Properties properties = AppiumConfig.getConfiguration();
//根据配置自动启动Appiume服务
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
as =new AppiumService();
@ -47,7 +47,7 @@ public class IosOneCaseExecute {
iosd = AppiumInitialization.setIosAppium(properties);
} catch (IOException e1) {
luckyclient.publicclass.LogUtil.APP.error("初始化IOSDriver出错", e1);
LogUtil.APP.error("初始化IOSDriver出错", e1);
e1.printStackTrace();
}
LogOperation caselog = new LogOperation();
@ -56,13 +56,13 @@ public class IosOneCaseExecute {
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
try {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
} catch (InterruptedException e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
LogOperation.updateTaskExecuteData(taskid, 0);

View File

@ -10,6 +10,7 @@ import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.caserun.publicdispose.ActionManageForSteps;
import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.publicclass.InvokeMethod;
import luckyclient.publicclass.LogUtil;
import luckyclient.publicclass.remoterinterface.HttpRequest;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
@ -56,7 +57,7 @@ public class ApiTestCaseDebug {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
if (steps.size() == 0) {
setcaseresult = 2;
luckyclient.publicclass.LogUtil.APP.error("用例中未找到步骤,请检查!");
LogUtil.APP.warn("用例中未找到步骤,请检查!");
testnote = "用例中未找到步骤,请检查!";
}
// 进入循环解析用例所有步骤
@ -70,7 +71,7 @@ public class ApiTestCaseDebug {
functionname = ChangString.changparams(functionname, variable, "方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "解析包名或是方法名失败,请检查!");
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "解析包名或是方法名失败,请检查!");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
}
@ -93,7 +94,7 @@ public class ApiTestCaseDebug {
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable, "用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename
+ " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
getParameterValues[j] = parameterValues;
}
@ -102,17 +103,17 @@ public class ApiTestCaseDebug {
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
LogUtil.APP.info("开始调用方法:" + functionname + " .....");
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues,
steps.get(i).getStepType(), steps.get(i).getExtend());
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
if (null != expectedresults && !expectedresults.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("expectedResults=【" + expectedresults + "");
LogUtil.APP.info("expectedResults=【" + expectedresults + "");
// 赋值传参
if (expectedresults.length() > ASSIGNMENT_SIGN.length()
&& expectedresults.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expectedresults.substring(ASSIGNMENT_SIGN.length()), testnote);
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给变量【"
+ expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
}
@ -120,19 +121,19 @@ public class ApiTestCaseDebug {
else if (expectedresults.length() > FUZZY_MATCHING_SIGN.length()
&& expectedresults.startsWith(FUZZY_MATCHING_SIGN)) {
if (testnote.contains(expectedresults.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info(
LogUtil.APP.info(
"用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果成功!执行结果:" + testnote);
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1)
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1)
+ "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length())
+ ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -142,66 +143,66 @@ public class ApiTestCaseDebug {
Pattern pattern = Pattern.compile(expectedresults.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(testnote);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info(
LogUtil.APP.info(
"用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果成功!执行结果:" + testnote);
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1)
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1)
+ "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length())
+ ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
// 完全相等
else {
if (expectedresults.equals(testnote)) {
luckyclient.publicclass.LogUtil.APP.info(
LogUtil.APP.info(
"用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果成功!执行结果:" + testnote);
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1)
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1)
+ "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
}
} catch (Exception e) {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
LogUtil.APP.error(e.getMessage(), e);
testnote = "CallCase调用出错";
e.printStackTrace();
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
variable.clear(); // 清空传参MAP
// 如果调用方法过程中未出错进入设置测试结果流程
if (testnote.indexOf("CallCase调用出错") <= -1 && testnote.indexOf("解析出错啦!") <= -1) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testCaseExternalId + "解析成功,并成功调用用例中方法,请继续查看执行结果!");
LogUtil.APP.info("用例 " + testCaseExternalId + "解析成功,并成功调用用例中方法,请继续查看执行结果!");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "解析或是调用步骤中的方法出错!");
LogUtil.APP.warn("用例 " + testCaseExternalId + "解析或是调用步骤中的方法出错!");
}
if (0 == setcaseresult) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testCaseExternalId + "步骤全部执行成功!");
LogUtil.APP.info("用例 " + testCaseExternalId + "步骤全部执行成功!");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "在执行过程中失败,请检查日志!");
LogUtil.APP.warn("用例 " + testCaseExternalId + "在执行过程中失败,请检查日志!");
}
}
@ -215,7 +216,7 @@ public class ApiTestCaseDebug {
System.out.println("当前调试用例总共:"+addtestcase.size());
for(String testCaseExternalId:addtestcase) {
try {
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("开始调用方法,项目名:" + projectname + ",用例编号:" + testCaseExternalId);
oneCaseDebug(projectname, testCaseExternalId);
} catch (Exception e) {

View File

@ -79,7 +79,7 @@ public class TestCaseExecution {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
if (steps.size() == 0) {
setcaseresult = 2;
luckyclient.publicclass.LogUtil.APP.error("用例中未找到步骤,请检查!");
LogUtil.APP.warn("用例中未找到步骤,请检查!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
testnote = "用例中未找到步骤,请检查!";
}
@ -93,7 +93,7 @@ public class TestCaseExecution {
functionname = ChangString.changparams(functionname, VARIABLE, "方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "解析包名或是方法名失败,请检查!");
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "解析包名或是方法名失败,请检查!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
@ -118,7 +118,7 @@ public class TestCaseExecution {
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, VARIABLE, "用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
getParameterValues[j] = parameterValues;
}
@ -127,7 +127,7 @@ public class TestCaseExecution {
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
LogUtil.APP.info("开始调用方法:" + functionname + " .....");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1), "");
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
@ -137,25 +137,24 @@ public class TestCaseExecution {
if (0 != stepresult) {
setcaseresult = stepresult;
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+steps.get(i).getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+steps.get(i).getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+steps.get(i).getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+steps.get(i).getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1), "");
luckyclient.publicclass.LogUtil.ERROR.error(e, e);
LogUtil.APP.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", e);
testnote = "CallCase调用出错";
setcaseresult = 1;
e.printStackTrace();
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -163,20 +162,20 @@ public class TestCaseExecution {
VARIABLE.clear(); // 清空传参MAP
// 如果调用方法过程中未出错进入设置测试结果流程
if (!testnote.contains("CallCase调用出错") && !testnote.contains("解析出错啦!")) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testcase.getCaseSign() + "解析成功,并成功调用用例中方法,请继续查看执行结果!");
LogUtil.APP.info("用例 " + testcase.getCaseSign() + "解析成功,并成功调用用例中方法,请继续查看执行结果!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info", "SETCASERESULT...", "");
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例 " + testcase.getCaseSign() + "解析或是调用步骤中的方法出错!");
LogUtil.APP.warn("用例 " + testcase.getCaseSign() + "解析或是调用步骤中的方法出错!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析或是调用步骤中的方法出错!", "error", "SETCASERESULT...", "");
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 2);
}
if (0 == setcaseresult) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testcase.getCaseSign() + "步骤全部执行成功!");
LogUtil.APP.info("用例 " + testcase.getCaseSign() + "步骤全部执行成功!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "步骤全部执行成功!", "info", "EXECUTECASESUC...", "");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testcase.getCaseSign() + "在执行过程中失败,请检查日志!");
LogUtil.APP.warn("用例 " + testcase.getCaseSign() + "在执行过程中失败,请检查日志!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在执行过程中失败,请检查日志!", "error", "EXECUTECASESUC...", "");
}
LogOperation.updateTaskExecuteData(taskid, 0);
@ -207,7 +206,7 @@ public class TestCaseExecution {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
if (steps.size() == 0) {
setresult = 2;
luckyclient.publicclass.LogUtil.APP.error("用例中未找到步骤,请检查!");
LogUtil.APP.warn("用例中未找到步骤,请检查!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
testnote = "用例中未找到步骤,请检查!";
}
@ -221,7 +220,7 @@ public class TestCaseExecution {
functionname = ChangString.changparams(functionname, variable, "方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseId() + "解析包名或是方法名失败,请检查!");
LogUtil.APP.error("用例:" + testcase.getCaseId() + "解析包名或是方法名失败,请检查!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
@ -245,7 +244,7 @@ public class TestCaseExecution {
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable, "用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
getParameterValues[j] = parameterValues;
}
@ -254,25 +253,25 @@ public class TestCaseExecution {
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
LogUtil.APP.info("开始调用方法:" + functionname + " .....");
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
if (null != expectedresults && !expectedresults.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("expectedResults=【" + expectedresults + "");
LogUtil.APP.info("expectedResults=【" + expectedresults + "");
// 赋值传参
if (expectedresults.length() > ASSIGNMENT_SIGN.length() && expectedresults.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expectedresults.substring(ASSIGNMENT_SIGN.length()), testnote);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
}
// 模糊匹配
else if (expectedresults.length() > FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(FUZZY_MATCHING_SIGN)) {
if (testnote.contains(expectedresults.substring(FUZZY_MATCHING_SIGN.length()))) {
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果成功!执行结果:" + testnote);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
break; // 某一步骤失败后此条用例置为失败退出
}
@ -283,10 +282,10 @@ public class TestCaseExecution {
Matcher matcher = pattern.matcher(testnote);
if (matcher.find()) {
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果成功!执行结果:" + testnote);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
break; // 某一步骤失败后此条用例置为失败退出
}
@ -295,18 +294,17 @@ public class TestCaseExecution {
else {
if (expectedresults.equals(testnote)) {
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果成功!执行结果:" + testnote);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
break; // 某一步骤失败后此条用例置为失败退出
}
}
}
} catch (Exception e) {
LogUtil.ERROR.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
LogUtil.ERROR.error(e, e);
LogUtil.APP.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!",e);
testnote = "CallCase调用出错";
setresult = 1;
e.printStackTrace();
@ -315,9 +313,9 @@ public class TestCaseExecution {
}
variable.clear(); // 清空传参MAP
if (0 == setresult) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testcase.getCaseSign() + "步骤全部执行成功!");
LogUtil.APP.info("用例 " + testcase.getCaseSign() + "步骤全部执行成功!");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testcase.getCaseSign() + "在执行过程中失败,请检查日志!");
LogUtil.APP.warn("用例 " + testcase.getCaseSign() + "在执行过程中失败,请检查日志!");
}
return testnote;
}
@ -348,7 +346,7 @@ public class TestCaseExecution {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
if (steps.size() == 0) {
setresult = 2;
luckyclient.publicclass.LogUtil.APP.error("用例中未找到步骤,请检查!");
LogUtil.APP.warn("用例中未找到步骤,请检查!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
testnote = "用例中未找到步骤,请检查!";
}
@ -409,10 +407,10 @@ public class TestCaseExecution {
VARIABLE.clear(); // 清空传参MAP
if (0 == setresult) {
testnote = "调用用例【" + testcase.getCaseSign() + "】执行成功!";
luckyclient.publicclass.LogUtil.APP.info("用例 " + testcase.getCaseSign() + "步骤全部执行成功!");
LogUtil.APP.info("用例 " + testcase.getCaseSign() + "步骤全部执行成功!");
} else {
testnote = "调用用例【" + testcase.getCaseSign() + "】执行失败,请检查日志!";
luckyclient.publicclass.LogUtil.APP.error("用例 " + testcase.getCaseSign() + "在执行过程中失败,请检查日志!");
LogUtil.APP.warn("用例 " + testcase.getCaseSign() + "在执行过程中失败,请检查日志!");
}
return testnote;
}
@ -440,7 +438,7 @@ public class TestCaseExecution {
functionname = ChangString.changparams(functionname, variable, "方法名");
if (null != functionname && functionname.contains("解析异常")) {
LogUtil.APP.error("用例: " + casenum + ", 解析这个方法【" + functionname + "】失败!");
LogUtil.APP.warn("用例: " + casenum + ", 解析这个方法【" + functionname + "】失败!");
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "用例: " + casenum + ", 解析这个方法【" + functionname + "】失败!", "error", String.valueOf(step.getStepSerialNumber()), "");
result = "步骤执行失败:解析用例失败!";
} else {
@ -454,7 +452,7 @@ public class TestCaseExecution {
}
String parameterValues = params.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable, "用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例: " + casenum + ", 解析包路径:" + packagename + "; 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
LogUtil.APP.info("用例: " + casenum + ", 解析包路径:" + packagename + "; 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "用例: " + casenum + ", 解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(step.getStepSerialNumber()), "");
getParameterValues[j] = parameterValues;
}
@ -484,28 +482,28 @@ public class TestCaseExecution {
int setresult = 0;
try{
if (null != expectedresults && !expectedresults.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("expectedResults=【" + expectedresults + "");
LogUtil.APP.info("expectedResults=【" + expectedresults + "");
// 赋值传参
if (expectedresults.length() > ASSIGNMENT_SIGN.length() && expectedresults.startsWith(ASSIGNMENT_SIGN)) {
VARIABLE.put(expectedresults.substring(ASSIGNMENT_SIGN.length()), testnote);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 赋值全局变量
else if (expectedresults.length() > ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(ASSIGNMENT_GLOBALSIGN)) {
VARIABLE.put(expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()), testnote);
ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()), testnote);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 模糊匹配
else if (expectedresults.length() > FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(FUZZY_MATCHING_SIGN)) {
if (testnote.contains(expectedresults.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
testnote = "用例第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
}
@ -515,11 +513,11 @@ public class TestCaseExecution {
Pattern pattern = Pattern.compile(expectedresults.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(testnote);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
testnote = "用例第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
}
@ -527,11 +525,11 @@ public class TestCaseExecution {
// 完全相等
else {
if (expectedresults.equals(testnote)) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
testnote = "用例第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
}

View File

@ -12,6 +12,7 @@ import luckyclient.jenkinsapi.BuildingInitialization;
import luckyclient.jenkinsapi.RestartServerInitialization;
import luckyclient.mail.HtmlMail;
import luckyclient.mail.MailSendInitialization;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -59,7 +60,7 @@ public class TestControl {
for (ProjectCase testcase : testCases) {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
if (steps.size() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【" + testcase.getCaseSign() + "】没有找到步骤,直接跳过,请检查!");
LogUtil.APP.warn("用例【" + testcase.getCaseSign() + "】没有找到步骤,直接跳过,请检查!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在用例中没有找到步骤,请检查", "error", "1", "");
continue;
}
@ -75,7 +76,7 @@ public class TestControl {
}
Thread.sleep(6000);
}
luckyclient.publicclass.LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
threadExecute.shutdown();
}
@ -115,15 +116,15 @@ public class TestControl {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(projectcase.getCaseId());
if (steps.size() == 0) {
caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),projectcase.getCaseId(),projectcase.getCaseSign(), projectcase.getCaseName(), 2);
luckyclient.publicclass.LogUtil.APP.error("用例【" + projectcase.getCaseSign() + "】没有找到步骤,直接跳过,请检查!");
LogUtil.APP.warn("用例【" + projectcase.getCaseSign() + "】没有找到步骤,直接跳过,请检查!");
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(), "在用例中没有找到步骤,请检查", "error", "1", "");
continue;
}
// 多线程计数,如果用例设置了优先级必须等优先级高的用例执行完成才继续后面的用例
if (casepriority < projectcase.getPriority()) {
luckyclient.publicclass.LogUtil.APP.info("用例编号:" + projectcase.getCaseSign() + " casepriority"
LogUtil.APP.info("用例编号:" + projectcase.getCaseSign() + " casepriority"
+ casepriority + " projectcase.getPriority()" + projectcase.getPriority());
luckyclient.publicclass.LogUtil.APP.info("THREAD_COUNT" + THREAD_COUNT);
LogUtil.APP.info("THREAD_COUNT" + THREAD_COUNT);
int i = 0;
while (THREAD_COUNT != 0) {
i++;
@ -153,14 +154,14 @@ public class TestControl {
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime, jobname),
taskid, taskScheduling, tastcount);
threadExecute.shutdown();
luckyclient.publicclass.LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
LogUtil.APP.warn("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid,
taskScheduling, tastcount);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
LogUtil.APP.warn("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid,
taskScheduling, tastcount);
}

View File

@ -12,6 +12,7 @@ import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.caserun.publicdispose.ParamsManageForSteps;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.InvokeMethod;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
import luckyclient.serverapi.entity.ProjectCaseSteps;
@ -83,7 +84,7 @@ public class ThreadForExecuteCase extends Thread {
functionname = ChangString.changparams(functionname, variable, "方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "解析包名或是方法名失败,请检查!");
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "解析包名或是方法名失败,请检查!");
caselog.insertTaskCaseLog(taskid, caseId, "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
@ -107,7 +108,7 @@ public class ThreadForExecuteCase extends Thread {
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable, "用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
caselog.insertTaskCaseLog(taskid, caseId, "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
getParameterValues[j] = parameterValues;
}
@ -116,41 +117,41 @@ public class ThreadForExecuteCase extends Thread {
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "开始调用方法:" + functionname + " .....");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "开始调用方法:" + functionname + " .....");
caselog.insertTaskCaseLog(taskid, caseId, "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1), "");
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
if (null != expectedresults && !expectedresults.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("expectedResults=【" + expectedresults + "");
LogUtil.APP.info("expectedResults=【" + expectedresults + "");
// 赋值传参
if (expectedresults.length() > ASSIGNMENT_SIGN.length() && expectedresults.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expectedresults.substring(ASSIGNMENT_SIGN.length()), testnote);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, caseId, "将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(i + 1), "");
}
// 赋值全局变量
else if (expectedresults.length() > ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(ASSIGNMENT_GLOBALSIGN)) {
variable.put(expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()), testnote);
ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()), testnote);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, caseId, "将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(i + 1), "");
}
// 模糊匹配
else if (expectedresults.length() > FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(FUZZY_MATCHING_SIGN)) {
if (testnote.contains(expectedresults.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果成功!执行结果:" + testnote);
caselog.insertTaskCaseLog(taskid, caseId, "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
caselog.insertTaskCaseLog(taskid, caseId, "" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -159,52 +160,51 @@ public class ThreadForExecuteCase extends Thread {
Pattern pattern = Pattern.compile(expectedresults.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(testnote);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果成功!执行结果:" + testnote);
caselog.insertTaskCaseLog(taskid, caseId, "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote);
caselog.insertTaskCaseLog(taskid, caseId, "" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
// 完全相等
else {
if (expectedresults.equals(testnote)) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果成功!执行结果:" + testnote);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果成功!执行结果:" + testnote);
caselog.insertTaskCaseLog(taskid, caseId, "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
} else {
setcaseresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
caselog.insertTaskCaseLog(taskid, caseId, "" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcase.getCaseSign() + "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!",e);
caselog.insertTaskCaseLog(taskid, caseId, "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1), "");
luckyclient.publicclass.LogUtil.ERROR.error(e, e);
testnote = "CallCase调用出错调用方法过程出错方法名" + functionname + " 请重新检查脚本方法名称以及参数!";
setcaseresult = 1;
e.printStackTrace();
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -215,29 +215,27 @@ public class ThreadForExecuteCase extends Thread {
caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult);
} else {
// 解析用例或是调用方法出错全部把用例置为锁定
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcase.getCaseSign() + "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....");
caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....","error", "SETCASERESULT...", "");
setcaseresult = 2;
caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult);
}
if (0 == setcaseresult) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "执行结果成功......");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "执行结果成功......");
caselog.insertTaskCaseLog(taskid, caseId, "用例步骤执行全部成功......", "info", "ending", "");
luckyclient.publicclass.LogUtil.APP.info("*********用例【" + testcase.getCaseSign() + "】执行完成,测试结果:成功*********");
LogUtil.APP.info("*********用例【" + testcase.getCaseSign() + "】执行完成,测试结果:成功*********");
} else if (1 == setcaseresult) {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcase.getCaseSign() + "执行结果失败......");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "执行结果失败......");
caselog.insertTaskCaseLog(taskid, caseId, "用例执行结果失败......", "error", "ending", "");
luckyclient.publicclass.LogUtil.APP.info("*********用例【" + testcase.getCaseSign() + "】执行完成,测试结果:失败*********");
LogUtil.APP.info("*********用例【" + testcase.getCaseSign() + "】执行完成,测试结果:失败*********");
} else {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcase.getCaseSign() + "执行结果锁定......");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "执行结果锁定......");
caselog.insertTaskCaseLog(taskid, caseId, "用例执行结果锁定......", "error", "ending", "");
luckyclient.publicclass.LogUtil.APP.info("*********用例【" + testcase.getCaseSign() + "】执行完成,测试结果:锁定*********");
LogUtil.APP.info("*********用例【" + testcase.getCaseSign() + "】执行完成,测试结果:锁定*********");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcase.getCaseSign() + "设置执行结果过程出错......");
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "设置执行结果过程出错......",e);
caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果过程出错......", "error", "ending", "");
luckyclient.publicclass.LogUtil.ERROR.error(e, e);
e.printStackTrace();
} finally {
variable.clear(); // 一条用例结束后清空变量存储空间
TestControl.THREAD_COUNT--; // 多线程计数--用于检测线程是否全部执行完

View File

@ -10,6 +10,7 @@ import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.caserun.publicdispose.ActionManageForSteps;
import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.publicclass.InvokeMethod;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.api.PostServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
@ -118,10 +119,10 @@ public class WebTestCaseDebug {
PostServerAPI.cPostDebugLog(userId, caseId, "ERROR", "" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote,0);
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -136,10 +137,10 @@ public class WebTestCaseDebug {
PostServerAPI.cPostDebugLog(userId, caseId, "ERROR", "" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote,0);
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -152,10 +153,10 @@ public class WebTestCaseDebug {
PostServerAPI.cPostDebugLog(userId, caseId, "ERROR", "" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote,0);
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -166,10 +167,10 @@ public class WebTestCaseDebug {
testnote = "CallCase调用出错";
e.printStackTrace();
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+(i + 1)+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}

View File

@ -6,6 +6,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseSteps;
/**
@ -58,16 +59,15 @@ public class InterfaceAnalyticCase{
}else{
params.put("ExpectedResults", subComment(resultstr));
}
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
LogUtil.APP.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!",e);
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
return params;
}

View File

@ -9,6 +9,8 @@ import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -38,11 +40,11 @@ public class BaseWebDrive {
try {
FileUtils.copyFile(scrFile, new File(pngpath));
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error("截图操作失败,抛出异常请查看日志...", e);
LogUtil.APP.error("截图操作失败,抛出异常请查看日志...", e);
e.printStackTrace();
}
scrFile.deleteOnExit();
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【" + pngpath + "");
return result;
}

View File

@ -7,6 +7,7 @@ import org.openqa.selenium.WebDriver;
import luckyclient.caserun.exwebdriver.ex.WebCaseExecution;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -33,12 +34,12 @@ public class CaseLocalDebug{
try {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
List<ProjectCaseSteps> steps=GetServerAPI.getStepsbycaseid(testcase.getCaseId());
WebCaseExecution.caseExcution(testcase,steps, "888888",wd,caselog,pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【"+testcase.getCaseSign()+"】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【"+testcase.getCaseSign()+"】执行完成......进入下一条");
} catch (Exception e) {
luckyclient.publicclass.LogUtil.ERROR.info("用户执行过程中抛出异常!", e);
LogUtil.APP.info("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
//关闭浏览器
@ -55,7 +56,7 @@ public class CaseLocalDebug{
System.out.println("当前调试用例总共:"+addtestcase.size());
for(String testCaseExternalId:addtestcase) {
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:" + testCaseExternalId);
LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:" + testCaseExternalId);
oneCasedebug(wd,testCaseExternalId);
}catch(Exception e){
continue;

View File

@ -1,5 +1,27 @@
package luckyclient.caserun.exwebdriver;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.Point;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -7,19 +29,6 @@ import com.alibaba.fastjson.JSONObject;
import luckyclient.caserun.exwebdriver.ocr.Ocr;
import luckyclient.caserun.publicdispose.ChangString;
import luckyclient.publicclass.LogUtil;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
* =================================================================
@ -43,21 +52,21 @@ public class EncapsulateOperation {
case "selectbyvisibletext":
select.selectByVisibleText(operationValue);
result = "下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "selectbyvalue":
select.selectByValue(operationValue);
result = "下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "selectbyindex":
select.selectByIndex(Integer.valueOf(operationValue));
result = "下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "isselect":
result = "获取到的值是【" + we.isSelected() + "";
luckyclient.publicclass.LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + we.isSelected() + "");
LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + we.isSelected() + "");
break;
default:
break;
@ -71,23 +80,23 @@ public class EncapsulateOperation {
switch (operation) {
case "gettext":
result = "获取到的值是【" + we.getText() + "";
luckyclient.publicclass.LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
break; // 获取输入框内容
case "gettagname":
result = "获取到的值是【" + we.getTagName() + "";
luckyclient.publicclass.LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
break;
case "getattribute":
result = "获取到的值是【" + we.getAttribute(value) + "";
luckyclient.publicclass.LogUtil.APP.info("getAttribute获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
LogUtil.APP.info("getAttribute获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
break;
case "getcssvalue":
result = "获取到的值是【" + we.getCssValue(value) + "";
luckyclient.publicclass.LogUtil.APP.info("getCssValue获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
LogUtil.APP.info("getCssValue获取对象【" + value + "】属性...【" + value + "属性值:" + result + "");
break;
case "getcaptcha":
result = "获取到的值是【" + Ocr.getCAPTCHA(wd, we) + "";
luckyclient.publicclass.LogUtil.APP.info("getcaptcha获取验证码...【验证码值:" + result + "");
LogUtil.APP.info("getcaptcha获取验证码...【验证码值:" + result + "");
break;
default:
break;
@ -104,41 +113,41 @@ public class EncapsulateOperation {
case "mouselkclick":
action.click(we).perform();
result = "mouselkclick鼠标左键点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouserkclick":
action.contextClick(we).perform();
result = "mouserkclick鼠标右键点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mousedclick":
action.doubleClick(we).perform();
result = "mousedclick鼠标双击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouseclickhold":
action.clickAndHold(we).perform();
result = "mouseclickhold鼠标点击对象后不释放...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mousedrag":
int[] location = getLocationFromParam(operationValue, ",");
// String[] temp = operationValue.split(",", -1);
action.dragAndDropBy(we, location[0], location[1]).perform();
result = "mousedrag鼠标移动至对象相对坐标...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 相对坐标(x,y):" + location[0] + "," + location[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouseto":
int[] location1 = getLocationFromParam(operationValue, ",");
// String[] temp1 = operationValue.split(",", -1);
action.moveToElement(we, location1[0], location1[1]).perform();
result = "mouseto鼠标移动至对象相对坐标...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 相对坐标(x,y):" + location1[0] + "," + location1[1] + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouserelease":
action.release(we).perform();
result = "mouserelease鼠标释放...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
default:
break;
@ -155,61 +164,61 @@ public class EncapsulateOperation {
case "mouselkclick":
action.click().perform();
result = "mouselkclick鼠标左键点击当前位置...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouserkclick":
action.contextClick().perform();
result = "mouserkclick鼠标右键点击当前位置...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mousedclick":
action.doubleClick().perform();
result = "mousedclick鼠标双击当前位置...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouseclickhold":
action.clickAndHold().perform();
result = "mouseclickhold鼠标点击当前位置后不释放...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouseto":
int[] location = getLocationFromParam(operationValue, ",");
// String[] temp1 = operationValue.split(",", -1);
action.moveByOffset(location[0], location[1]).perform();
result = "mouseto鼠标移动至对象相对坐标...坐标x" + location[0] + " 坐标y" + location[1];
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mouserelease":
action.release().perform();
result = "mouserelease鼠标释放...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "mousekey":
switch (operationValue) {
case "tab":
action.sendKeys(Keys.TAB).perform();
result = "键盘操作TAB键...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "space":
action.sendKeys(Keys.SPACE).perform();
result = "键盘操作SPACE键...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "ctrl":
action.sendKeys(Keys.CONTROL).perform();
result = "键盘操作CONTROL键...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "shift":
action.sendKeys(Keys.SHIFT).perform();
result = "键盘操作SHIFT键...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "enter":
action.sendKeys(Keys.ENTER).perform();
result = "键盘操作ENTER键...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
default:
break;
@ -228,30 +237,30 @@ public class EncapsulateOperation {
case "click":
we.click();
result = "click点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "sendkeys":
we.sendKeys(operationValue);
result = "sendKeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 操作值:" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "clear":
we.clear();
result = "clear清空输入框...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break; // 清空输入框
case "gotoframe":
wd.switchTo().frame(we);
result = "gotoframe切换Frame...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "isenabled":
result = "获取到的值是【" + we.isEnabled() + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "isdisplayed":
result = "获取到的值是【" + we.isDisplayed() + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "exjsob":
JavascriptExecutor jse = (JavascriptExecutor) wd;
@ -291,16 +300,16 @@ public class EncapsulateOperation {
case "alertaccept":
alert.accept();
result = "弹出框对象点击同意...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "alertdismiss":
alert.dismiss();
result = "弹出框对象点击取消...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "alertgettext":
result = "获取到的值是【" + alert.getText() + "";
luckyclient.publicclass.LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
break;
default:
break;
@ -315,14 +324,14 @@ public class EncapsulateOperation {
case "open":
wd.get(operationValue);
result = "Open页面...【" + operationValue + "";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "addcookie":
List<Cookie> cookies = buildCookie(operationValue);
if (null != cookies && cookies.size() > 0) {
for (Cookie cookie : cookies) {
wd.manage().addCookie(cookie);
luckyclient.publicclass.LogUtil.APP.info("添加Cookie:【"+cookie+"】成功!");
LogUtil.APP.info("添加Cookie:【"+cookie+"】成功!");
}
}
result = "添加cookie...【" + operationValue + "";
@ -343,7 +352,7 @@ public class EncapsulateOperation {
case "gotodefaultcontent":
wd.switchTo().defaultContent();
result = "gotodefaultcontent切换至默认页面位置...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
case "gotoparentframe":
wd.switchTo().parentFrame();
@ -352,7 +361,7 @@ public class EncapsulateOperation {
break;
case "gettitle":
result = "获取到的值是【" + wd.getTitle() + "";
luckyclient.publicclass.LogUtil.APP.info("获取页面Title...【" + wd.getTitle() + "");
LogUtil.APP.info("获取页面Title...【" + wd.getTitle() + "");
break;
case "getwindowhandle":
result = getTargetWindowHandle(wd, operationValue);
@ -371,10 +380,10 @@ public class EncapsulateOperation {
// 设置元素出现最大时长30秒
wd.manage().timeouts().implicitlyWait(Integer.valueOf(operationValue), TimeUnit.SECONDS);
result = "当前任务操作等待【" + operationValue + "】秒...";
luckyclient.publicclass.LogUtil.APP.info(result);
LogUtil.APP.info(result);
break;
} catch (NumberFormatException e) {
luckyclient.publicclass.LogUtil.APP.error("等待时间转换出错!");
LogUtil.APP.error("等待时间转换出错!");
e.printStackTrace();
result = "【等待时间转换出错,请检查参数】";
break;
@ -387,13 +396,13 @@ public class EncapsulateOperation {
private static List<Cookie> buildCookie(String operationValue) {
if (StringUtils.isBlank(operationValue)) {
luckyclient.publicclass.LogUtil.APP.info("获取Cookie值operationValue为空");
LogUtil.APP.info("获取Cookie值operationValue为空");
return null;
}
try {
JSONArray objects = JSON.parseArray(operationValue);
if (null == objects) {
luckyclient.publicclass.LogUtil.APP.info("格式化Cookie字符串成JSONArray对象为空");
LogUtil.APP.info("格式化Cookie字符串成JSONArray对象为空");
return null;
}
List<Cookie> result = new ArrayList<>(objects.size());
@ -410,16 +419,16 @@ public class EncapsulateOperation {
//String expire = jsonObject.getString("expire");
if (!StringUtils.isBlank(name) && !StringUtils.isBlank(val)) {
Cookie cookie = new Cookie(name, val, domain, path, null);
luckyclient.publicclass.LogUtil.APP.info("解析Cookie成功"+cookie+"");
LogUtil.APP.info("解析Cookie成功"+cookie+"");
result.add(cookie);
}else{
luckyclient.publicclass.LogUtil.APP.error("cookie:" + jsonObject + "错误,name或是val为空");
LogUtil.APP.warn("cookie:" + jsonObject + "错误,name或是val为空");
}
}
return result;
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("格式化Cookie对象出错请检查您的格式是否正确"+operationValue+"");
LogUtil.APP.error("格式化Cookie对象出错请检查您的格式是否正确"+operationValue+"");
return null;
}
}
@ -456,7 +465,7 @@ public class EncapsulateOperation {
} else {
result = "获取窗口句柄值失败WebDriver为空";
}
if (result.contains("获取窗口句柄值失败")) LogUtil.APP.error(result);
if (result.contains("获取窗口句柄值失败")) LogUtil.APP.warn(result);
else LogUtil.APP.info("获取窗口句柄值成功,目标窗口句柄值为【" + result + "");
return result;
}
@ -549,7 +558,7 @@ public class EncapsulateOperation {
try {
if (null == Wait(driver).until(windowToBeAvailableAndSwitchToIt(target))) {
result = "切换窗口句柄失败,未找到句柄值为【" + target + "】的对象";
LogUtil.APP.error(result);
LogUtil.APP.warn(result);
} else {
result = "切换窗口句柄成功,找到句柄值为【" + target + "】的对象";
LogUtil.APP.info(result);

View File

@ -13,6 +13,8 @@ import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.ie.InternetExplorerDriver;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -38,13 +40,13 @@ public class WebDriverInitialization{
File directory = new File("");
String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
WebDriver webDriver = null;
luckyclient.publicclass.LogUtil.APP.info("准备初始化WebDriver对象...检查到当前操作系统是:"+os);
LogUtil.APP.info("准备初始化WebDriver对象...检查到当前操作系统是:"+os);
if(drivertype==0){
if(os.startsWith("win")){
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
webDriver = new InternetExplorerDriver();
}else{
luckyclient.publicclass.LogUtil.APP.error("当前操作系统无法进行IE浏览器的Web UI测试请选择火狐或是谷歌浏览器");
LogUtil.APP.warn("当前操作系统无法进行IE浏览器的Web UI测试请选择火狐或是谷歌浏览器");
}
}else if(drivertype==1){
FirefoxOptions options = new FirefoxOptions();
@ -54,7 +56,7 @@ public class WebDriverInitialization{
options.addArguments("start-maximized");
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver_mac");
}else{
luckyclient.publicclass.LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Firefox浏览器的Web UI自动化...");
LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Firefox浏览器的Web UI自动化...");
//无界面参数
options.setHeadless(true);
//禁用沙盒
@ -71,7 +73,7 @@ public class WebDriverInitialization{
options.addArguments("start-maximized");
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver_mac");
}else{
luckyclient.publicclass.LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Chrome浏览器的Web UI自动化...");
LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Chrome浏览器的Web UI自动化...");
//无界面参数
options.setHeadless(true);
//禁用沙盒
@ -85,11 +87,10 @@ public class WebDriverInitialization{
System.setProperty("webdriver.edge.driver",drivenpath+"MicrosoftWebDriver.exe");
webDriver = new EdgeDriver();
}else{
luckyclient.publicclass.LogUtil.APP.error("当前操作系统无法进行Edge浏览器的Web UI测试请选择火狐或是谷歌浏览器");
LogUtil.APP.warn("当前操作系统无法进行Edge浏览器的Web UI测试请选择火狐或是谷歌浏览器");
}
}else{
luckyclient.publicclass.LogUtil.APP.error("浏览器类型标识:"+drivertype);
luckyclient.publicclass.LogUtil.APP.error("获取到的浏览器类型标识未定义默认IE浏览器进行执行....");
LogUtil.APP.warn("浏览器类型标识:"+drivertype+"获取到的浏览器类型标识未定义默认IE浏览器进行执行....");
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
webDriver = new InternetExplorerDriver();
}

View File

@ -16,6 +16,7 @@ import luckyclient.jenkinsapi.BuildingInitialization;
import luckyclient.jenkinsapi.RestartServerInitialization;
import luckyclient.mail.HtmlMail;
import luckyclient.mail.MailSendInitialization;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -59,7 +60,7 @@ public class WebTestControl {
if (testCases.size() != 0) {
pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
}
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + testCases.size() + "");
LogUtil.APP.info("当前计划中读取到用例共 " + testCases.size() + "");
int i = 0;
for (ProjectCase testcase : testCases) {
List<ProjectCaseSteps> steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
@ -67,17 +68,17 @@ public class WebTestControl {
continue;
}
i++;
luckyclient.publicclass.LogUtil.APP.info("开始执行第" + i + "条用例:【" + testcase.getCaseSign() + "】......");
LogUtil.APP.info("开始执行第" + i + "条用例:【" + testcase.getCaseSign() + "】......");
try {
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
}
luckyclient.publicclass.LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
// 关闭浏览器
wd.quit();
}
@ -104,16 +105,16 @@ public class WebTestControl {
try {
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
} catch (WebDriverException e1) {
luckyclient.publicclass.LogUtil.APP.error("初始化WebDriver出错 WebDriverException", e1);
LogUtil.APP.error("初始化WebDriver出错 WebDriverException", e1);
e1.printStackTrace();
} catch (IOException e2) {
luckyclient.publicclass.LogUtil.APP.error("初始化WebDriver出错 IOException", e2);
LogUtil.APP.error("初始化WebDriver出错 IOException", e2);
e2.printStackTrace();
}
LogOperation caselog = new LogOperation();
List<ProjectCase> cases = GetServerAPI.getCasesbyplanId(taskScheduling.getPlanId());
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogOperation.updateTaskExecuteStatus(taskid, cases.size());
for (ProjectCase testcase : cases) {
@ -121,34 +122,34 @@ public class WebTestControl {
if (steps.size() == 0) {
continue;
}
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
try {
// 插入开始执行的用例
caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4);
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
}
tastcount = LogOperation.updateTaskExecuteData(taskid, cases.size());
String testtime = LogOperation.getTestTime(taskid);
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime, jobname),
taskid, taskScheduling, tastcount);
// 关闭浏览器
wd.quit();
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
LogUtil.APP.warn("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.sendMailInitialization(jobname, "构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid,
taskScheduling, tastcount);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
LogUtil.APP.warn("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.sendMailInitialization(jobname, "项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid,
taskScheduling, tastcount);
}

View File

@ -10,6 +10,7 @@ import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.WebDriverInitialization;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -56,7 +57,7 @@ public class WebBatchExecute{
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}
@ -71,7 +72,7 @@ public class WebBatchExecute{
WebCaseExecution.caseExcution(testcase, steps,taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
}

View File

@ -82,10 +82,10 @@ public class WebCaseExecution extends TestCaseExecution {
if (0 != stepresult) {
setcaseresult = stepresult;
if (testcase.getFailcontinue() == 0) {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
break;
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
}
}
}
@ -93,10 +93,10 @@ public class WebCaseExecution extends TestCaseExecution {
variable.clear();
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
if (setcaseresult == 0) {
luckyclient.publicclass.LogUtil.APP.info("用例【" + testcase.getCaseSign() + "】全部步骤执行结果成功...");
LogUtil.APP.info("用例【" + testcase.getCaseSign() + "】全部步骤执行结果成功...");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功", "info", "ending", "");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例【" + testcase.getCaseSign() + "】步骤执行过程中失败或是锁定...请查看具体原因!" + casenote);
LogUtil.APP.warn("用例【" + testcase.getCaseSign() + "】步骤执行过程中失败或是锁定...请查看具体原因!" + casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定" + casenote, "error", "ending", "");
}
}
@ -120,11 +120,11 @@ public class WebCaseExecution extends TestCaseExecution {
operation = ChangString.changparams(operation, variable, "操作");
operationValue = ChangString.changparams(operationValue, variable, "操作参数");
luckyclient.publicclass.LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:" + operation + "; 操作值:" + operationValue, "info", String.valueOf(stepno), "");
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("二次解析用例过程抛出异常!---" + e.getMessage());
LogUtil.APP.error("二次解析用例过程抛出异常!---" + e.getMessage());
return "步骤执行失败:解析用例失败!";
}
@ -145,7 +145,7 @@ public class WebCaseExecution extends TestCaseExecution {
WebElement we = isElementExist(wd, property, propertyValue);
// 判断此元素是否存在
if (null == we) {
luckyclient.publicclass.LogUtil.APP.error("定位对象失败isElementExist为null!");
LogUtil.APP.warn("定位对象失败isElementExist为null!");
return "步骤执行失败:定位的元素不存在!";
}
@ -169,11 +169,11 @@ public class WebCaseExecution extends TestCaseExecution {
result = EncapsulateOperation.driverOperation(wd, operation, operationValue);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("元素操作过程失败!");
LogUtil.APP.warn("元素操作过程失败!");
result = "步骤执行失败:元素操作过程失败!";
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("元素定位过程或是操作过程失败或异常!" + e.getMessage());
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!" + e.getMessage());
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
@ -218,7 +218,7 @@ public class WebCaseExecution extends TestCaseExecution {
return we;
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("当前对象定位失败:" + e.getMessage());
LogUtil.APP.error("当前对象定位失败:" + e.getMessage());
return null;
}
@ -233,18 +233,18 @@ public class WebCaseExecution extends TestCaseExecution {
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
luckyclient.publicclass.LogUtil.APP.info("期望结果为【" + expect + "");
LogUtil.APP.info("期望结果为【" + expect + "");
// 赋值传参模式
if (expect.length() > ASSIGNMENT_SIGN.length() && expect.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expect.substring(ASSIGNMENT_SIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 赋值全局变量
else if (expect.length() > ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(ASSIGNMENT_GLOBALSIGN)) {
variable.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// WebUI检查模式
@ -254,13 +254,13 @@ public class WebCaseExecution extends TestCaseExecution {
WebElement we = isElementExist(driver, checkproperty, checkPropertyValue);
if (null != we) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -269,13 +269,13 @@ public class WebCaseExecution extends TestCaseExecution {
// 模糊匹配预期结果模式
if (expect.length() > FUZZY_MATCHING_SIGN.length() && expect.startsWith(FUZZY_MATCHING_SIGN)) {
if (result.contains(expect.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -284,26 +284,26 @@ public class WebCaseExecution extends TestCaseExecution {
Pattern pattern = Pattern.compile(expect.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(result);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
// 精确匹配预期结果模式
else {
if (expect.equals(result)) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
LogUtil.APP.info("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"");
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"");
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@ -313,15 +313,11 @@ public class WebCaseExecution extends TestCaseExecution {
casenote = (null != result) ? result : "";
setresult = 2;
BaseWebDrive.webScreenShot(driver, imagname);
LogUtil.APP.error("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
return setresult;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -6,6 +6,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseSteps;
/**
@ -45,7 +46,7 @@ public class WebDriverAnalyticCase {
params.put("property", property.trim().toLowerCase());
//set属性值
params.put("property_value", propertyValue.trim());
luckyclient.publicclass.LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+propertyValue.trim());
LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+propertyValue.trim());
}
//set操作方法
params.put("operation", step.getStepOperation().toLowerCase());
@ -53,7 +54,7 @@ public class WebDriverAnalyticCase {
//set属性值
params.put("operation_value", step.getStepParameters());
}
luckyclient.publicclass.LogUtil.APP.info("对象操作解析结果operation:"+step.getStepOperation().toLowerCase()+"; operation_value:"+step.getStepParameters());
LogUtil.APP.info("对象操作解析结果operation:"+step.getStepOperation().toLowerCase()+"; operation_value:"+step.getStepParameters());
//获取预期结果字符串
resultstr = step.getExpectedResult();
@ -70,19 +71,18 @@ public class WebDriverAnalyticCase {
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
}
params.put("ExpectedResults", expectedResults);
luckyclient.publicclass.LogUtil.APP.info("预期结果解析ExpectedResults:"+expectedResults);
LogUtil.APP.info("预期结果解析ExpectedResults:"+expectedResults);
}
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.APP.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!");
LogUtil.APP.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!",e);
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
}
luckyclient.publicclass.LogUtil.APP.error(e,e);
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
return params;
}

View File

@ -9,6 +9,7 @@ import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.WebDriverInitialization;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.ProjectCase;
import luckyclient.serverapi.entity.ProjectCaseParams;
@ -36,7 +37,7 @@ public class WebOneCaseExecute{
try {
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
} catch (IOException e1) {
luckyclient.publicclass.LogUtil.APP.error("初始化WebDriver出错", e1);
LogUtil.APP.error("初始化WebDriver出错", e1);
e1.printStackTrace();
}
LogOperation caselog = new LogOperation();
@ -45,13 +46,13 @@ public class WebOneCaseExecute{
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List<ProjectCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【"+testcase.getCaseSign()+"】......");
LogUtil.APP.info("开始执行用例:【"+testcase.getCaseSign()+"】......");
try {
List<ProjectCaseSteps> steps=GetServerAPI.getStepsbycaseid(testcase.getCaseId());
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【"+testcase.getCaseSign()+"】执行完成......进入下一条");
LogUtil.APP.info("当前用例:【"+testcase.getCaseSign()+"】执行完成......进入下一条");
} catch (InterruptedException e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
LogUtil.APP.error("用户执行过程中抛出异常!", e);
e.printStackTrace();
}
LogOperation.updateTaskExecuteData(taskid, 0);

View File

@ -1,6 +1,7 @@
package luckyclient.caserun.publicdispose;
import luckyclient.driven.SubString;
import luckyclient.publicclass.LogUtil;
/**
* 动作关键字处理
@ -21,10 +22,10 @@ public class ActionManageForSteps {
* @return
*/
public static String actionManage(String stepsaction,String testresult){
luckyclient.publicclass.LogUtil.APP.info("测试结果是:" + testresult);
luckyclient.publicclass.LogUtil.APP.info("现在进入到Action(动作)处理......ACTION值"+stepsaction);
LogUtil.APP.info("测试结果是:" + testresult);
LogUtil.APP.info("现在进入到Action(动作)处理......ACTION值"+stepsaction);
if(null==stepsaction||"".equals(stepsaction.trim())){
luckyclient.publicclass.LogUtil.APP.info("Action(动作)无需处理......");
LogUtil.APP.info("Action(动作)无需处理......");
return testresult;
}
stepsaction=stepsaction.toLowerCase().trim();
@ -52,7 +53,7 @@ public class ActionManageForSteps {
// 获取步骤间等待时间
int time=Integer.parseInt(actionorder.substring(0, actionorder.lastIndexOf("#wait")));
if (time > 0) {
luckyclient.publicclass.LogUtil.APP.info("Action(Wait):线程等待"+time+"秒...");
LogUtil.APP.info("Action(Wait):线程等待"+time+"秒...");
Thread.sleep(time * 1000);
}
} catch (InterruptedException e) {
@ -60,7 +61,7 @@ public class ActionManageForSteps {
e.printStackTrace();
}
}else{
luckyclient.publicclass.LogUtil.APP.error("使用等待关键字的参数不是整数,直接跳过此动作,请检查!");
LogUtil.APP.warn("使用等待关键字的参数不是整数,直接跳过此动作,请检查!");
}
}else if(actionorder.endsWith("#getjv")){
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#getjv"));
@ -74,7 +75,7 @@ public class ActionManageForSteps {
key=actionparams;
testresult=SubString.getJsonValue(testresult, key, index);
}
luckyclient.publicclass.LogUtil.APP.info("Action(getJV):获取JSON字符串指定Key的值是"+testresult);
LogUtil.APP.info("Action(getJV):获取JSON字符串指定Key的值是"+testresult);
}else if(actionorder.endsWith("#subcentrestr")){
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#subcentrestr"));
String startstr="";
@ -83,10 +84,10 @@ public class ActionManageForSteps {
startstr=actionparams.substring(actionparams.indexOf("[")+1, actionparams.indexOf("]"));
endstr=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
testresult=SubString.subCentreStr(testresult, startstr, endstr);
luckyclient.publicclass.LogUtil.APP.info("Action(subCentreStr):截取测试结果指定开始及结束位置字符串:"+testresult);
LogUtil.APP.info("Action(subCentreStr):截取测试结果指定开始及结束位置字符串:"+testresult);
}else{
testresult="步骤动作subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionorder;
luckyclient.publicclass.LogUtil.APP.error("步骤动作subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionorder);
LogUtil.APP.warn("步骤动作subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionorder);
}
}else if(actionorder.endsWith("#subcentrenum")){
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#subcentrenum"));
@ -96,10 +97,10 @@ public class ActionManageForSteps {
startnum=actionparams.substring(actionparams.indexOf("[")+1, actionparams.indexOf("]"));
endnum=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
testresult=SubString.subCentreNum(testresult, startnum, endnum);
luckyclient.publicclass.LogUtil.APP.info("Action(subCentreNum):截取测试结果指定开始及结束位置字符串:"+testresult);
LogUtil.APP.info("Action(subCentreNum):截取测试结果指定开始及结束位置字符串:"+testresult);
}else{
testresult="步骤动作subCentreNum 必须是[\"开始字符\"][\"结束字符\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionorder;
luckyclient.publicclass.LogUtil.APP.error("步骤动作subCentreNum 必须是[\"开始位置(整数)\"][\"结束位置(整数)\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionorder);
LogUtil.APP.warn("步骤动作subCentreNum 必须是[\"开始位置(整数)\"][\"结束位置(整数)\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionorder);
}
}else if(actionorder.endsWith("#substrrgex")){
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#substrrgex"));
@ -113,15 +114,15 @@ public class ActionManageForSteps {
key=actionparams;
testresult=SubString.subStrRgex(testresult, key, index);
}
luckyclient.publicclass.LogUtil.APP.info("Action(subStrRgex):获取JSON字符串指定Key的值是"+testresult);
LogUtil.APP.info("Action(subStrRgex):获取JSON字符串指定Key的值是"+testresult);
}else{
testresult="未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionorder;
luckyclient.publicclass.LogUtil.APP.error("未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionorder);
LogUtil.APP.warn("未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionorder);
}
return testresult;
}catch(Exception e){
testresult="处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionorder;
luckyclient.publicclass.LogUtil.APP.error("处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionorder);
LogUtil.APP.error("处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionorder);
return testresult;
}
}

View File

@ -18,6 +18,8 @@ import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import luckyclient.publicclass.LogUtil;
/**
* 对参数替换进行处理
* =================================================================
@ -49,7 +51,7 @@ public class ChangString {
// 如果存在传参进行处理
if (varcount > 0) {
luckyclient.publicclass.LogUtil.APP.info("" + changname + "" + str + "】中找到" + varcount + "个可替换参数");
LogUtil.APP.info("" + changname + "" + str + "】中找到" + varcount + "个可替换参数");
int changcount = 0;
// 准备将HASHMAP换成LINKMAP对KEY进行排序解决要先替换最长KEY的问题
@ -80,7 +82,7 @@ public class ChangString {
// "\\\\&#39;"));
int viewcount = counter(str, "@" + entry.getKey());
str = str.replace("@" + entry.getKey(), entry.getValue());
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("" + changname + "引用变量【@" + entry.getKey() + "】替换成值【" + entry.getValue() + "");
str = str.replace("////CHANG////", "@@" + entry.getKey());
changcount = changcount + viewcount;
@ -88,7 +90,7 @@ public class ChangString {
}
if (varcount != changcount) {
luckyclient.publicclass.LogUtil.APP.error(changname + "有引用变量未在参数列中找到,请检查!处理结果【" + str + "");
LogUtil.APP.warn(changname + "有引用变量未在参数列中找到,请检查!处理结果【" + str + "");
}
}
str = str.replace("@@", "@");
@ -218,10 +220,10 @@ public class ChangString {
if(entry.getValue() instanceof List){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始String值"+entry.getValue()+"");
LogUtil.APP.info("对象原始String值"+entry.getValue()+"");
JSONArray jsonarr = JSONArray.parseArray(value);
entry.setValue(jsonarr);
luckyclient.publicclass.LogUtil.APP.info("对象替换后String值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后String值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -236,10 +238,10 @@ public class ChangString {
}catch(JSONException jsone){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始List值"+entry.getValue()+"");
LogUtil.APP.info("对象原始List值"+entry.getValue()+"");
JSONArray jsonarr = JSONArray.parseArray(value);
entry.setValue(jsonarr);
luckyclient.publicclass.LogUtil.APP.info("对象替换后List值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后List值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -253,9 +255,9 @@ public class ChangString {
if(entry.getValue() instanceof String){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始String值"+entry.getValue()+"");
LogUtil.APP.info("对象原始String值"+entry.getValue()+"");
entry.setValue(value);
luckyclient.publicclass.LogUtil.APP.info("对象替换后String值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后String值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -265,9 +267,9 @@ public class ChangString {
if(entry.getValue() instanceof Integer){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始Integer值"+entry.getValue()+"");
LogUtil.APP.info("对象原始Integer值"+entry.getValue()+"");
entry.setValue(Integer.valueOf(value));
luckyclient.publicclass.LogUtil.APP.info("对象替换后Integer值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后Integer值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -277,9 +279,9 @@ public class ChangString {
if(entry.getValue() instanceof Long){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始Long值"+entry.getValue()+"");
LogUtil.APP.info("对象原始Long值"+entry.getValue()+"");
entry.setValue(Long.valueOf(value));
luckyclient.publicclass.LogUtil.APP.info("对象替换后Long值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后Long值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -289,10 +291,10 @@ public class ChangString {
if(entry.getValue() instanceof BigDecimal){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始BigDecimal值"+entry.getValue()+"");
LogUtil.APP.info("对象原始BigDecimal值"+entry.getValue()+"");
BigDecimal bd = new BigDecimal(value);
entry.setValue(bd);
luckyclient.publicclass.LogUtil.APP.info("对象替换后BigDecimal值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后BigDecimal值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -302,9 +304,9 @@ public class ChangString {
if(entry.getValue() instanceof Boolean){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
luckyclient.publicclass.LogUtil.APP.info("对象原始Boolean值"+entry.getValue()+"");
LogUtil.APP.info("对象原始Boolean值"+entry.getValue()+"");
entry.setValue(Boolean.valueOf(value));
luckyclient.publicclass.LogUtil.APP.info("对象替换后Boolean值"+entry.getValue()+"");
LogUtil.APP.info("对象替换后Boolean值"+entry.getValue()+"");
BCHANG=true;
}
COUNTER++;
@ -324,10 +326,10 @@ public class ChangString {
*/
public static Map<String, String> changjson(String json, String key, String value,int index) {
json=json.trim();
luckyclient.publicclass.LogUtil.APP.info("原始JSON"+json+"");
luckyclient.publicclass.LogUtil.APP.info("待替换JSON KEY"+key+"");
luckyclient.publicclass.LogUtil.APP.info("待替换JSON VALUE"+value+"");
luckyclient.publicclass.LogUtil.APP.info("待替换JSON KEY序号"+index+"");
LogUtil.APP.info("原始JSON"+json+"");
LogUtil.APP.info("待替换JSON KEY"+key+"");
LogUtil.APP.info("待替换JSON VALUE"+value+"");
LogUtil.APP.info("待替换JSON KEY序号"+index+"");
Map<String, String> map = new HashMap<String, String>(0);
map.put("json", json);
map.put("boolean", BCHANG.toString().toLowerCase());
@ -337,12 +339,12 @@ public class ChangString {
JSONObject jsonStr = JSONObject.parseObject(json);
jsonStr=parseJsonString(json,key,value,index);
if (BCHANG) {
luckyclient.publicclass.LogUtil.APP
LogUtil.APP
.info("JSON字符串替换成功新JSON:【" + jsonStr.toJSONString() + "");
}
map.put("json", jsonStr.toJSONString());
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("格式化成JSON异常请检查参数" + json, e);
LogUtil.APP.error("格式化成JSON异常请检查参数" + json, e);
return map;
}
} else if (json.startsWith("[") && json.endsWith("]")) {
@ -354,7 +356,7 @@ public class ChangString {
jsonStr=parseJsonString(jsonStr.toJSONString(),key,value,index);
if(BCHANG){
jsonarr.set(i, jsonStr);
luckyclient.publicclass.LogUtil.APP.info(
LogUtil.APP.info(
"JSONARRAY字符串替换成功新JSONARRAY:【" + jsonarr.toJSONString() + "");
break;
}
@ -362,7 +364,7 @@ public class ChangString {
map.put("json", jsonarr.toJSONString());
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("格式化成JSONArray异常请检查参数" + json, e);
LogUtil.APP.error("格式化成JSONArray异常请检查参数" + json, e);
return map;
}
}

View File

@ -8,6 +8,8 @@ import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import luckyclient.publicclass.LogUtil;
/**
* ÔÄÚÖòÎÊý½øÐд¦Àí
* =================================================================
@ -53,15 +55,15 @@ public class ParamsManageForSteps {
Random random = new Random();
String replacement = String.valueOf(random.nextInt(endnum - startnum + 1) + startnum);
params = m.replaceFirst(replacement);
luckyclient.publicclass.LogUtil.APP.info("Params(" + matcherstr + "):替换成随机数后,字符串:" + params);
LogUtil.APP.info("Params(" + matcherstr + "):替换成随机数后,字符串:" + params);
m = pattern.matcher(params);
}
return params;
} catch (IllegalArgumentException iae) {
luckyclient.publicclass.LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查数字区间是否正常!");
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查数字区间是否正常!");
return params;
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
return params;
}
}
@ -90,18 +92,18 @@ public class ParamsManageForSteps {
matcherstr=df.format(new Date());
}
} catch (IllegalArgumentException iae) {
luckyclient.publicclass.LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
matcherstr=df.format(new Date());
} finally {
params = m.replaceFirst(matcherstr);
luckyclient.publicclass.LogUtil.APP.info("Params(" + matcherstr + "):替换成随机数后,字符串:" + params);
LogUtil.APP.info("Params(" + matcherstr + "):替换成随机数后,字符串:" + params);
m = pattern.matcher(params);
}
}
return params;
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
return params;
}
}

View File

@ -3,6 +3,7 @@ package luckyclient.dblog;
import java.util.Properties;
import luckyclient.publicclass.DBOperation;
import luckyclient.publicclass.SysConfig;
/**
* =================================================================
@ -30,7 +31,7 @@ public class DbLink {
*
*/
public static DBOperation dbLogLink(){
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
Properties properties = SysConfig.getConfiguration();
String urlBase = "jdbc:mysql://"+properties.getProperty("mysql.db.ip")+":"+properties.getProperty("mysql.db.port")
+"/"+properties.getProperty("mysql.db.dbname")+"?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false";
String userNameBase = properties.getProperty("mysql.db.username");

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.alibaba.fastjson.JSONObject;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.api.PostServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
@ -49,8 +50,8 @@ public class LogOperation {
String imgname) {
if (0 == exetype) {
if (logDetail.length()>5000) {
luckyclient.publicclass.LogUtil.APP.info("日志明细超过5000字符无法进入数据库存储进行日志明细打印...");
luckyclient.publicclass.LogUtil.APP.info(""+logStep+"步,日志级别"+logGrade+",日志明细【"+logGrade+"】...");
LogUtil.APP.info("日志明细超过5000字符无法进入数据库存储进行日志明细打印...");
LogUtil.APP.info(""+logStep+"步,日志级别"+logGrade+",日志明细【"+logGrade+"】...");
logDetail="日志明细超过5000字符无法存入数据库已在LOG4J日志中打印请前往查看...";
}

View File

@ -1,6 +1,7 @@
package luckyclient.jenkinsapi;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
@ -24,7 +25,7 @@ public class BuildingInitialization {
String result = JenkinsBuilding.buildingResult(buildname[i]);
if(result.indexOf("alt=\"Failed\"")>-1){
buildresult = "项目"+buildname[i]+"构建失败,自动化测试退出!";
luckyclient.publicclass.LogUtil.APP.error("项目"+buildname[i]+"构建失败,自动化测试退出!");
LogUtil.APP.warn("项目"+buildname[i]+"构建失败,自动化测试退出!");
break;
}else if(result.indexOf("alt=\"Success\"")>-1){
k++;
@ -33,7 +34,7 @@ public class BuildingInitialization {
if(buildresult.indexOf("Status:true")<=-1){
break;
}
luckyclient.publicclass.LogUtil.APP.info("正在检查构建中的项目(每6秒检查一次)。。。需要构建项目"+buildname.length+"个,目前成功"+k+"");
LogUtil.APP.info("正在检查构建中的项目(每6秒检查一次)。。。需要构建项目"+buildname.length+"个,目前成功"+k+"");
if(k==buildname.length){
break;
}
@ -48,7 +49,7 @@ public class BuildingInitialization {
String[] buildurl = LogOperation.getBuildName(tastid);
if(buildurl!=null){
luckyclient.publicclass.LogUtil.APP.info("准备将配置的测试项目进行构建!请稍等。。。。");
LogUtil.APP.info("准备将配置的测试项目进行构建!请稍等。。。。");
for(int i=0;i<buildurl.length;i++){
JenkinsBuilding.sendBuilding(buildurl[i]);
}
@ -56,11 +57,10 @@ public class BuildingInitialization {
Thread.sleep(10000);
result = booleanBuildingOver(buildurl);
}else{
luckyclient.publicclass.LogUtil.APP.info("当前任务没有找到需要构建的项目!");
LogUtil.APP.info("当前任务没有找到需要构建的项目!");
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.APP.error("项目构建过程中出现异常");
luckyclient.publicclass.LogUtil.APP.error(e);
LogUtil.APP.error("项目构建过程中出现异常",e);
result = "项目构建过程中出现异常";
return result;
}

View File

@ -7,6 +7,8 @@ import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -46,7 +48,7 @@ public class JenkinsBuilding {
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
luckyclient.publicclass.LogUtil.APP.info(key + "--->" + map.get(key));
LogUtil.APP.info(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
@ -56,7 +58,7 @@ public class JenkinsBuilding {
result += line;
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("发送构建请求(GET)时出现异常!", e);
LogUtil.APP.error("发送构建请求(GET)时出现异常!", e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
@ -102,7 +104,7 @@ public class JenkinsBuilding {
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
luckyclient.publicclass.LogUtil.APP.info(key + "--->" + map.get(key));
LogUtil.APP.info(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
@ -112,7 +114,7 @@ public class JenkinsBuilding {
result += line;
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("发送构建请求(GET)时出现异常!", e);
LogUtil.APP.error("发送构建请求(GET)时出现异常!", e);
e.printStackTrace();
}
// 使用finally块来关闭输入流

View File

@ -1,6 +1,7 @@
package luckyclient.jenkinsapi;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
@ -20,22 +21,21 @@ public class RestartServerInitialization {
try{
String[] command = LogOperation.getRestartComm(tastid);
if(command!=null){
luckyclient.publicclass.LogUtil.APP.info("准备重启指定的TOMCAT请稍等。。。参数个数"+command.length);
LogUtil.APP.info("准备重启指定的TOMCAT请稍等。。。参数个数"+command.length);
if(command.length==5){
luckyclient.publicclass.LogUtil.APP.info("开始调用重启TOMCAT方法。。。参数0"+command[0]+" 参数1"+command[1]
LogUtil.APP.info("开始调用重启TOMCAT方法。。。参数0"+command[0]+" 参数1"+command[1]
+" 参数2"+command[2]+" 参数3"+command[3]+" 参数4"+command[4]);
result = RmtShellExecutor.sshShell(command[0], command[1], command[2], Integer.valueOf(command[3]), command[4]);
}else{
luckyclient.publicclass.LogUtil.APP.error("重启TOMCAT命令行参数出现异常请检查配置信息");
LogUtil.APP.warn("重启TOMCAT命令行参数出现异常请检查配置信息");
result = "重启TOMCAT命令行参数出现异常请检查配置信息";
}
}else{
result = "Status:true"+" 当前任务没有找到需要重启的TOMCAT命令";
luckyclient.publicclass.LogUtil.APP.info("当前任务没有指定需要重启TOMCAT");
LogUtil.APP.info("当前任务没有指定需要重启TOMCAT");
}
}catch(Throwable e){
luckyclient.publicclass.LogUtil.APP.error("重启TOMCAT过程中出现异常");
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(),e);
LogUtil.APP.error("重启TOMCAT过程中出现异常",e);
result = "重启TOMCAT过程中出现异常";
return result;
}

View File

@ -6,6 +6,8 @@ import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import luckyclient.publicclass.LogUtil;
/**
* 远程执行shell脚本类
* @author l
@ -31,7 +33,7 @@ public class RmtShellExecutor {
String result = "Status:true"+" 重启命令执行成功!";
try {
JSch jsch = new JSch();
luckyclient.publicclass.LogUtil.APP.info("进入到重启TOMCAT方法。。。");
LogUtil.APP.info("进入到重启TOMCAT方法。。。");
//设置密钥和密码
if (privateKey != null && !"".equals(privateKey)) {
if (passphrase != null && "".equals(passphrase)) {
@ -45,18 +47,18 @@ public class RmtShellExecutor {
if(port <=0){
//连接服务器采用默认端口
luckyclient.publicclass.LogUtil.APP.info("设置重启TOMCAT服务器IP及默认端口。。。");
LogUtil.APP.info("设置重启TOMCAT服务器IP及默认端口。。。");
session = jsch.getSession(user, ip);
}else{
//采用指定的端口连接服务器
luckyclient.publicclass.LogUtil.APP.info("设置重启TOMCAT服务器IP及端口。。。");
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口。。。");
session = jsch.getSession(user, ip ,port);
luckyclient.publicclass.LogUtil.APP.info("设置重启TOMCAT服务器IP及端口完成!");
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口完成!");
}
//如果服务器连接不上则抛出异常
if (session == null) {
luckyclient.publicclass.LogUtil.APP.error("重启TOMCAT过程中链接服务器session is null");
LogUtil.APP.warn("重启TOMCAT过程中链接服务器session is null");
result = "重启TOMCAT过程中链接服务器session is null";
throw new Exception("session is null");
}
@ -76,7 +78,7 @@ public class RmtShellExecutor {
OutputStream outstream = channel.getOutputStream();
//发送需要执行的SHELL命令需要用\n结尾表示回车
luckyclient.publicclass.LogUtil.APP.info("准备往重启TOMCAT服务器发送命令!");
LogUtil.APP.info("准备往重启TOMCAT服务器发送命令!");
String shellCommand = command+" \n";
outstream.write(shellCommand.getBytes());
outstream.flush();
@ -87,20 +89,20 @@ public class RmtShellExecutor {
byte[] data = new byte[instream.available()];
int nLen = instream.read(data);
if (nLen < 0) {
luckyclient.publicclass.LogUtil.APP.error("重启TOMCAT过程中获取命令执行结果出现异常");
LogUtil.APP.warn("重启TOMCAT过程中获取命令执行结果出现异常");
result = "重启TOMCAT过程中获取命令执行结果出现异常";
throw new Exception("network error.");
}
//转换输出结果并打印出来
String temp = new String(data, 0, nLen,"iso8859-1");
luckyclient.publicclass.LogUtil.APP.info("开始打印重启TOMCAT命令执行结果"+temp);
LogUtil.APP.info("开始打印重启TOMCAT命令执行结果"+temp);
}
outstream.close();
instream.close();
} catch (Exception e) {
result = "重启TOMCAT过程中出现异常";
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
return result;
} finally {
if(null!=session){

View File

@ -8,6 +8,7 @@ import java.util.Properties;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import luckyclient.publicclass.SysConfig;
/**
* 基于Freemarker模板技术的邮件模板服务
@ -15,7 +16,7 @@ import freemarker.template.Template;
* @author Administrator
*/
public class FreemarkerEmailTemplate {
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
Properties properties = SysConfig.getConfiguration();
/**
* 邮件模板的存放位置
*/

View File

@ -4,6 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import luckyclient.publicclass.LogUtil;
import luckyclient.publicclass.SysConfig;
import luckyclient.publicclass.remoterinterface.HttpClientHelper;
import luckyclient.serverapi.entity.ProjectProtocolTemplate;
@ -34,9 +36,9 @@ public class HtmlMail {
parameters.put("jobname", jobname);
try {
Map<String, String> headmsg = new HashMap<>(0);
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
Properties properties = SysConfig.getConfiguration();
if ("true".equals(properties.getProperty("task.push.switch").toLowerCase())) {
luckyclient.publicclass.LogUtil.APP.info("开始向第三方平台推送任务执行情况....");
LogUtil.APP.info("开始向第三方平台推送任务执行情况....");
Map<String, Object> pushparameters = new HashMap<>(0);
pushparameters.put("buildstatus", buildstatus);
pushparameters.put("restartstatus", restartstatus);
@ -56,7 +58,7 @@ public class HtmlMail {
HttpClientHelper.httpClientPostJson(pushurl, pushparameters, headmsg,ppt);
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("向第三方平台推送任务执行情况出现异常,请检查!", e);
LogUtil.APP.error("向第三方平台推送任务执行情况出现异常,请检查!", e);
e.printStackTrace();
return fet.getText("task-body", parameters);
}

View File

@ -3,6 +3,8 @@ package luckyclient.mail;
import java.util.Properties;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.LogUtil;
import luckyclient.publicclass.SysConfig;
import luckyclient.serverapi.entity.TaskScheduling;
/**
@ -43,13 +45,13 @@ public class MailSendInitialization {
}
}
if (!isSend) {
luckyclient.publicclass.LogUtil.APP.info("当前任务不需要发送邮件通知!");
LogUtil.APP.info("当前任务不需要发送邮件通知!");
return;
}
String[] addresses = LogOperation.getEmailAddress(taskid);
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
Properties properties = SysConfig.getConfiguration();
if (addresses != null) {
luckyclient.publicclass.LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等。。。。");
LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等。。。。");
//这个类主要是设置邮件
MailSenderInfo mailInfo = new MailSenderInfo();
//这个类主要来发送邮件
@ -75,12 +77,12 @@ public class MailSendInitialization {
}
String addressesmail = stringBuilder.toString();
if (sms.sendHtmlMail(mailInfo)) {
luckyclient.publicclass.LogUtil.APP.info("" + addressesmail + "的测试结果通知邮件发送完成!");
LogUtil.APP.info("" + addressesmail + "的测试结果通知邮件发送完成!");
} else {
luckyclient.publicclass.LogUtil.APP.error("" + addressesmail + "的测试结果通知邮件发送失败!");
LogUtil.APP.warn("" + addressesmail + "的测试结果通知邮件发送失败!");
}
} else {
luckyclient.publicclass.LogUtil.APP.info("当前任务不需要发送邮件通知!");
LogUtil.APP.info("当前任务不需要发送邮件通知!");
}
}

View File

@ -1,10 +1,12 @@
package luckyclient.mail;
import com.sun.mail.util.MailSSLSocketFactory;
import java.security.GeneralSecurityException;
import java.util.Properties;
import com.sun.mail.util.MailSSLSocketFactory;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -76,7 +78,7 @@ public class MailSenderInfo {
p.put("mail.smtp.ssl.socketFactory", sf);
}
} catch (GeneralSecurityException e) {
luckyclient.publicclass.LogUtil.APP.error("获得邮件会话属性失败或异常: " + e.getMessage());
LogUtil.APP.error("获得邮件会话属性失败或异常: " + e.getMessage());
return null;
}
return p;

View File

@ -15,6 +15,8 @@ import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import luckyclient.publicclass.LogUtil;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -119,7 +121,7 @@ public class SimpleMailSender {
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error(ex);
LogUtil.APP.error("邮件发送异常", ex);
}
return false;
}

View File

@ -47,12 +47,12 @@ public class InvokeMethod {
if (steptype == 2) {
if(functionname.toLowerCase().endsWith(".py")){
//调用Python脚本
luckyclient.publicclass.LogUtil.APP.info("准备开始调用Python脚本......");
LogUtil.APP.info("准备开始调用Python脚本......");
result = callPy(packagename, functionname, getParameterValues);
}else{
//调用JAVA
// 调用非静态方法用到
luckyclient.publicclass.LogUtil.APP.info("准备开始调用JAVA驱动桩程序......");
LogUtil.APP.info("准备开始调用JAVA驱动桩程序......");
Object server = Class.forName(packagename).newInstance();
@SuppressWarnings("rawtypes")
Class[] getParameterTypes = null;
@ -78,16 +78,16 @@ public class InvokeMethod {
} else if (steptype == 0) {
if(null==extend||"".equals(extend)||!extend.contains("")){
result = "您当前步骤是HTTP请求请确认是否没有配置对应的HTTP协议模板...";
luckyclient.publicclass.LogUtil.APP.error("您当前步骤是HTTP请求请确认是否没有配置对应的HTTP协议模板...");
LogUtil.APP.warn("您当前步骤是HTTP请求请确认是否没有配置对应的HTTP协议模板...");
return result;
}
String templateidstr = extend.substring(1, extend.indexOf(""));
String templatenamestr = extend.substring(extend.indexOf("") + 1);
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID:【" + templateidstr + "】发送HTTP请求");
LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID:【" + templateidstr + "】发送HTTP请求");
ProjectProtocolTemplate ppt = GetServerAPI.clientGetProjectProtocolTemplateByTemplateId(Integer.valueOf(templateidstr));
if (null == ppt) {
luckyclient.publicclass.LogUtil.APP.error("协议模板为空,请检查用例使用的协议模板是否已经删除!");
LogUtil.APP.warn("协议模板为空,请检查用例使用的协议模板是否已经删除!");
return "协议模板为空,请确认用例使用的模板是否已经删除!";
}
@ -134,9 +134,9 @@ public class InvokeMethod {
if (key.contains("[") && key.endsWith("]")) {
index = Integer.valueOf(key.substring(key.lastIndexOf("[") + 1, key.lastIndexOf("]")));
key = key.substring(0, key.lastIndexOf("["));
luckyclient.publicclass.LogUtil.APP.info("准备替换JSON对象中的参数值替换指定第" + index + "个参数...");
LogUtil.APP.info("准备替换JSON对象中的参数值替换指定第" + index + "个参数...");
} else {
luckyclient.publicclass.LogUtil.APP.info("准备替换JSON对象中的参数值未检测到指定参数名序号默认替换第1个参数...");
LogUtil.APP.info("准备替换JSON对象中的参数值未检测到指定参数名序号默认替换第1个参数...");
}
if(ptp.getParamValue().contains("\""+key+"\":")){
@ -145,34 +145,34 @@ public class InvokeMethod {
ptp.setParamValue(map.get("json"));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("替换参数"+key+"完成...");
LogUtil.APP.info("替换参数"+key+"完成...");
break;
}
}else if(ptp.getParamValue().contains(key)){
ptp.setParamValue(ptp.getParamValue().replace(key, value));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParamValue()+"】中直接把【"+key+"】替换成【"+value+"】...");
LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParamValue()+"】中直接把【"+key+"】替换成【"+value+"】...");
break;
}else{
luckyclient.publicclass.LogUtil.APP.error("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
LogUtil.APP.warn("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
}
}else{
if (ptp.getParamName().equals(key)) {
ptp.setParamValue(value);
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"");
LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"");
break;
}
}
}
if(replaceflag==0){
luckyclient.publicclass.LogUtil.APP.error("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
LogUtil.APP.warn("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
+ "设置请求参数失败,请检查协议模板中此参数是否存在。");
}
}else{
luckyclient.publicclass.LogUtil.APP.error("替换模板或是头域参数失败,原因是因为没有检测到#"
LogUtil.APP.warn("替换模板或是头域参数失败,原因是因为没有检测到#"
+ "注意HTTP请求替换参数格式是【headmsg(头域名#头域值)|参数名#参数值|参数名2#参数值2】");
}
@ -191,26 +191,26 @@ public class InvokeMethod {
if (ptp.getParamType() == 1) {
JSONObject json = JSONObject.parseObject(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), json);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONObject类型参数值:【" + json.toString() + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONObject类型参数值:【" + json.toString() + "");
} else if (ptp.getParamType() == 2) {
JSONArray jarr = JSONArray.parseArray(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), jarr);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONArray类型参数值:【" + jarr.toString() + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONArray类型参数值:【" + jarr.toString() + "");
} else if (ptp.getParamType() == 3) {
File file = new File(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), file);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 File类型参数值:【" + file.getAbsolutePath() + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 File类型参数值:【" + file.getAbsolutePath() + "");
} else if (ptp.getParamType() == 4) {
Double dp = Double.valueOf(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), dp);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 数字类型参数值:【" + tempparam + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 数字类型参数值:【" + tempparam + "");
} else if (ptp.getParamType() == 5) {
Boolean bn = Boolean.valueOf(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), bn);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 Boolean类型参数值:【" + bn + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 Boolean类型参数值:【" + bn + "");
} else {
params.put(ptp.getParamName().replace("&quot;", "\""), ptp.getParamValue().replace("&quot;", "\""));
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 String类型参数值:【" + ptp.getParamValue().replace("&quot;", "\"") + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 String类型参数值:【" + ptp.getParamValue().replace("&quot;", "\"") + "");
}
}
@ -240,17 +240,17 @@ public class InvokeMethod {
} else if (functionname.toLowerCase().equals("httpclientget")) {
result = HttpClientHelper.httpClientGet(packagename, params, headmsg, ppt);
} else {
luckyclient.publicclass.LogUtil.APP.error("您的HTTP操作方法异常检测到的操作方法是" + functionname);
LogUtil.APP.warn("您的HTTP操作方法异常检测到的操作方法是" + functionname);
result = "调用异常,请查看错误日志!";
}
} else if (steptype == 4) {
String templateidstr = extend.substring(1, extend.indexOf(""));
String templatenamestr = extend.substring(extend.indexOf("") + 1);
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID:【" + templateidstr + "】 发送SOCKET请求");
LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID:【" + templateidstr + "】 发送SOCKET请求");
ProjectProtocolTemplate ppt = GetServerAPI.clientGetProjectProtocolTemplateByTemplateId(Integer.valueOf(templateidstr));
if (null == ppt) {
luckyclient.publicclass.LogUtil.APP.error("协议模板为空,请检查用例使用的协议模板是否已经删除!");
LogUtil.APP.warn("协议模板为空,请检查用例使用的协议模板是否已经删除!");
return "协议模板为空,请确认用例使用的模板是否已经删除!";
}
@ -295,9 +295,9 @@ public class InvokeMethod {
if (key.indexOf("[") >= 0 && key.endsWith("]")) {
index = Integer.valueOf(key.substring(key.lastIndexOf("[") + 1, key.lastIndexOf("]")));
key = key.substring(0, key.lastIndexOf("["));
luckyclient.publicclass.LogUtil.APP.info("准备替换JSON对象中的参数值未检测到指定参数名序号默认替换第1个参数...");
LogUtil.APP.info("准备替换JSON对象中的参数值未检测到指定参数名序号默认替换第1个参数...");
} else {
luckyclient.publicclass.LogUtil.APP.info("准备替换JSON对象中的参数值替换指定第" + index + "个参数...");
LogUtil.APP.info("准备替换JSON对象中的参数值替换指定第" + index + "个参数...");
}
Map<String,String> map=ChangString.changjson(ptp.getParamValue(), key, value,index);
@ -305,34 +305,34 @@ public class InvokeMethod {
ptp.setParamValue(map.get("json"));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("替换参数"+key+"完成...");
LogUtil.APP.info("替换参数"+key+"完成...");
break;
}
}else if(ptp.getParamValue().indexOf(key)>=0){
ptp.setParamValue(ptp.getParamValue().replace(key, value));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParamValue()+"】中直接把【"+key+"】替换成【"+value+"】...");
LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParamValue()+"】中直接把【"+key+"】替换成【"+value+"】...");
break;
}else{
luckyclient.publicclass.LogUtil.APP.error("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
LogUtil.APP.warn("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
}
}else{
if (ptp.getParamName().equals(key)) {
ptp.setParamValue(value);
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"");
LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"");
break;
}
}
}
if(replaceflag==0){
luckyclient.publicclass.LogUtil.APP.error("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
LogUtil.APP.warn("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
+ "设置请求参数失败,请检查协议模板中此参数是否存在。");
}
}else{
luckyclient.publicclass.LogUtil.APP.error("替换模板或是头域参数失败,原因是因为没有检测到#"
LogUtil.APP.warn("替换模板或是头域参数失败,原因是因为没有检测到#"
+ "注意HTTP请求替换参数格式是【headmsg(头域名#头域值)|参数名#参数值|参数名2#参数值2】");
}
@ -349,26 +349,26 @@ public class InvokeMethod {
if (ptp.getParamType() == 1) {
JSONObject json = JSONObject.parseObject(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), json);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONObject类型参数值:【" + json.toString() + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONObject类型参数值:【" + json.toString() + "");
} else if (ptp.getParamType() == 2) {
JSONArray jarr = JSONArray.parseArray(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), jarr);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONArray类型参数值:【" + jarr.toString() + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONArray类型参数值:【" + jarr.toString() + "");
} else if (ptp.getParamType() == 3) {
File file = new File(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), file);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 File类型参数值:【" + file.getAbsolutePath() + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 File类型参数值:【" + file.getAbsolutePath() + "");
} else if (ptp.getParamType() == 4) {
Double dp = Double.valueOf(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), dp);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 数字类型参数值:【" + tempparam + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 数字类型参数值:【" + tempparam + "");
} else if (ptp.getParamType() == 5) {
Boolean bn = Boolean.valueOf(tempparam);
params.put(ptp.getParamName().replace("&quot;", "\""), bn);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 Boolean类型参数值:【" + bn + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 Boolean类型参数值:【" + bn + "");
} else {
params.put(ptp.getParamName().replace("&quot;", "\""), ptp.getParamValue().replace("&quot;", "\""));
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 String类型参数值:【" + ptp.getParamValue().replace("&quot;", "\"") + "");
LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 String类型参数值:【" + ptp.getParamValue().replace("&quot;", "\"") + "");
}
}
@ -378,12 +378,12 @@ public class InvokeMethod {
} else if (functionname.toLowerCase().equals("socketget")) {
result = HttpClientHelper.sendSocketGet(packagename, params, ppt.getEncoding().toLowerCase(), headmsg);
} else {
luckyclient.publicclass.LogUtil.APP.error("您的SOCKET操作方法异常检测到的操作方法是" + functionname);
LogUtil.APP.warn("您的SOCKET操作方法异常检测到的操作方法是" + functionname);
result = "调用异常,请查看错误日志!";
}
}
} catch (Throwable e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
return "调用异常,请查看错误日志!";
}
return result;
@ -457,7 +457,7 @@ public class InvokeMethod {
args[1]=packagename+File.separator+functionname;
//args[1]="E:\\PycharmProjects\\untitled\\venv\\testaaa.py";
}
luckyclient.publicclass.LogUtil.APP.info("调用Python脚本路径:"+args[1]);
LogUtil.APP.info("调用Python脚本路径:"+args[1]);
for(int i=0;i < params;i++){
args[2+i]=getParameterValues[i].toString();
}
@ -479,16 +479,16 @@ public class InvokeMethod {
// 打印流信息
if(outerrStream.toString().equals("")){
result = outStream.toString().trim();
luckyclient.publicclass.LogUtil.APP.info("成功调用Python脚本返回结果:"+result);
LogUtil.APP.info("成功调用Python脚本返回结果:"+result);
}else{
result = outerrStream.toString().trim();
if(result.indexOf("ModuleNotFoundError")>-1){
luckyclient.publicclass.LogUtil.APP.error("调用Python脚本出现异常有相关Python模块未引用到请在Python脚本中注意设置系统环境路径(例: sys.path.append(\"E:\\PycharmProjects\\untitled\\venv\\Lib\\site-packages\"))"
LogUtil.APP.warn("调用Python脚本出现异常有相关Python模块未引用到请在Python脚本中注意设置系统环境路径(例: sys.path.append(\"E:\\PycharmProjects\\untitled\\venv\\Lib\\site-packages\"))"
+ "详细错误信息:"+result);
}else if(result.indexOf("No such file or directory")>-1){
luckyclient.publicclass.LogUtil.APP.error("调用Python脚本出现异常在指定路径下未找到Python脚本原因有可能是Python脚本路径错误或是传入Python指定参数个数不一致详细错误信息:"+result);
LogUtil.APP.warn("调用Python脚本出现异常在指定路径下未找到Python脚本原因有可能是Python脚本路径错误或是传入Python指定参数个数不一致详细错误信息:"+result);
}else{
luckyclient.publicclass.LogUtil.APP.error("调用Python脚本出现异常错误信息:"+result);
LogUtil.APP.warn("调用Python脚本出现异常错误信息:"+result);
}
}
}

View File

@ -3,8 +3,8 @@ package luckyclient.publicclass;
import java.lang.reflect.Field;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 系统日志记录
@ -14,20 +14,12 @@ import org.apache.commons.logging.LogFactory;
public class LogUtil {
/**
* 记录系统运行日志监控系统运行情况
* 主要使用三种日志级别info,warn,error
* info 记录客户端系统日志监控客户端运行情况
* warn 记录客户端业务上的告警日志
* error 记录客户端在执行过程中抛出的异常以及严重错误
*/
public static final Log APP = LogFactory.getLog("app");
/**
* 记录业务日志监控业务执行情况
*/
public static final Log MSG = LogFactory.getLog("msg");
/**
* 记录系统错误监控程序是否出错
*/
public static final Log ERROR = LogFactory.getLog("error");
public static final Logger APP = LoggerFactory.getLogger("info");
public static StringBuffer getFieldValue(Object bean){
StringBuffer sb = new StringBuffer();
@ -58,7 +50,7 @@ public class LogUtil {
}
}
catch(Exception ex){
LogUtil.ERROR.error(ex,ex);
LogUtil.APP.error("日志异常",ex);
}
return sb;
}

View File

@ -56,6 +56,7 @@ import org.apache.http.ssl.SSLContexts;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.entity.ProjectProtocolTemplate;
/**
@ -86,12 +87,12 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLPost请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLPost请求(必须为key-value)...");
return "协议模板是纯文本无法使用sendHttpURLPost请求(必须为key-value)...";
}else{
for (Entry<String, Object> e : params.entrySet()) {
@ -99,7 +100,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPURLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
LogUtil.APP.info("设置HTTPURLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
}
}
}
@ -120,11 +121,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTPURLPost头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTPURLPost头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -160,14 +161,14 @@ public class HttpClientHelper {
resultBuffer.append("Content-Length=0");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
osw = null;
throw new RuntimeException(e);
} finally {
@ -181,7 +182,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
} finally {
@ -213,11 +214,11 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLPost请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLPost请求(必须为key-value)...");
return "协议模板是纯文本无法使用sendURLPost请求(必须为key-value)...";
}else{
for (Entry<String, Object> e : params.entrySet()) {
@ -225,7 +226,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置URLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
LogUtil.APP.info("设置URLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
}
}
}
@ -245,11 +246,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换URLPost头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换URLPost头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -292,14 +293,14 @@ public class HttpClientHelper {
resultBuffer.append("Content-Length=0");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
osw = null;
throw new RuntimeException(e);
}
@ -308,7 +309,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -327,7 +328,7 @@ public class HttpClientHelper {
*/
public static String sendGetAndSaveFile(String urlParam, Map<String, Object> params, String fileSavePath, Map<String, String> headmsg,ProjectProtocolTemplate ppt) {
// 构建请求参数
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
int timeout=ppt.getTimeout();
int responsehead=ppt.getIsResponseHead();
int responsecode=ppt.getIsResponseCode();
@ -335,14 +336,14 @@ public class HttpClientHelper {
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendGetAndSaveFile请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendGetAndSaveFile请求(必须为key-value)...");
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPSaveFile参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
LogUtil.APP.info("设置HTTPSaveFile参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
@ -362,11 +363,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTPSaveFile头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTPSaveFile头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -394,14 +395,14 @@ public class HttpClientHelper {
os.flush();
return resultBuffer.toString()+"下载文件成功,请前往客户端路径:" + fileSavePath + " 查看附件。";
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
os = null;
throw new RuntimeException(e);
} finally {
@ -415,7 +416,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
} finally {
@ -445,11 +446,11 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLGet请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
@ -457,7 +458,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPURLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
LogUtil.APP.info("设置HTTPURLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
@ -476,11 +477,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTPURLGet头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTPURLGet头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -506,14 +507,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常!响应码:"+con.getResponseCode());
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
} finally {
@ -544,11 +545,11 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLGet请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
@ -556,7 +557,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置URLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
LogUtil.APP.info("设置URLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
@ -579,11 +580,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换URLGet头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换URLGet头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -610,14 +611,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常!");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -645,7 +646,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPost httpPost = new HttpPost(urlParam);
httpPost.setHeader("Content-Type", "application/json");
@ -658,11 +659,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTPPostJson头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTPPostJson头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@ -673,12 +674,12 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.info("参数类型TEXT,设置HTTPPostJson参数信息...【"+params.get("_forTextJson").toString()+"");
LogUtil.APP.info("参数类型TEXT,设置HTTPPostJson参数信息...【"+params.get("_forTextJson").toString()+"");
StringEntity entity = new StringEntity(params.get("_forTextJson").toString(),charset);
httpPost.setEntity(entity);
}else{
String jsonString = JSON.toJSONString(params);
luckyclient.publicclass.LogUtil.APP.info("参数类型FORM,设置HTTPPostJson参数信息...【"+jsonString+"");
LogUtil.APP.info("参数类型FORM,设置HTTPPostJson参数信息...【"+jsonString+"");
StringEntity entity = new StringEntity(jsonString,charset);
httpPost.setEntity(entity);
}
@ -707,14 +708,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -743,7 +744,7 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
HttpPost httpPost = new HttpPost(urlParam);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(timeout)
@ -754,11 +755,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTPClientPost头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTPClientPost头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@ -769,14 +770,14 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPost请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPost请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPost请求(必须为key-value)...";
}else{
//拼接参数
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
for (Map.Entry<String, Object> m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientPost参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
LogUtil.APP.info("设置HTTPClientPost参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps,charset));
}
@ -805,14 +806,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常,响应码:"+response.getStatusLine().getStatusCode());
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -841,7 +842,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPost httpPost = new HttpPost(urlParam);
RequestConfig requestConfig = RequestConfig.custom()
@ -853,11 +854,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换httpClientUploadFile头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换httpClientUploadFile头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@ -868,7 +869,7 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientUploadFile请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientUploadFile请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientUploadFile请求(必须为key-value)...";
}else{
//拼接参数
@ -879,10 +880,10 @@ public class HttpClientHelper {
for (Map.Entry<String, Object> m :params.entrySet()) {
if (m.getValue() instanceof File) {
entityBuilder.addBinaryBody(m.getKey(), (File)m.getValue());
luckyclient.publicclass.LogUtil.APP.info("设置httpClientUploadFile 上传文件参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
LogUtil.APP.info("设置httpClientUploadFile 上传文件参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}else{
entityBuilder.addTextBody(m.getKey(), m.getValue().toString());
luckyclient.publicclass.LogUtil.APP.info("设置httpClientUploadFile参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
LogUtil.APP.info("设置httpClientUploadFile参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
}
HttpEntity reqEntity =entityBuilder.build();
@ -913,14 +914,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常,响应码:"+response.getStatusLine().getStatusCode());
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -948,14 +949,14 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
BufferedReader br = null;
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientGet请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
@ -964,11 +965,11 @@ public class HttpClientHelper {
try {
sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), charset));
} catch (UnsupportedEncodingException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
}
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
LogUtil.APP.info("设置HTTPClientGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
@ -986,11 +987,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTPClientGet头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTPClientGet头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
httpGet.setHeader(key, value);
}else{
httpGet.setHeader(key, value);
@ -1018,14 +1019,14 @@ public class HttpClientHelper {
resultBuffer.append(temp);
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -1045,12 +1046,12 @@ public class HttpClientHelper {
public static String sendSocketPost(String urlParam, Map<String, Object> params, String charset,
Map<String, String> headmsg) {
String result = "";
luckyclient.publicclass.LogUtil.APP.info("设置Socket请求地址:【"+urlParam+"");
LogUtil.APP.info("设置Socket请求地址:【"+urlParam+"");
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketPost请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketPost请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketPost请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
@ -1058,7 +1059,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
@ -1083,11 +1084,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换Socket头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换Socket头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
sb.append(key+": "+value+" \r\n");
}else{
sb.append(key+": "+value+" \r\n");
@ -1118,14 +1119,14 @@ public class HttpClientHelper {
// 读取出响应体数据就是你要的数据
result = readLine(is, contentLength, charset);
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
osw = null;
throw new RuntimeException(e);
} finally {
@ -1133,7 +1134,7 @@ public class HttpClientHelper {
try {
socket.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
socket = null;
throw new RuntimeException(e);
}
@ -1144,7 +1145,7 @@ public class HttpClientHelper {
try {
is.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
is = null;
throw new RuntimeException(e);
} finally {
@ -1153,7 +1154,7 @@ public class HttpClientHelper {
socket.close();
} catch (IOException e) {
socket = null;
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
@ -1173,12 +1174,12 @@ public class HttpClientHelper {
*/
public static String sendSocketGet(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg) {
String result = "";
luckyclient.publicclass.LogUtil.APP.info("设置Socket请求地址:【"+urlParam+"");
LogUtil.APP.info("设置Socket请求地址:【"+urlParam+"");
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketGet请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
@ -1186,7 +1187,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
@ -1212,11 +1213,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换Socket头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换Socket头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
sb.append(key+": "+value+" \r\n");
}else{
sb.append(key+": "+value+" \r\n");
@ -1247,14 +1248,14 @@ public class HttpClientHelper {
// 读取出响应体数据就是你要的数据
result = readLine(is, contentLength, charset);
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
osw = null;
throw new RuntimeException(e);
} finally {
@ -1262,7 +1263,7 @@ public class HttpClientHelper {
try {
socket.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
socket = null;
throw new RuntimeException(e);
}
@ -1273,7 +1274,7 @@ public class HttpClientHelper {
try {
is.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
is = null;
throw new RuntimeException(e);
} finally {
@ -1281,7 +1282,7 @@ public class HttpClientHelper {
try {
socket.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
socket = null;
throw new RuntimeException(e);
}
@ -1343,11 +1344,11 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLDel请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLDel请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLDel请求(必须为key-value)...";
}else{
for (Entry<String, Object> e : params.entrySet()) {
@ -1355,7 +1356,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HttpURLDel参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
LogUtil.APP.info("设置HttpURLDel参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
}
}
}
@ -1375,11 +1376,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
con.setRequestProperty(key,value);
}else{
con.setRequestProperty(key,value);
@ -1412,14 +1413,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
osw = null;
throw new RuntimeException(e);
} finally {
@ -1433,7 +1434,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
} finally {
@ -1468,7 +1469,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPut httpput = new HttpPut(urlParam);
httpput.setHeader("Content-Type", "application/json");
@ -1481,11 +1482,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
httpput.setHeader(key,value);
}else{
httpput.setHeader(key,value);
@ -1496,12 +1497,12 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.info("参数类型TEXT,设置HTTPClientPutJson参数信息...【"+params.get("_forTextJson").toString()+"");
LogUtil.APP.info("参数类型TEXT,设置HTTPClientPutJson参数信息...【"+params.get("_forTextJson").toString()+"");
StringEntity entity = new StringEntity(params.get("_forTextJson").toString(),charset);
httpput.setEntity(entity);
}else{
String jsonString = JSON.toJSONString(params);
luckyclient.publicclass.LogUtil.APP.info("参数类型FORM,设置HTTPClientPutJson参数信息...【"+jsonString+"");
LogUtil.APP.info("参数类型FORM,设置HTTPClientPutJson参数信息...【"+jsonString+"");
StringEntity entity = new StringEntity(jsonString,charset);
httpput.setEntity(entity);
}
@ -1531,14 +1532,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -1566,7 +1567,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPut httpput = new HttpPut(urlParam);
RequestConfig requestConfig = RequestConfig.custom()
@ -1578,11 +1579,11 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
luckyclient.publicclass.LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"");
LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"");
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
luckyclient.publicclass.LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
httpput.setHeader(key,value);
}else{
httpput.setHeader(key,value);
@ -1593,14 +1594,14 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPut请求(必须为key-value)...");
LogUtil.APP.warn("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPut请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPut请求(必须为key-value)...";
}else{
//拼接参数
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
for (Map.Entry<String, Object> m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
luckyclient.publicclass.LogUtil.APP.info("开始设置HTTPClientPut参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
LogUtil.APP.info("开始设置HTTPClientPut参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
httpput.setEntity(new UrlEncodedFormEntity(nvps,charset));
}
@ -1630,14 +1631,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}
@ -1656,12 +1657,12 @@ public class HttpClientHelper {
SSLContext sslContext = null;
FileInputStream instream = null;
KeyStore trustStore = null;
luckyclient.publicclass.LogUtil.APP.info("证书路径:"+keyStorePath+" 密钥:"+keyStorepass);
LogUtil.APP.info("证书路径:"+keyStorePath+" 密钥:"+keyStorepass);
try {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
luckyclient.publicclass.LogUtil.APP.info("开始读取证书文件流...");
LogUtil.APP.info("开始读取证书文件流...");
instream = new FileInputStream(new File(keyStorePath));
luckyclient.publicclass.LogUtil.APP.info("开始设置证书以及密钥...");
LogUtil.APP.info("开始设置证书以及密钥...");
trustStore.load(instream, keyStorepass.toCharArray());
// 相信自己的CA和所有自签名的证书
sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();
@ -1673,12 +1674,12 @@ public class HttpClientHelper {
sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tms, new java.security.SecureRandom());
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
} finally {
try {
instream.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
}
}
return sslContext;
@ -1701,12 +1702,12 @@ public class HttpClientHelper {
//采用绕过验证的方式处理https请求
SSLContext sslContext=null;
if(null==cerpath||"".equals(cerpath.trim())){
luckyclient.publicclass.LogUtil.APP.info("开始构建HTTPS单向认证请求...");
LogUtil.APP.info("开始构建HTTPS单向认证请求...");
TrustManager[] trustManagers = {new MyX509TrustManager()};
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, new SecureRandom());
}else{
luckyclient.publicclass.LogUtil.APP.info("开始构建HTTPS双向认证请求...");
LogUtil.APP.info("开始构建HTTPS双向认证请求...");
String strcerpath[]=cerpath.split(";",-1);
sslContext = sslContextKeyStore(strcerpath[0], strcerpath[1]);
}

View File

@ -20,6 +20,9 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import luckyclient.publicclass.LogUtil;
import luckyclient.publicclass.SysConfig;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -32,7 +35,7 @@ import org.apache.http.impl.client.HttpClients;
*
*/
public class HttpRequest {
final static Properties PROPERTIES = luckyclient.publicclass.SysConfig.getConfiguration();
final static Properties PROPERTIES = SysConfig.getConfiguration();
private final static String WEB_URL = "http://" + PROPERTIES.getProperty("server.web.ip") + ":"
+ PROPERTIES.getProperty("server.web.port");
@ -59,14 +62,14 @@ public class HttpRequest {
resultBuffer.append(temp);
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
LogUtil.APP.error(e.getMessage(), e);
br = null;
throw new RuntimeException(e);
}

View File

@ -19,6 +19,8 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -28,6 +30,7 @@ import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import luckyclient.publicclass.SysConfig;
import luckyclient.publicclass.remoterinterface.HttpRequest;
import luckyclient.serverapi.entity.monitor.Server;
import springboot.model.RunBatchCaseEntity;
@ -45,7 +48,7 @@ import springboot.model.WebDebugCaseEntity;
*/
@RestController
public class HttpImpl {
private static final Logger log = LoggerFactory.getLogger(HttpImpl.class);
private static final String os=System.getProperty("os.name").toLowerCase();
/**
* 运行自动化任务
@ -66,38 +69,37 @@ public class HttpImpl {
} catch (IOException e) {
e.printStackTrace();
}
luckyclient.publicclass.LogUtil.APP.info("开始转换RunTaskEntity执行任务实体...");
log.info("开始转换RunTaskEntity执行任务实体...");
RunTaskEntity runTaskEntity = JSONObject.parseObject(sb.toString(), RunTaskEntity.class);
luckyclient.publicclass.LogUtil.APP.info("TaskId:"+runTaskEntity.getTaskId()
log.info("TaskId:"+runTaskEntity.getTaskId()
+" SchedulingName:"+runTaskEntity.getSchedulingName()+" LoadPath:"+runTaskEntity.getLoadPath());
try{
luckyclient.publicclass.LogUtil.APP.info("开始获取客户端驱动路径...");
log.info("开始获取客户端驱动路径...");
File file =new File(System.getProperty("user.dir")+runTaskEntity.getLoadPath());
luckyclient.publicclass.LogUtil.APP.info("客户端驱动路径:"+file.getAbsolutePath());
log.info("客户端驱动路径:"+file.getAbsolutePath());
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
log.warn("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
luckyclient.publicclass.LogUtil.APP.info("初始化Runtime...");
log.info("初始化Runtime...");
Runtime run = Runtime.getRuntime();
StringBuffer sbf=new StringBuffer();
sbf.append(runTaskEntity.getTaskId()).append(" ");
sbf.append(runTaskEntity.getLoadPath());
luckyclient.publicclass.LogUtil.APP.info("启动任务模式测试程序...调度名称:【"+runTaskEntity.getSchedulingName()+"】 任务ID"+runTaskEntity.getTaskId());
log.info("启动任务模式测试程序...调度名称:【"+runTaskEntity.getSchedulingName()+"】 任务ID"+runTaskEntity.getTaskId());
if(os.startsWith("win")){
luckyclient.publicclass.LogUtil.APP.info("开始调起windows命令行窗口...");
log.info("开始调起windows命令行窗口...");
run.exec("cmd.exe /k start " + "task.cmd" +" "+ sbf.toString(), null,new File(System.getProperty("user.dir")+File.separator));
luckyclient.publicclass.LogUtil.APP.info("调起windows命令行窗口完成...");
log.info("调起windows命令行窗口完成...");
}else{
luckyclient.publicclass.LogUtil.APP.info("开始调起Linux命令脚本...");
log.info("开始调起Linux命令脚本...");
Process ps = Runtime.getRuntime().exec(System.getProperty("user.dir")+File.separator+"task.sh"+ " " +sbf.toString());
ps.waitFor();
luckyclient.publicclass.LogUtil.APP.info("调起Linux命令脚本完成...");
log.info("调起Linux命令脚本完成...");
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动任务模式测试程序异常!!!",e);
log.error("启动任务模式测试程序异常!!!",e);
return "启动任务模式测试程序异常!!!";
}
return "启动任务模式测试程序正常";
@ -129,13 +131,13 @@ public class HttpImpl {
String loadpath = jsonObject.getString("loadpath");
String testCaseExternalId = jsonObject.getString("testCaseExternalId");
String version = jsonObject.getString("version");
luckyclient.publicclass.LogUtil.APP.info("启动单用例模式测试程序...测试项目:"+projectname+" 任务ID"+taskid);
luckyclient.publicclass.LogUtil.APP.info("测试用例编号:"+testCaseExternalId+" 用例版本:"+version);
log.info("启动单用例模式测试程序...测试项目:"+projectname+" 任务ID"+taskid);
log.info("测试用例编号:"+testCaseExternalId+" 用例版本:"+version);
try{
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
log.warn("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
@ -152,7 +154,7 @@ public class HttpImpl {
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动单用例模式测试程序异常!!!",e);
log.error("启动单用例模式测试程序异常!!!",e);
return "启动单用例模式测试程序异常!!!";
}
return "启动单用例模式测试程序正常";
@ -176,43 +178,43 @@ public class HttpImpl {
} catch (IOException e) {
e.printStackTrace();
}
luckyclient.publicclass.LogUtil.APP.info("开始转换RunBatchCaseEntity批量执行用例实体...");
log.info("开始转换RunBatchCaseEntity批量执行用例实体...");
RunBatchCaseEntity runBatchCaseEntity = JSONObject.parseObject(sbd.toString(), RunBatchCaseEntity.class);
String projectName = runBatchCaseEntity.getProjectname();
String taskId = runBatchCaseEntity.getTaskid();
String loadPath = runBatchCaseEntity.getLoadpath();
String batchCase = runBatchCaseEntity.getBatchcase();
luckyclient.publicclass.LogUtil.APP.info("批量测试用例:"+batchCase);
log.info("批量测试用例:"+batchCase);
try{
luckyclient.publicclass.LogUtil.APP.info("开始获取客户端驱动路径...");
log.info("开始获取客户端驱动路径...");
File file =new File(System.getProperty("user.dir")+loadPath);
luckyclient.publicclass.LogUtil.APP.info("客户端驱动路径:"+file.getAbsolutePath());
log.info("客户端驱动路径:"+file.getAbsolutePath());
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
log.warn("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
luckyclient.publicclass.LogUtil.APP.info("初始化Runtime...");
log.info("初始化Runtime...");
Runtime run = Runtime.getRuntime();
StringBuffer sb=new StringBuffer();
sb.append(taskId).append(" ");
sb.append(batchCase).append(" ");
sb.append(loadPath);
luckyclient.publicclass.LogUtil.APP.info("启动批量用例模式测试程序...测试项目:"+projectName+" 任务ID"+taskId);
log.info("启动批量用例模式测试程序...测试项目:"+projectName+" 任务ID"+taskId);
if(os.startsWith("win")){
luckyclient.publicclass.LogUtil.APP.info("开始调起windows命令行窗口...");
log.info("开始调起windows命令行窗口...");
run.exec("cmd.exe /k start " + "task_batch.cmd" + " " +sb.toString(), null,new File(System.getProperty("user.dir")+File.separator));
luckyclient.publicclass.LogUtil.APP.info("调起windows命令行窗口完成...");
log.info("调起windows命令行窗口完成...");
}else{
luckyclient.publicclass.LogUtil.APP.info("开始调起Linux命令脚本...");
log.info("开始调起Linux命令脚本...");
Process ps = Runtime.getRuntime().exec(System.getProperty("user.dir")+File.separator+"task_batch.sh"+ " " +sb.toString());
ps.waitFor();
luckyclient.publicclass.LogUtil.APP.info("调起Linux命令脚本完成...");
log.info("调起Linux命令脚本完成...");
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动批量用例模式测试程序异常!!!",e);
log.error("启动批量用例模式测试程序异常!!!",e);
return "启动批量用例模式测试程序异常!!!";
}
return "启动批量用例模式测试程序正常";
@ -237,12 +239,12 @@ public class HttpImpl {
e.printStackTrace();
}
WebDebugCaseEntity webDebugCaseEntity = JSONObject.parseObject(sbd.toString(), WebDebugCaseEntity.class);
luckyclient.publicclass.LogUtil.APP.info("Web端调试用例ID"+webDebugCaseEntity.getCaseId()+" 发起人ID"+webDebugCaseEntity.getUserId());
log.info("Web端调试用例ID"+webDebugCaseEntity.getCaseId()+" 发起人ID"+webDebugCaseEntity.getUserId());
try{
File file =new File(System.getProperty("user.dir")+webDebugCaseEntity.getLoadpath());
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
log.warn("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
@ -258,7 +260,7 @@ public class HttpImpl {
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动Web调试模式测试程序异常",e);
log.error("启动Web调试模式测试程序异常",e);
return "启动Web调试模式测试程序异常";
}
return "启动Web调试模式测试程序正常";
@ -286,7 +288,7 @@ public class HttpImpl {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath,e);
log.error("读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath,e);
return "读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath;
}
BufferedReader bos = new BufferedReader(isr);
@ -297,11 +299,11 @@ public class HttpImpl {
sb.append(str).append("##n##");
}
bos.close();
luckyclient.publicclass.LogUtil.APP.info("服务端读取本地日志成功!");
log.info("服务端读取本地日志成功!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("客户端转BufferedReader失败请检查原因",e);
log.error("客户端转BufferedReader失败请检查原因",e);
return "客户端转BufferedReader失败请检查原因";
}
return sb.toString();
@ -325,11 +327,11 @@ public class HttpImpl {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
is.read(b);
is.close();
luckyclient.publicclass.LogUtil.APP.info("服务端获取本地图片:"+downLoadPath);
log.info("服务端获取本地图片:"+downLoadPath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("此文件不存在,请检查:"+downLoadPath,e);
log.error("此文件不存在,请检查:"+downLoadPath,e);
return b;
} catch (IOException e) {
// TODO Auto-generated catch block
@ -344,11 +346,11 @@ public class HttpImpl {
if (!jarfile.isEmpty()){
if (!FilenameUtils.getExtension(jarfile.getOriginalFilename())
.equalsIgnoreCase("jar")) {
luckyclient.publicclass.LogUtil.APP.error("文件格式后续不是.jar上传失败");
log.warn("文件格式后续不是.jar上传失败");
return "文件格式后续不是.jar上传失败";
}
}else{
luckyclient.publicclass.LogUtil.APP.error("上传文件为空,请检查!");
log.warn("上传文件为空,请检查!");
return "上传文件为空,请检查!";
}
@ -357,7 +359,7 @@ public class HttpImpl {
String path = System.getProperty("user.dir")+loadpath;
if (!new File(path) .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+path+"");
log.warn("客户端测试驱动桩路径不存在,请检查【"+path+"");
return "客户端测试驱动桩路径不存在,请检查【"+path+"";
}
String pathName = path +File.separator+ name;
@ -373,17 +375,17 @@ public class HttpImpl {
os.write(jarfileByte);
os.flush();
os.close();
luckyclient.publicclass.LogUtil.APP.info("上传JAR包【"+name+"】到客户端驱动目录【"+file.getAbsolutePath()+"】成功!");
log.info("上传JAR包【"+name+"】到客户端驱动目录【"+file.getAbsolutePath()+"】成功!");
return "上传JAR包【"+name+"】到客户端驱动目录【"+file.getAbsolutePath()+"】成功!";
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("客户端未找到正确路径或文件,上传失败!文件路径名称:"+pathName,e);
log.error("客户端未找到正确路径或文件,上传失败!文件路径名称:"+pathName,e);
return "客户端未找到正确路径或文件,上传失败!文件路径名称:"+pathName;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("客户端IOExceptiona或是未找到驱动路径文件路径名称"+pathName,e);
log.error("客户端IOExceptiona或是未找到驱动路径文件路径名称"+pathName,e);
return "客户端IOExceptiona或是未找到驱动路径文件路径名称"+pathName;
}
}
@ -396,7 +398,7 @@ public class HttpImpl {
*/
@GetMapping("/getClientStatus")
private String getClientStatus(HttpServletRequest req) throws RemoteException{
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
Properties properties = SysConfig.getConfiguration();
String verison=properties.getProperty("client.verison");
return "{\"status\":\"success\",\"version\":\""+verison+"\"}";
}
@ -423,31 +425,26 @@ public class HttpImpl {
* @date 2019年5月6日
*/
public static boolean checkHostNet() {
luckyclient.publicclass.LogUtil.APP.info("检查客户端配置中,请稍后......");
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
log.info("检查客户端配置中,请稍后......");
Properties properties = SysConfig.getConfiguration();
String version=properties.getProperty("client.verison");
String webip=properties.getProperty("server.web.ip");
Integer webport=Integer.valueOf(properties.getProperty("server.web.port"));
try {
String result = HttpRequest.loadJSON("/openGetApi/clientGetServerVersion.do");
if(version.equals(result)){
luckyclient.publicclass.LogUtil.APP.info("客户端访问Web端配置"+webip+":"+webport+" 检测通过......");
log.info("客户端访问Web端配置"+webip+":"+webport+" 检测通过......");
}else{
luckyclient.publicclass.LogUtil.APP.error("客户端版本:"+version);
luckyclient.publicclass.LogUtil.APP.error("服务端版本:"+result);
luckyclient.publicclass.LogUtil.APP.error("客户端与服务端版本不一致,有可能会导致未知问题,请检查...");
log.warn("客户端版本:"+version);
log.warn("服务端版本:"+result);
log.warn("客户端与服务端版本不一致,有可能会导致未知问题,请检查...");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("客户端配置检测异常,请确认您项目根目录下的客户端配置文件(sys_config.properties)是否已经正确配置。",e);
log.error("客户端配置检测异常,请确认您项目根目录下的客户端配置文件(sys_config.properties)是否已经正确配置。",e);
return false;
}
return true;
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
checkHostNet();
}
}

View File

@ -5,6 +5,8 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -20,15 +22,16 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RunService {
private static final Logger log = LoggerFactory.getLogger(RunService.class);
public static void main(String[] args) {
// TODO Auto-generated method stub
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator +"bootlog4j.conf");
SpringApplication.run(RunService.class, args);
try {
String host = InetAddress.getLocalHost().getHostAddress();
luckyclient.publicclass.LogUtil.APP.info("启动客户端监听,请稍后......监听IP"+host);
log.info("启动客户端监听,请稍后......监听IP"+host);
} catch (UnknownHostException e) {
luckyclient.publicclass.LogUtil.APP.error("获取服务IP出现异常......", e);
log.error("获取服务IP出现异常......", e);
}
HttpImpl.checkHostNet();
}