diff --git a/pom.xml b/pom.xml index 4d0aa79..b348953 100644 --- a/pom.xml +++ b/pom.xml @@ -327,6 +327,11 @@ org.springframework.boot spring-boot-starter-aop + + + org.projectlombok + lombok + diff --git a/src/main/Resources/web_debugcase.cmd b/src/main/Resources/web_debugcase.cmd index bc6ac32..83715c5 100644 --- a/src/main/Resources/web_debugcase.cmd +++ b/src/main/Resources/web_debugcase.cmd @@ -1,8 +1,8 @@ title Webԡ%1 set classpath=%CLASSPATH%;.\luckyclient; @echo Webӿ -@echo ˵ Ϊ ִ -java -Djava.ext.dirs=./lib;.%3 luckyclient.execution.WebDebugExecute %1 %2 +@echo ˵ Ϊ ִ +java -Djava.ext.dirs=./lib;.%4 luckyclient.execution.WebDebugExecute %1 %2 %3 @echo ǰԴڽ90˳ ping 127.0.0.1 -n 90 >nul exit \ No newline at end of file diff --git a/src/main/Resources/web_debugcase.sh b/src/main/Resources/web_debugcase.sh index 612507e..6efb4e9 100644 --- a/src/main/Resources/web_debugcase.sh +++ b/src/main/Resources/web_debugcase.sh @@ -1,9 +1,9 @@ #!/bin/sh BASE_DIR="." LIB="${BASE_DIR}/lib" -DRIVENPATH="${BASE_DIR}/$3" +DRIVENPATH="${BASE_DIR}/$4" JAVA_OPTS=" -Xmx2048m -XX:PermSize=64m -XX:MaxPermSize=512m -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=1024k -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/mtdperf.hprof -server -Dfile.encoding=UTF-8" -START_CLASS="luckyclient.execution.WebDebugExecute $1 $2" +START_CLASS="luckyclient.execution.WebDebugExecute $1 $2 $3" echo ${LIB} diff --git a/src/main/Resources/web_debugcase_web.cmd b/src/main/Resources/web_debugcase_web.cmd new file mode 100644 index 0000000..aa9b10c --- /dev/null +++ b/src/main/Resources/web_debugcase_web.cmd @@ -0,0 +1,8 @@ +title Webԡ%1 +set classpath=%CLASSPATH%;.\luckyclient; +@echo Webӿ +@echo ˵ Ϊ ִ web +java -Djava.ext.dirs=./lib;.%4 luckyclient.execution.WebDebugExecuteWeb %1 %2 %3 %5 +@echo ǰԴڽ90˳ +ping 127.0.0.1 -n 90 >nul +exit \ No newline at end of file diff --git a/src/main/java/luckyclient/driven/SubString.java b/src/main/java/luckyclient/driven/SubString.java index f73da1d..e406689 100644 --- a/src/main/java/luckyclient/driven/SubString.java +++ b/src/main/java/luckyclient/driven/SubString.java @@ -1,10 +1,7 @@ package luckyclient.driven; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/main/java/luckyclient/execution/appium/AppiumInitialization.java b/src/main/java/luckyclient/execution/appium/AppiumInitialization.java index 91afa8d..81b2063 100644 --- a/src/main/java/luckyclient/execution/appium/AppiumInitialization.java +++ b/src/main/java/luckyclient/execution/appium/AppiumInitialization.java @@ -34,9 +34,9 @@ public class AppiumInitialization { public static AndroidDriver setAndroidAppium(Properties properties) throws IOException { AndroidDriver appium; DesiredCapabilities capabilities = new DesiredCapabilities(); - File directory = new File(""); - File app = new File(directory.getCanonicalPath() + File.separator + properties.getProperty("appname")); - capabilities.setCapability("app", app.getAbsolutePath()); +// File directory = new File(""); +// File app = new File(directory.getCanonicalPath() + File.separator + properties.getProperty("appname")); +// capabilities.setCapability("app", app.getAbsolutePath()); // ԶԷ capabilities.setCapability("automationName", properties.getProperty("automationName")); // 豸 diff --git a/src/main/java/luckyclient/execution/httpinterface/TestCaseExecution.java b/src/main/java/luckyclient/execution/httpinterface/TestCaseExecution.java index 894f2da..791b989 100644 --- a/src/main/java/luckyclient/execution/httpinterface/TestCaseExecution.java +++ b/src/main/java/luckyclient/execution/httpinterface/TestCaseExecution.java @@ -315,6 +315,121 @@ public class TestCaseExecution { return testnote; } + //޸ĵ + public String oneCaseExecuteForCase(String testCaseExternalId, Map outVariable, Object driver) { + String expectedresults; + int setresult = 1; + int stepJumpNo=0; + String testnote = "ʼԽ"; + ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId); + List pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId())); +// if(null==caselog){ +// // ʼдԼ־ģ +// caselog = new serverOperation(); +// } + // ѹ뵽MAP + for (ProjectCaseParams pcp : pcplist) { + RUNCASE_VARIABLE.put(pcp.getParamsName(), pcp.getParamsValue()); + } + // ȫֱ + RUNCASE_VARIABLE.putAll(ParamsManageForSteps.GLOBAL_VARIABLE); + // еı + RUNCASE_VARIABLE.putAll(outVariable); + + List steps = GetServerApi.getStepsbycaseid(testcase.getCaseId()); + if (steps.size() == 0) { + setresult = 2; + LogUtil.APP.warn("δҵ裬飡"); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "δҵ裬飡", "error", "1", ""); + testnote = "δҵ裬飡"; + } + + // ѭв + for (int i = 0; i < steps.size(); i++) { + Map params = null; + ProjectCaseSteps step = steps.get(i); + //ת﷨ + if(stepJumpNo!=0&&setresult!=0){ + if(stepJumpNo==i+1){ + LogUtil.APP.info("תǰ{}",i+1); + }else if(stepJumpNo>i+1){ + LogUtil.APP.info("ǰ{},ִ...",i+1); + continue; + }else{ + LogUtil.APP.info("ת衾{}Сڵǰ衾{}ֱ¼ִ...",stepJumpNo,i+1); + } + } + + // ݲ + if (1 == step.getStepType()){ + params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, RUNCASE_VARIABLE); + }else if (3 == step.getStepType()){ +// params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,RUNCASE_VARIABLE); + } else{ + params = InterfaceAnalyticCase.analyticCaseStep(testcase, step,RUNCASE_VARIABLE); + } + + // жϷǷ쳣 + if (params.get("exception") != null && params.get("exception").contains("쳣")) { + setresult = 2; + break; + } + + expectedresults = params.get("ExpectedResults"); + Map judgeResult=new HashMap<>(); + // ݲִв + if (1 == step.getStepType()){ + WebDriver wd=(WebDriver)driver; + testnote = WebCaseExecution.runWebStep(params, wd, testcase.getCaseId(), step.getStepSerialNumber()); + testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote); + // жϽ + judgeResult = WebCaseExecution.judgeResult(testcase, step, params, wd, expectedresults, testnote);//޸ĵ + setresult = judgeResult.get("setResult"); + stepJumpNo = judgeResult.get("stepJumpNo"); + }else if (3 == step.getStepType()){ +// if (driver instanceof AndroidDriver){ +// AndroidDriver ad=(AndroidDriver)driver; +// testnote = AndroidCaseExecution.androidRunStep(params, ad, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog); +// testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote); +// // жϽ +// judgeResult = AndroidCaseExecution.judgeResult(testcase, step, params, ad, taskid, expectedresults, testnote, caselog); +// setresult = judgeResult.get("setResult"); +// stepJumpNo = judgeResult.get("stepJumpNo"); +// }else{ +// IOSDriver ios=(IOSDriver)driver; +// testnote = IosCaseExecution.iosRunStep(params, RUNCASE_VARIABLE, ios, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog); +// testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote); +// // жϽ +// judgeResult = IosCaseExecution.judgeResult(testcase, step, params, ios, taskid, expectedresults, testnote, caselog); +// setresult = judgeResult.get("setResult"); +// stepJumpNo = judgeResult.get("stepJumpNo"); +// } + + } else{ + testnote = runStep(params, testcase.getCaseSign(), step); + testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote); + // жϽ + judgeResult = interfaceJudgeResult(testcase, step, expectedresults, testnote); + setresult = judgeResult.get("setResult"); + stepJumpNo = judgeResult.get("stepJumpNo"); + } + + if (0 != setresult){ + testnote = ":"+testcase.getCaseSign()+" "+step.getStepSerialNumber()+"ִйʧܡ"; + LogUtil.APP.warn(":{} {}ִйʧܣ־{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote); + break; + } + } + + //βգŵִеķȥ + // RUNCASE_VARIABLE.clear(); + if (0 == setresult) { + LogUtil.APP.info(":{}ȫִгɹ",testcase.getCaseSign()); + } + + return testnote; + } + /** * ͲеýӿڲԲ * @param params @@ -379,6 +494,62 @@ public class TestCaseExecution { return result; } + //޸ĵ + public String runStep(Map params, String casenum, ProjectCaseSteps step) { + String result; + String packagename; + String functionname = ""; + Object[] getParameterValues; + ProjectCase projectCase = GetServerApi.cgetCaseBysign(casenum); + try { + packagename = params.get("PackageName"); + functionname = params.get("FunctionName"); + + if (null != functionname && functionname.contains("쳣")) { + LogUtil.APP.warn(":{}, {}ʧܣ",casenum,functionname); +// caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), ": " + casenum + ", " + functionname + "ʧܣ", "error", String.valueOf(step.getStepSerialNumber()), ""); + result = "ִʧܣʧ!"; + } else { + // жϷǷ + if (params.size() > 4) { + // ȡ + getParameterValues = new Object[params.size() - 4]; + for (int j = 0; j < params.size() - 4; j++) { + if (params.get("FunctionParams" + (j + 1)) == null) { + break; + } + String parameterValues = params.get("FunctionParams" + (j + 1)); + 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; + } + } else { + getParameterValues = null; + } + + LogUtil.APP.info("νɣȴнӿڲ......"); +// caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "·: " + packagename + "; : " + functionname, "info", String.valueOf(step.getStepSerialNumber()), ""); + + // ӿ֧ʹruncaseؼ + if ((null != functionname && "runcase".equals(functionname))) { + TestCaseExecution testCaseExecution=new TestCaseExecution(); + result = testCaseExecution.oneCaseExecuteForCase(getParameterValues[0].toString(), RUNCASE_VARIABLE, null); + }else{ + result = InvokeMethod.callCase(packagename, functionname, getParameterValues, step.getStepType(), step.getExtend()); + } + } + } catch (Exception e) { + LogUtil.APP.error("÷̳:{}¼űԼ",functionname,e); + result = "ִʧܣӿڵó"; + } + if (result.contains("ִʧܣ")){ +// caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), result, "error", String.valueOf(step.getStepSerialNumber()), ""); + } else{ +// caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), result, "info", String.valueOf(step.getStepSerialNumber()), ""); + } + return result; + } + private Map interfaceJudgeResult(ProjectCase testcase, ProjectCaseSteps step, String taskid, String expectedresults, String testnote, serverOperation caselog){ Map judgeResult=new HashMap<>(); judgeResult.put("setResult",0); @@ -482,5 +653,108 @@ public class TestCaseExecution { return judgeResult; } + //޸ĵ + private Map interfaceJudgeResult(ProjectCase testcase, ProjectCaseSteps step, String expectedresults, String testnote){ + Map judgeResult=new HashMap<>(); + judgeResult.put("setResult",0); + judgeResult.put("stepJumpNo",0); + try{ + if (null != expectedresults && !expectedresults.isEmpty()) { + //ת + if (expectedresults.length() > Constants.IFFAIL_JUMP.length() && expectedresults.startsWith(Constants.IFFAIL_JUMP)) { + LogUtil.APP.info("Ԥڽджת裬ǰԭʼַ{}",expectedresults); + String expectedTemp = expectedresults.substring(Constants.IFFAIL_JUMP.length()); + if(expectedTemp.contains(Constants.SYMLINK)){ + expectedresults = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+2); + try{ + Integer stepJumpNo = Integer.parseInt(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK))); + judgeResult.put("stepJumpNo",stepJumpNo); + }catch (NumberFormatException nfe){ + LogUtil.APP.error("ת﷨ʧܣŲ֣ȷ:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK))); + } + }else{ + LogUtil.APP.warn("ԤڽжʧܣȷԤڽ﷨ṹ"+Constants.IFFAIL_JUMP+">>ԤڽԭʼԤڽֵ{}",expectedresults); + } + } + + LogUtil.APP.info("expectedResults={}",expectedresults); + // ֵ + if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) { + RUNCASE_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()), testnote); + LogUtil.APP.info(":{} {}Խ{}ֵ{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote,expectedresults.substring(Constants.ASSIGNMENT_SIGN.length())); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "Խ" + testnote + "ֵ" + expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), ""); + } + // ֵȫֱ + else if (expectedresults.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) { + RUNCASE_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote); + ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote); + LogUtil.APP.info(":{} {}Խ{}ֵȫֱ{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote,expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length())); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "Խ" + testnote + "ֵȫֱ" + expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), ""); + } + // ģƥ + else if (expectedresults.length() > Constants.FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.FUZZY_MATCHING_SIGN)) { + if (testnote.contains(expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()))) { + LogUtil.APP.info(":{} {}ģƥԤڽɹִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ģƥԤڽɹִн" + testnote, "info", String.valueOf(step.getStepSerialNumber()), ""); + } else { + judgeResult.put("setResult",1); + LogUtil.APP.warn(":{} {}ģƥԤڽʧܣԤڽ:{}Խ:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()),testnote); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ģƥԤڽʧܣԤڽ" + expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()) + "Խ" + testnote, "error", String.valueOf(step.getStepSerialNumber()), ""); + } + } + // ƥ + else if (expectedresults.length() > Constants.REGULAR_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.REGULAR_MATCHING_SIGN)) { + Pattern pattern = Pattern.compile(expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length())); + Matcher matcher = pattern.matcher(testnote); + if (matcher.find()) { + LogUtil.APP.info(":{} {}ƥԤڽɹִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ƥԤڽɹִн" + testnote, "info", String.valueOf(step.getStepSerialNumber()), ""); + } else { + judgeResult.put("setResult",1); + LogUtil.APP.warn(":{} {}ƥԤڽʧܣԤڽ:{}Խ:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()),testnote); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ƥԤڽʧܣԤڽ" + expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()) + "Խ" + testnote, "error", String.valueOf(step.getStepSerialNumber()), ""); + } + } + //jsonpath + else if (expectedresults.length() > Constants.JSONPATH_SIGN.length() && expectedresults.startsWith(Constants.JSONPATH_SIGN)) { + expectedresults = expectedresults.substring(Constants.JSONPATH_SIGN.length()); + String expression = expectedresults.split("(? variable = new HashMap<>(0); serverOperation.exetype=1; String packagename; @@ -257,5 +261,19 @@ public class WebTestCaseDebug { PostServerApi.cPostDebugLog(userId, caseId, "ERRORover", " " + sign + "ִйʧܣ飡",1); } } + } + //޸ĵ + /** + * WEBҳϵʱṩĽӿ + * @param caseIdStr ID + * @param userIdStr ûID + * @param caseTypeStr ͣ1 + * @param browserTypeStr web0 IE 1 2 ȸ 3 Edge + */ + public static void oneCaseDebug(String caseIdStr, String userIdStr,String caseTypeStr,String browserTypeStr) { + int caseId=Integer.parseInt(caseIdStr); + int browserType=Integer.parseInt(browserTypeStr); + WebOneCaseExecute.debugoneCaseExecute(caseId, browserType); + } } \ No newline at end of file diff --git a/src/main/java/luckyclient/execution/httpinterface/analyticsteps/InterfaceAnalyticCase.java b/src/main/java/luckyclient/execution/httpinterface/analyticsteps/InterfaceAnalyticCase.java index 9adae1e..ac13cb9 100644 --- a/src/main/java/luckyclient/execution/httpinterface/analyticsteps/InterfaceAnalyticCase.java +++ b/src/main/java/luckyclient/execution/httpinterface/analyticsteps/InterfaceAnalyticCase.java @@ -79,7 +79,56 @@ public class InterfaceAnalyticCase{ return params; } - + + public static Map analyticCaseStep(ProjectCase projectcase,ProjectCaseSteps step, Map variable){ + Map params = new HashMap<>(0); + + try { + String resultstr = step.getExpectedResult(); + params.put("Action", step.getAction()); + // ֵ + String packageName = ChangString.changparams(step.getStepPath(), variable, "·"); + params.put("PackageName", packageName); + // ֵ + String functionName = ChangString.changparams(step.getStepOperation(), variable, ""); + params.put("FunctionName", functionName); + String stepParams = replaceSpi(step.getStepParameters(),0); + String[] temp=stepParams.split("\\|",-1); + for(int i=0;i steps, WebDriver wd, List pcplist) { + // ѹ뵽MAP + for (ProjectCaseParams pcp : pcplist) { + variable.put(pcp.getParamsName(), pcp.getParamsValue()); + } + // ȫֱ + variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE); + // 0:ɹ 1:ʧ 2: + int setcaseresult = 0; + //תʶ + int stepJumpNo=0; + for (int i = 0; i < steps.size(); i++) { + Map params; + String result; + ProjectCaseSteps step = steps.get(i); + + //ת﷨ + if(stepJumpNo!=0&&setcaseresult!=0){ + if(stepJumpNo==i+1){ + setcaseresult = 0; + LogUtil.APP.info("תǰ{}",i+1); + }else if(stepJumpNo>i+1){ + LogUtil.APP.info("ǰ{},ִ...",i+1); + continue; + }else{ + LogUtil.APP.info("ת衾{}Сڵǰ衾{}ֱ¼ִ...",stepJumpNo,i+1); + } + } + + // ݲ + if (1 == step.getStepType()){ + params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, variable); + }else{ + params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, variable); + } + + // жϷǷ쳣 + if (null != params.get("exception") && params.get("exception").contains("쳣")) { + setcaseresult = 2; + break; + } + + // ݲִв + if (1 == step.getStepType()){ + result = runWebStep(params, wd, testcase.getCaseId(), step.getStepSerialNumber()); + }else{ + TestCaseExecution testCaseExecution=new TestCaseExecution(); + result = testCaseExecution.runStep(params, testcase.getCaseSign(), step); + } + + String expectedResults = params.get("ExpectedResults"); + + // жϽ + Map judgeResult = judgeResult(testcase, step, params, wd, expectedResults, result); + Integer stepresult = judgeResult.get("setResult"); + stepJumpNo = judgeResult.get("stepJumpNo"); + // ʧܣҲڼ,ֱֹ + if (0 != stepresult) { + setcaseresult = stepresult; + if (testcase.getFailcontinue() == 0) { + LogUtil.APP.warn("{}ڡ{}ִʧܣжϱִУ뵽һִ......",testcase.getCaseSign(),step.getStepSerialNumber()); + break; + } else { + LogUtil.APP.warn("{}ڡ{}ִʧܣִУ¸ִ......",testcase.getCaseSign(),step.getStepSerialNumber()); + } + } + } + + variable.clear(); +// caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult); + if (setcaseresult == 0) { + LogUtil.APP.info("{}ȫִнɹ...",testcase.getCaseSign()); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ȫִнɹ", "info", "ending", ""); + } else { + LogUtil.APP.warn("{}ִйʧܻ...鿴ԭ:{}",testcase.getCaseSign(),casenote); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ִйʧܻ" + casenote, "error", "ending", ""); + } + } + public static String runWebStep(Map params, WebDriver wd, String taskid, Integer caseId, int stepno, serverOperation caselog) { String result; String property; @@ -157,8 +237,12 @@ public class WebCaseExecution{ // ҳԪز if (null != property && null != propertyValue && null != operation) { - WebElement we = isElementExist(wd, property, propertyValue); - + WebElement we; + if (!property.equals("classnames")){ + we = isElementExist(wd, property, propertyValue); + }else{ + we = isElementExist(wd, property, propertyValue,operationValue); + } //жԪǷڹؼ if(operation.equals("iselementexist")){ // жϴԪǷ @@ -221,6 +305,113 @@ public class WebCaseExecution{ } + //޸ĵ + public static String runWebStep(Map params, WebDriver wd, Integer caseId, int stepno) { + String result; + String property; + String propertyValue; + String operation; + String operationValue; + + try { + property = params.get("property"); + propertyValue = params.get("property_value"); + operation = params.get("operation"); + operationValue = params.get("operation_value"); + + LogUtil.APP.info("νɣȴж......"); +// caselog.insertTaskCaseLog(taskid, caseId, ":" + operation + "; ֵ:" + operationValue, "info", String.valueOf(stepno), ""); + } catch (Exception e) { + LogUtil.APP.error("ν׳쳣",e); + return "ִʧܣʧ!"; + } + + try { + //һֽ֧ӿڣweb + if (null != operationValue && "runcase".equals(operation)) { + String[] temp = operationValue.split(",", -1); + TestCaseExecution testCaseExecution=new TestCaseExecution(); + String ex = testCaseExecution.oneCaseExecuteForCase(temp[0], variable, wd); + if (!ex.contains("CallCaseó") && !ex.contains("") && !ex.contains("ʧ")) { + // runcaseеı + variable.putAll(testCaseExecution.RUNCASE_VARIABLE); + testCaseExecution.RUNCASE_VARIABLE.clear(); + return ex; + } else { + return "ִʧܣ"+ex; + } + } + + // ҳԪز + if (null != property && null != propertyValue && null != operation) { + WebElement we; + if (!property.equals("classnames")){ + we = isElementExist(wd, property, propertyValue); + }else{ + we = isElementExist(wd, property, propertyValue,operationValue); + } + //жԪǷڹؼ + if(operation.equals("iselementexist")){ + // жϴԪǷ + if (null == we) { + LogUtil.APP.warn("ȡֵǡfalse"); + return "ȡֵǡfalse"; + }else{ + LogUtil.APP.info("ȡֵǡtrue"); + return "ȡֵǡtrue"; + } + } + + // жϴԪǷ + if (null == we) { + LogUtil.APP.warn("λʧܣisElementExistΪnull!"); + return "ִʧܣλԪزڣ"; + } + + //Ԫ + BaseWebDrive.highLightElement(wd, we); + + if (operation.contains("select")) { + result = EncapsulateOperation.selectOperation(we, operation, operationValue); + } else if (operation.contains("get")) { + result = EncapsulateOperation.getOperation(wd, we, operation, operationValue); + } else if (operation.contains("mouse")) { + result = EncapsulateOperation.actionWeOperation(wd, we, operation, operationValue, property, propertyValue); + } else { + result = EncapsulateOperation.objectOperation(wd, we, operation, operationValue, property, propertyValue); + } + // Driver + } else if (null == property && null != operation) { + // ¼ + if (operation.contains("alert")) { + result = EncapsulateOperation.alertOperation(wd, operation); + } else if (operation.contains("mouse")) { + result = EncapsulateOperation.actionOperation(wd, operation, operationValue); + } else { + result = EncapsulateOperation.driverOperation(wd, operation, operationValue); + } + } else { + LogUtil.APP.warn("Ԫزʧܣ"); + result = "ִʧܣԪزʧܣ"; + } + } catch (Exception e) { + LogUtil.APP.error("Ԫضλ̻Dzʧܻ쳣",e); + return "ִʧܣԪضλ̻Dzʧܻ쳣" + e.getMessage(); + } + + if (result.contains("ִʧܣ")){ +// caselog.insertTaskCaseLog(taskid, caseId, result, "error", String.valueOf(stepno), ""); + } else{ +// caselog.insertTaskCaseLog(taskid, caseId, result, "info", String.valueOf(stepno), ""); + } + + if (result.contains("ȡֵǡ") && result.contains("")) { + result = result.substring(result.indexOf("ȡֵǡ") + "ȡֵǡ".length(), result.length() - 1); + } + return result; + + } + private static WebElement isElementExist(WebDriver wd, String property, String propertyValue) { try { WebElement we = null; @@ -230,6 +421,10 @@ public class WebCaseExecution{ case "id": we = wd.findElement(By.id(propertyValue)); break; + //className + case "classname": + we = wd.findElement(By.className(propertyValue)); + break; case "name": we = wd.findElement(By.name(propertyValue)); break; @@ -258,6 +453,26 @@ public class WebCaseExecution{ } + //޸ĵ + private static WebElement isElementExist(WebDriver wd, String property, String propertyValue,String operationValue) { + try { + int index = Integer.parseInt(operationValue); + WebElement we = null; + property = property.toLowerCase(); + // WebElementλ + //className[] + if ("classnames".equals(property)) { + we = wd.findElements(By.className(propertyValue)).get(index); + } + return we; + + } catch (Exception e) { + LogUtil.APP.error("ǰλʧܣ",e); + return null; + } + + } + public static Map judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map params, WebDriver driver, String taskid, String expect, String result, serverOperation caselog) { Map judgeResult=new HashMap<>(); judgeResult.put("setResult",0); @@ -373,7 +588,127 @@ public class WebCaseExecution{ LogUtil.APP.warn(":{} {}ִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote); caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ǰִйн|λԪ|ʧܣ" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname); } - + + return judgeResult; + } + + //޸ĵ + public static Map judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map params, WebDriver driver, String expect, String result) { + Map judgeResult=new HashMap<>(); + judgeResult.put("setResult",0); + judgeResult.put("stepJumpNo",0); + java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss"); + String imagname = timeformat.format(new Date()); + + result = ActionManageForSteps.actionManage(step.getAction(), result); + if (null != result && !result.contains("ִʧܣ")) { + // Ԥڽ + if (null != expect && !expect.isEmpty()) { + //ת + if (expect.length() > Constants.IFFAIL_JUMP.length() && expect.startsWith(Constants.IFFAIL_JUMP)) { + LogUtil.APP.info("Ԥڽджת裬ǰԭʼַ{}",expect); + String expectedTemp = expect.substring(Constants.IFFAIL_JUMP.length()); + if(expectedTemp.contains(Constants.SYMLINK)){ + expect = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+2); + try{ + Integer stepJumpNo = Integer.parseInt(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK))); + judgeResult.put("stepJumpNo",stepJumpNo); + }catch (NumberFormatException nfe){ + LogUtil.APP.error("ת﷨ʧܣŲ֣ȷ:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK))); + } + }else{ + LogUtil.APP.warn("ԤڽжʧܣȷԤڽ﷨ṹ"+Constants.IFFAIL_JUMP+">>ԤڽԭʼԤڽֵ{}",expect); + } + } + + LogUtil.APP.info("Ϊ{}",expect); + // ֵģʽ + if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) { + variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result); + LogUtil.APP.info(":{} {}Խ{}ֵ{}",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length())); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "Խ" + result + "ֵ" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), ""); + } + // ֵȫֱ + else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) { + variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result); + ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result); + LogUtil.APP.info(":{} {}Խ{}ֵȫֱ{}",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length())); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "Խ" + result + "ֵȫֱ" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "", "info", String.valueOf(step.getStepSerialNumber()), ""); + } + // WebUIģʽ + else if (1 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) { + String checkproperty = params.get("checkproperty"); + String checkPropertyValue = params.get("checkproperty_value"); + + WebElement we = isElementExist(driver, checkproperty, checkPropertyValue); + if (null != we) { + LogUtil.APP.info(":{} {}ڵǰҳҵԤڽж󡣵ǰִгɹ",testcase.getCaseSign(),step.getStepSerialNumber()); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ڵǰҳҵԤڽж󡣵ǰִгɹ", "info", String.valueOf(step.getStepSerialNumber()), ""); + } else { + casenote = "" + step.getStepSerialNumber() + "ûڵǰҳҵԤڽжִʧܣ"; + judgeResult.put("setResult",1); + BaseWebDrive.webScreenShot(driver, imagname); + LogUtil.APP.warn(":{} {}ûڵǰҳҵԤڽж󡣵ǰִʧܣ",testcase.getCaseSign(),step.getStepSerialNumber()); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ڵǰҳûҵԤڽж󡣵ǰִʧܣ" + "checkproperty" + checkproperty + " checkproperty_value" + checkPropertyValue + "", "error", String.valueOf(step.getStepSerialNumber()), imagname); + } + } + // ƥģʽ + else { + // ģƥԤڽģʽ + if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) { + if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) { + LogUtil.APP.info(":{} {}ģƥԤڽɹִн{}",testcase.getCaseSign(),step.getStepSerialNumber(),result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ģƥԤڽɹִн" + result, "info", String.valueOf(step.getStepSerialNumber()), ""); + } else { + casenote = "" + step.getStepSerialNumber() + "ģƥԤڽʧܣ"; + judgeResult.put("setResult",1); + BaseWebDrive.webScreenShot(driver, imagname); + LogUtil.APP.warn(":{} {}ģƥԤڽʧܣԤڽ:{}Խ:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ģƥԤڽʧܣԤڽ" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + "Խ" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname); + } + } + // ƥԤڽģʽ + else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) { + Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length())); + Matcher matcher = pattern.matcher(result); + if (matcher.find()) { + LogUtil.APP.info(":{} {}ƥԤڽɹִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ƥԤڽɹ", "info", String.valueOf(step.getStepSerialNumber()), ""); + } else { + casenote = "" + step.getStepSerialNumber() + "ƥԤڽʧܣ"; + judgeResult.put("setResult",1); + BaseWebDrive.webScreenShot(driver, imagname); + LogUtil.APP.warn(":{} {}ƥԤڽʧܣԤڽ:{}Խ:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ƥԤڽʧܣԤڽ" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + "Խ" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname); + } + } + // ȷƥԤڽģʽ + else { + if (expect.equals(result)) { + LogUtil.APP.info(":{} {}ȷƥԤڽɹִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ȷƥԤڽɹ", "info", String.valueOf(step.getStepSerialNumber()), ""); + } else if(expect.trim().equals("NULL")&& StringUtils.isBlank(result)){ + result = "ؽΪգƥNULLɹ"; + LogUtil.APP.info(":{} {}ȷƥԤڽɹִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ȷƥԤڽɹ", "info", String.valueOf(step.getStepSerialNumber()), ""); + } else { + casenote = "" + step.getStepSerialNumber() + "ȷƥԤڽʧܣ"; + judgeResult.put("setResult",1); + BaseWebDrive.webScreenShot(driver, imagname); + LogUtil.APP.warn(":{} {}ȷƥԤڽʧܣԤڽ:{} ִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ȷƥԤڽʧܣԤڽǣ"+expect+" ִн"+ result+"", "error", String.valueOf(step.getStepSerialNumber()), imagname); + } + } + } + } + } else { + casenote = (null != result) ? result : ""; + judgeResult.put("setResult",2); + BaseWebDrive.webScreenShot(driver, imagname); + LogUtil.APP.warn(":{} {}ִн:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote); +// caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "ǰִйн|λԪ|ʧܣ" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname); + } + return judgeResult; } diff --git a/src/main/java/luckyclient/execution/webdriver/ex/WebDriverAnalyticCase.java b/src/main/java/luckyclient/execution/webdriver/ex/WebDriverAnalyticCase.java index ff80aff..8164495 100644 --- a/src/main/java/luckyclient/execution/webdriver/ex/WebDriverAnalyticCase.java +++ b/src/main/java/luckyclient/execution/webdriver/ex/WebDriverAnalyticCase.java @@ -107,6 +107,74 @@ public class WebDriverAnalyticCase { return params; } + public static Map analyticCaseStep(ProjectCase projectcase, ProjectCaseSteps step, Map variable) { + Map params = new HashMap<>(0); + + String resultstr; + try { + // ֵ + String path = ChangString.changparams(step.getStepPath(), variable, "·|λ·"); + if (null != path && path.contains("=")) { + String property = path.substring(0, path.indexOf("=")).trim(); + String propertyValue = path.substring(path.indexOf("=") + 1).trim(); + // set + params.put("property", property.toLowerCase()); + // setֵ + params.put("property_value", propertyValue); + LogUtil.APP.info("Խproperty:{}; property_value:{}", property, propertyValue); + } + // set,ֵ + String operation = ChangString.changparams(step.getStepOperation().toLowerCase(), variable, ""); + params.put("operation", operation); + // setֵ,ֵ + String operationValue = ChangString.changparams(step.getStepParameters(), variable, ""); + if (StringUtils.isNotEmpty(operationValue)) { + params.put("operation_value", operationValue); + } + LogUtil.APP.info("operation:{}; operation_value:{}", operation,operationValue); + // ȡԤڽַ + resultstr = step.getExpectedResult(); + + // setԤڽ + if (null == resultstr || "".equals(resultstr)) { + params.put("ExpectedResults", ""); + } else { + String expectedResults = subComment(resultstr); + + // checkֶ + if (expectedResults.toLowerCase().startsWith("check(")) { + expectedResults = expectedResults.replace("Check(", "check("); + params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(") + 6, + expectedResults.indexOf("="))); + params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=") + 1, + expectedResults.lastIndexOf(")"))); + } + //ֵ + expectedResults = ChangString.changparams(expectedResults, variable, "Ԥڽ"); + params.put("ExpectedResults", expectedResults); + LogUtil.APP.info("ԤڽExpectedResults:{}", expectedResults); + } + + 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) { + LogUtil.APP.error(":{} {}Զű쳣", projectcase.getCaseSign(), step.getStepSerialNumber(), + e); +// if (null != caselog) { +// caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(), +// "ţ" + step.getStepSerialNumber() + " Զű", "error", +// String.valueOf(step.getStepSerialNumber()), ""); +// } + params.put("exception", "ţ" + projectcase.getCaseSign() + "|쳣,Ϊջű"); + return params; + } + return params; + } + private static String subComment(String htmlStr) { // scriptʽ String regExScript = "]*?>[\\s\\S]*?"; diff --git a/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java b/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java index 60f6669..07e8c6f 100644 --- a/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java +++ b/src/main/java/luckyclient/execution/webdriver/ex/WebOneCaseExecute.java @@ -58,4 +58,33 @@ public class WebOneCaseExecute{ wd.quit(); } + public static void debugoneCaseExecute(int caseId, int drivertype){ +// //¼־ݿ +// serverOperation.exetype = 1; + WebDriver wd = null; + try { + wd = WebDriverInitialization.setWebDriverForTask(drivertype); + } catch (IOException e1) { + LogUtil.APP.error("ʼWebDriver", e1); + } +// serverOperation caselog = new serverOperation(); + ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId); + //ɾɵ־ +// serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid); + + List pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId())); + LogUtil.APP.info("ʼִ:{}......",testcase.getCaseSign()); + try { + List steps=GetServerApi.getStepsbycaseid(testcase.getCaseId()); + WebCaseExecution.caseExcution(testcase, steps, wd,pcplist); + LogUtil.APP.info("ǰ:{}ִ......һ",testcase.getCaseSign()); + } catch (Exception e) { + LogUtil.APP.error("ûִй׳쳣", e); + } +// serverOperation.updateTaskExecuteData(taskid, 0,2); + //ر + assert wd != null; + wd.quit(); + } + } diff --git a/src/main/java/luckyclient/tool/SpecialProjectT.java b/src/main/java/luckyclient/tool/SpecialProjectT.java new file mode 100644 index 0000000..d5391d7 --- /dev/null +++ b/src/main/java/luckyclient/tool/SpecialProjectT.java @@ -0,0 +1,67 @@ +package luckyclient.tool; + + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import luckyclient.utils.LogUtil; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; + +/** + * @author lifengyang + */ +public class SpecialProjectT { + public static String set_String(String set){ + LogUtil.APP.info("õַΪ"+set); + return set; + } + + + //jsonַ󣬶keyȻ + public static String jsonStringNaturalOrdering(String jsonString){ + LogUtil.APP.info("õjsonStringַΪ"+jsonString); + jsonString=JSONObject.toJSONString(JSONObject.parseObject(jsonString), SerializerFeature.MapSortField); + LogUtil.APP.info("ȻjsonStringַΪ"+jsonString); + return jsonString; + } + + /** + * windows ִcmd + * @param cmd + * @return cmdִн + * @throws IOException + */ + public String exeCMD(String cmd) throws IOException { + LogUtil.APP.info("cmdΪ"+cmd); + String lw=cmd.toLowerCase(); + if(!lw.contains("cmd /c")){ + cmd="cmd /c "+lw; + } + //jmeter ɱ + if(cmd.contains("jmeter -g")){ + Date date = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HH_mm_ss"); + String time=formatter.format(date); + cmd=cmd+time; + } + Process process=Runtime.getRuntime().exec(cmd); + InputStream input = process.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(input,"GBK")); + String s; + StringBuilder sb = new StringBuilder(); + while((s=reader.readLine())!=null){ + sb.append(s+"\n"); + } + reader.close(); + input.close(); + s=sb.toString(); + LogUtil.APP.info(s); + return s; + } +} diff --git a/src/main/java/luckyclient/tool/UseConstant.java b/src/main/java/luckyclient/tool/UseConstant.java new file mode 100644 index 0000000..d84964c --- /dev/null +++ b/src/main/java/luckyclient/tool/UseConstant.java @@ -0,0 +1,31 @@ +package luckyclient.tool; + +public class UseConstant { + + + public static final String[] tag_names ={"span","label","div","input","a"}; + +// public static final String tag_names_span="span"; +// public static final String tag_names_label="span"; +// public static final String tag_names_div="div"; +// public static final String tag_names_input="input"; +// public static final String tag_names_a="a"; + + + public static final String attribute_value_starts_with="starts-with"; + public static final String attribute_value_contains="contains"; + public static final String attribute_value_ends_with="ends-with"; + + + + + public static final String ID = "id"; + public static final String XPATH = "xpath"; + public static final String LINK_TEXT = "link text"; + public static final String PARTIAL_LINK_TEXT = "partial link text"; + public static final String NAME = "name"; + public static final String TAG_NAME = "tag name"; + public static final String CLASS_NAME = "class name"; + public static final String CSS_SELECTOR = "css selector"; + public static final String XPATH_OTHER = "xpath other"; +} diff --git a/src/main/java/luckyclient/utils/InvokeMethod.java b/src/main/java/luckyclient/utils/InvokeMethod.java index a665466..703c359 100644 --- a/src/main/java/luckyclient/utils/InvokeMethod.java +++ b/src/main/java/luckyclient/utils/InvokeMethod.java @@ -13,6 +13,7 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import luckyclient.execution.dispose.ChangString; import luckyclient.execution.dispose.ParamsManageForSteps; import luckyclient.remote.api.GetServerApi; @@ -192,7 +193,7 @@ public class InvokeMethod { } // if (ptp.getParamType() == 1) { - JSONObject json = JSONObject.parseObject(tempparam); + JSONObject json = JSONObject.parseObject(tempparam, Feature.OrderedField); params.put(ptp.getParamName().replace(""", "\""), json); LogUtil.APP.info("ģ{} JSONObjectͲֵ:{}",ptp.getParamName(),json.toString()); } else if (ptp.getParamType() == 2) { diff --git a/src/main/java/luckyclient/utils/httputils/HttpClientTools.java b/src/main/java/luckyclient/utils/httputils/HttpClientTools.java index 132c953..8e3e46d 100644 --- a/src/main/java/luckyclient/utils/httputils/HttpClientTools.java +++ b/src/main/java/luckyclient/utils/httputils/HttpClientTools.java @@ -19,6 +19,7 @@ import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; @@ -41,6 +42,7 @@ import java.security.KeyStore; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -577,7 +579,7 @@ public class HttpClientTools { * @param ppt Эģ * @return */ - public String httpClientPostJson(String urlParam, Map params, Map headmsg, ProjectProtocolTemplate ppt) throws NoSuchAlgorithmException, KeyManagementException { + public String httpClientPostJson(String urlParam, Map params, Map headmsg, ProjectProtocolTemplate ppt) throws NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException { String cerpath = ppt.getCerificatePath(); String charset = ppt.getEncoding().toLowerCase(); int timeout = ppt.getTimeout() * 1000; @@ -611,7 +613,7 @@ public class HttpClientTools { try { if (params.size() > 0) { if (1 == params.size() && params.containsKey("_forTextJson")) { - LogUtil.APP.info("ͣTEXT,HTTPPostJsonϢ...{}", params.get("_forTextJson").toString()); + LogUtil.APP.info("ͣRAW,HTTPPostJsonϢ...{}", params.get("_forTextJson").toString()); StringEntity entity = new StringEntity(params.get("_forTextJson").toString(), charset); httpPost.setEntity(entity); } else { diff --git a/src/main/java/springboot/HttpImpl.java b/src/main/java/springboot/HttpImpl.java index baebd9d..1cf905d 100644 --- a/src/main/java/springboot/HttpImpl.java +++ b/src/main/java/springboot/HttpImpl.java @@ -178,7 +178,7 @@ public class HttpImpl { e.printStackTrace(); } WebDebugCaseEntity webDebugCaseEntity = JSONObject.parseObject(sbd.toString(), WebDebugCaseEntity.class); - log.info("Web˵ID:{} ID:{}",webDebugCaseEntity.getCaseId(),webDebugCaseEntity.getUserId()); + log.info("Web˵ID:{} ID:{} :{}",webDebugCaseEntity.getCaseId(),webDebugCaseEntity.getUserId(),webDebugCaseEntity.getCaseType()); try{ File file =new File(RunService.APPLICATION_HOME+webDebugCaseEntity.getLoadpath()); if (!file .isDirectory()) @@ -190,13 +190,23 @@ public class HttpImpl { StringBuilder sb=new StringBuilder(); sb.append(webDebugCaseEntity.getCaseId()).append(" "); sb.append(webDebugCaseEntity.getUserId()).append(" "); + sb.append(webDebugCaseEntity.getCaseType()).append(" ");//޸ĵ sb.append(webDebugCaseEntity.getLoadpath()); - if(OS.startsWith("win")){ - run.exec("cmd.exe /k start " + "web_debugcase.cmd" + " " +sb.toString(), null,new File(RunService.APPLICATION_HOME+File.separator)); - }else{ - Process ps = Runtime.getRuntime().exec(RunService.APPLICATION_HOME+File.separator+"web_debugcase.sh"+ " " +sb.toString()); - ps.waitFor(); - } + if(webDebugCaseEntity.getCaseType().intValue()==0||webDebugCaseEntity.getCaseType().intValue()==2){ + if(OS.startsWith("win")){ + run.exec("cmd.exe /k start " + "web_debugcase.cmd" + " " +sb.toString(), null,new File(RunService.APPLICATION_HOME+File.separator)); + }else{ + Process ps = Runtime.getRuntime().exec(RunService.APPLICATION_HOME+File.separator+"web_debugcase.sh"+ " " +sb.toString()); + ps.waitFor(); + } + }else if (webDebugCaseEntity.getCaseType().intValue()==1){ + if(OS.startsWith("win")){ + sb.append(" ").append(webDebugCaseEntity.getBrowserType()); + run.exec("cmd.exe /k start " + "web_debugcase_web.cmd" + " " +sb.toString(), null,new File(RunService.APPLICATION_HOME+File.separator)); + }else{ + // + } + } } catch (Exception e) { e.printStackTrace(); log.error("WebģʽԳ쳣",e); diff --git a/src/main/java/springboot/model/WebDebugCaseEntity.java b/src/main/java/springboot/model/WebDebugCaseEntity.java index 415959d..12f55d5 100644 --- a/src/main/java/springboot/model/WebDebugCaseEntity.java +++ b/src/main/java/springboot/model/WebDebugCaseEntity.java @@ -19,7 +19,10 @@ public class WebDebugCaseEntity implements Serializable { private Integer caseId; private Integer userId; private String loadpath; - + //޸ĵ + private Integer caseType; + private Integer browserType; + public Integer getCaseId() { return caseId; } @@ -39,4 +42,15 @@ public class WebDebugCaseEntity implements Serializable { this.loadpath = loadpath; } + //޸ĵ + public Integer getCaseType(){return caseType; } + public void setCaseType(Integer caseType) { + this.caseType = caseType; + } + public Integer getBrowserType() { + return browserType; + } + public void setBrowserType(Integer browserType) { + this.browserType = browserType; + } }