优化了步骤动作关键字解析的代码,采用了策略模式,代码结构更清晰。之前关键字的处理逻辑没有变。
需要增加一个关键字处理时,只需实现ActionKeyWordParser接口,重写parse方法即可
This commit is contained in:
parent
f3b3c57517
commit
87e0b6716c
|
@ -0,0 +1,13 @@
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Maven: org.javassist:javassist:3.21.0-GA">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Maven: org.reflections:reflections:0.9.11">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/reflections/reflections/0.9.11/reflections-0.9.11.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/reflections/reflections/0.9.11/reflections-0.9.11-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/reflections/reflections/0.9.11/reflections-0.9.11-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
6
pom.xml
6
pom.xml
|
@ -299,5 +299,11 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.9.11</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package luckyclient.caserun.publicdispose;
|
||||||
|
|
||||||
|
import luckyclient.caserun.publicdispose.actionkeyword.Action;
|
||||||
|
import luckyclient.caserun.publicdispose.actionkeyword.ActionKeyWordParser;
|
||||||
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 步骤动作容器,根据参数生成不同的动作关键字类型,执行相应的解析
|
||||||
|
* @author: sunshaoyan@
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
public class ActionContext {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ActionContext.class);
|
||||||
|
|
||||||
|
private static Map<String, Class> allActions;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Reflections reflections = new Reflections("luckyclient.caserun.publicdispose.actionkeyword");
|
||||||
|
Set<Class<?>> annotatedClasses =
|
||||||
|
reflections.getTypesAnnotatedWith(Action.class);
|
||||||
|
allActions = new ConcurrentHashMap<String, Class>();
|
||||||
|
for (Class<?> classObject : annotatedClasses) {
|
||||||
|
Action action = (Action) classObject
|
||||||
|
.getAnnotation(Action.class);
|
||||||
|
allActions.put(action.name(), classObject);
|
||||||
|
}
|
||||||
|
allActions = Collections.unmodifiableMap(allActions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionKeyWordParser action;
|
||||||
|
|
||||||
|
public ActionContext(String name){
|
||||||
|
|
||||||
|
if (allActions.containsKey(name)) {
|
||||||
|
logger.info("Created Action name is {}", name);
|
||||||
|
try {
|
||||||
|
action = (ActionKeyWordParser) allActions.get(name).newInstance();
|
||||||
|
} catch (InstantiationException | IllegalAccessException ex) {
|
||||||
|
logger.error("Instantiate Action failed", ex);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.error("Specified Action name {} does not exist", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parse(String actionKeyWord,String testResult) {
|
||||||
|
if(null != action){
|
||||||
|
testResult = action.parse(actionKeyWord, testResult);
|
||||||
|
}else {
|
||||||
|
testResult="未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionKeyWord;
|
||||||
|
LogUtil.APP.error("未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionKeyWord);
|
||||||
|
}
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package luckyclient.caserun.publicdispose;
|
package luckyclient.caserun.publicdispose;
|
||||||
|
|
||||||
import luckyclient.driven.SubString;
|
|
||||||
import luckyclient.publicclass.LogUtil;
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,12 +12,11 @@ import luckyclient.publicclass.LogUtil;
|
||||||
* @date 2019年1月15日
|
* @date 2019年1月15日
|
||||||
*/
|
*/
|
||||||
public class ActionManageForSteps {
|
public class ActionManageForSteps {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析用例步骤
|
* 解析用例步骤
|
||||||
* @param projectcase
|
* @param stepsaction
|
||||||
* @param step
|
* @param testresult
|
||||||
* @param taskid
|
|
||||||
* @param caselog
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String actionManage(String stepsaction,String testresult){
|
public static String actionManage(String stepsaction,String testresult){
|
||||||
|
@ -28,7 +26,7 @@ public class ActionManageForSteps {
|
||||||
LogUtil.APP.info("Action(动作)无需处理......");
|
LogUtil.APP.info("Action(动作)无需处理......");
|
||||||
return testresult;
|
return testresult;
|
||||||
}
|
}
|
||||||
stepsaction=stepsaction.toLowerCase().trim();
|
stepsaction=stepsaction.trim();
|
||||||
String[] temp=stepsaction.split("\\|",-1);
|
String[] temp=stepsaction.split("\\|",-1);
|
||||||
for(String actionorder:temp){
|
for(String actionorder:temp){
|
||||||
if(null!=actionorder&&!"".equals(actionorder.trim())){
|
if(null!=actionorder&&!"".equals(actionorder.trim())){
|
||||||
|
@ -37,93 +35,29 @@ public class ActionManageForSteps {
|
||||||
}
|
}
|
||||||
return testresult;
|
return testresult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作关键字执行
|
* 动作关键字执行
|
||||||
* @param actionorder
|
* @param actionKeyWord
|
||||||
* @param testresult
|
* @param testResult
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String actionExecute(String actionorder,String testresult){
|
private static String actionExecute(String actionKeyWord,String testResult){
|
||||||
try{
|
try{
|
||||||
// 处理动作事件
|
|
||||||
if(actionorder.endsWith("#wait")){
|
String[] actionArr = actionKeyWord.split("#");
|
||||||
if(ChangString.isInteger(actionorder.substring(0, actionorder.lastIndexOf("#wait")))){
|
if(actionArr.length == 2){
|
||||||
try {
|
ActionContext actionContext = new ActionContext(actionArr[1]);
|
||||||
// 获取步骤间等待时间
|
testResult = actionContext.parse(actionKeyWord, testResult);
|
||||||
int time=Integer.parseInt(actionorder.substring(0, actionorder.lastIndexOf("#wait")));
|
}else {
|
||||||
if (time > 0) {
|
testResult="关键字语法书写有误,请检查关键字:"+actionKeyWord;
|
||||||
LogUtil.APP.info("Action(Wait):线程等待"+time+"秒...");
|
LogUtil.APP.error("关键字语法书写有误,请检查关键字:"+actionKeyWord);
|
||||||
Thread.sleep(time * 1000);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
LogUtil.APP.warn("使用等待关键字的参数不是整数,直接跳过此动作,请检查!");
|
|
||||||
}
|
|
||||||
}else if(actionorder.endsWith("#getjv")){
|
|
||||||
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#getjv"));
|
|
||||||
String key="";
|
|
||||||
String index="1";
|
|
||||||
if(actionparams.endsWith("]")&&actionparams.contains("[")){
|
|
||||||
key=actionparams.substring(0,actionparams.lastIndexOf("["));
|
|
||||||
index=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
|
||||||
testresult=SubString.getJsonValue(testresult, key, index);
|
|
||||||
}else{
|
|
||||||
key=actionparams;
|
|
||||||
testresult=SubString.getJsonValue(testresult, key, index);
|
|
||||||
}
|
|
||||||
LogUtil.APP.info("Action(getJV):获取JSON字符串指定Key的值是:"+testresult);
|
|
||||||
}else if(actionorder.endsWith("#subcentrestr")){
|
|
||||||
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#subcentrestr"));
|
|
||||||
String startstr="";
|
|
||||||
String endstr="";
|
|
||||||
if(actionparams.startsWith("[")&&actionparams.endsWith("]")){
|
|
||||||
startstr=actionparams.substring(actionparams.indexOf("[")+1, actionparams.indexOf("]"));
|
|
||||||
endstr=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
|
||||||
testresult=SubString.subCentreStr(testresult, startstr, endstr);
|
|
||||||
LogUtil.APP.info("Action(subCentreStr):截取测试结果指定开始及结束位置字符串:"+testresult);
|
|
||||||
}else{
|
|
||||||
testresult="步骤动作:subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionorder;
|
|
||||||
LogUtil.APP.warn("步骤动作:subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionorder);
|
|
||||||
}
|
|
||||||
}else if(actionorder.endsWith("#subcentrenum")){
|
|
||||||
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#subcentrenum"));
|
|
||||||
String startnum="";
|
|
||||||
String endnum="";
|
|
||||||
if(actionparams.startsWith("[")&&actionparams.endsWith("]")){
|
|
||||||
startnum=actionparams.substring(actionparams.indexOf("[")+1, actionparams.indexOf("]"));
|
|
||||||
endnum=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
|
||||||
testresult=SubString.subCentreNum(testresult, startnum, endnum);
|
|
||||||
LogUtil.APP.info("Action(subCentreNum):截取测试结果指定开始及结束位置字符串:"+testresult);
|
|
||||||
}else{
|
|
||||||
testresult="步骤动作:subCentreNum 必须是[\"开始字符\"][\"结束字符\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionorder;
|
|
||||||
LogUtil.APP.warn("步骤动作:subCentreNum 必须是[\"开始位置(整数)\"][\"结束位置(整数)\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionorder);
|
|
||||||
}
|
|
||||||
}else if(actionorder.endsWith("#substrrgex")){
|
|
||||||
String actionparams=actionorder.substring(0, actionorder.lastIndexOf("#substrrgex"));
|
|
||||||
String key="";
|
|
||||||
String index="1";
|
|
||||||
if(actionparams.endsWith("]")&&actionparams.contains("[")){
|
|
||||||
key=actionparams.substring(0,actionparams.lastIndexOf("["));
|
|
||||||
index=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
|
||||||
testresult=SubString.subStrRgex(testresult, key, index);
|
|
||||||
}else{
|
|
||||||
key=actionparams;
|
|
||||||
testresult=SubString.subStrRgex(testresult, key, index);
|
|
||||||
}
|
|
||||||
LogUtil.APP.info("Action(subStrRgex):获取JSON字符串指定Key的值是:"+testresult);
|
|
||||||
}else{
|
|
||||||
testresult="未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionorder;
|
|
||||||
LogUtil.APP.warn("未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionorder);
|
|
||||||
}
|
}
|
||||||
return testresult;
|
return testResult;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
testresult="处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionorder;
|
testResult="处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionKeyWord;
|
||||||
LogUtil.APP.error("处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionorder);
|
LogUtil.APP.error("处理步骤动作事件过程中出现异常,直接返回测试结果:" ,e);
|
||||||
return testresult;
|
return testResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字注解定义
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
public @interface Action {
|
||||||
|
String name() default "";
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
public interface ActionKeyWordParser {
|
||||||
|
|
||||||
|
String parse(String actionKeyWord, String testResult);
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
import luckyclient.driven.SubString;
|
||||||
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口的实现类:获取JSON字符串指定Key的值的
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
@Action(name="getJV")
|
||||||
|
public class GetJsonActionParser implements ActionKeyWordParser {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取JSON字符串指定Key的值是
|
||||||
|
* @param actionKeyWord 动作关键字
|
||||||
|
* @param testResult 测试结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String parse(String actionKeyWord, String testResult) {
|
||||||
|
String actionparams=actionKeyWord.substring(0, actionKeyWord.lastIndexOf("#getJV"));
|
||||||
|
String key="";
|
||||||
|
String index="1";
|
||||||
|
if(actionparams.endsWith("]")&&actionparams.contains("[")){
|
||||||
|
key=actionparams.substring(0,actionparams.lastIndexOf("["));
|
||||||
|
index=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
||||||
|
testResult= SubString.getJsonValue(testResult, key, index);
|
||||||
|
}else{
|
||||||
|
key=actionparams;
|
||||||
|
testResult=SubString.getJsonValue(testResult, key, index);
|
||||||
|
}
|
||||||
|
LogUtil.APP.info("Action(getJV):获取JSON字符串指定Key的值是:"+testResult);
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口的实现类:从响应header中取出某个header值
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
@Action(name="Header")
|
||||||
|
public class HeaderParser implements ActionKeyWordParser {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param actionorder 动作关键字
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String parse(String actionorder, String testResult) {
|
||||||
|
|
||||||
|
|
||||||
|
// 获取步骤间等待时间
|
||||||
|
String headerParam=actionorder.substring(0, actionorder.lastIndexOf("#Header"));
|
||||||
|
String pre = "RESPONSE_HEAD:【";
|
||||||
|
String headerStr = testResult.substring(testResult.indexOf(pre) + pre.length(), testResult.indexOf("】 RESPONSE_CODE"));
|
||||||
|
return JSONObject.parseObject(headerStr).getJSONArray(headerParam).getString(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
|
||||||
|
import luckyclient.driven.SubString;
|
||||||
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口的实现类:截取测试结果指定开始及结束位置字符串
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
@Action(name="subCentreNum")
|
||||||
|
public class SubCentreNumActionParser implements ActionKeyWordParser {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 截取测试结果指定开始及结束位置字符串
|
||||||
|
* @param actionKeyWord 动作关键字
|
||||||
|
* @param testResult 测试结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String parse(String actionKeyWord, String testResult) {
|
||||||
|
String actionParams=actionKeyWord.substring(0, actionKeyWord.lastIndexOf("#subCentreNum"));
|
||||||
|
|
||||||
|
if(actionParams.startsWith("[")&&actionParams.endsWith("]")){
|
||||||
|
String startnum=actionParams.substring(actionParams.indexOf("[")+1, actionParams.indexOf("]"));
|
||||||
|
String endnum=actionParams.substring(actionParams.lastIndexOf("[")+1, actionParams.lastIndexOf("]"));
|
||||||
|
testResult= SubString.subCentreNum(testResult, startnum, endnum);
|
||||||
|
LogUtil.APP.info("Action(subCentreNum):截取测试结果指定开始及结束位置字符串:"+testResult);
|
||||||
|
}else{
|
||||||
|
testResult="步骤动作:subCentreNum 必须是[\"开始字符\"][\"结束字符\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionKeyWord;
|
||||||
|
LogUtil.APP.error("步骤动作:subCentreNum 必须是[\"开始位置(整数)\"][\"结束位置(整数)\"]#subCentreNum 格式,请检查您的步骤动作关键字:"+actionKeyWord);
|
||||||
|
}
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
import luckyclient.driven.SubString;
|
||||||
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口的实现类:截取测试结果指定开始及结束位置字符串
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
@Action(name="subCentreStr")
|
||||||
|
public class SubCentresStrActionParser implements ActionKeyWordParser {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 截取测试结果指定开始及结束位置字符串
|
||||||
|
* @param actionKeyWord 动作关键字
|
||||||
|
* @param testResult 测试结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String parse(String actionKeyWord, String testResult) {
|
||||||
|
String actionparams=actionKeyWord.substring(0, actionKeyWord.lastIndexOf("#subCentreStr"));
|
||||||
|
String startstr="";
|
||||||
|
String endstr="";
|
||||||
|
if(actionparams.startsWith("[")&&actionparams.endsWith("]")){
|
||||||
|
startstr=actionparams.substring(actionparams.indexOf("[")+1, actionparams.indexOf("]"));
|
||||||
|
endstr=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
||||||
|
testResult= SubString.subCentreStr(testResult, startstr, endstr);
|
||||||
|
LogUtil.APP.info("Action(subCentreStr):截取测试结果指定开始及结束位置字符串:"+testResult);
|
||||||
|
}else{
|
||||||
|
testResult="步骤动作:subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionKeyWord;
|
||||||
|
LogUtil.APP.error("步骤动作:subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作关键字:"+actionKeyWord);
|
||||||
|
}
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
import luckyclient.driven.SubString;
|
||||||
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口的实现类:获取JSON字符串指定Key的值,采用正则匹配
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
@Action(name="subStrRgex")
|
||||||
|
public class SubStrRegxActionParser implements ActionKeyWordParser {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取JSON字符串指定Key的值,采用正则匹配
|
||||||
|
* @param actionKeyWord 动作关键字
|
||||||
|
* @param testResult 测试结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String parse(String actionKeyWord, String testResult) {
|
||||||
|
String actionparams=actionKeyWord.substring(0, actionKeyWord.lastIndexOf("#subStrRgex"));
|
||||||
|
String key="";
|
||||||
|
String index="1";
|
||||||
|
if(actionparams.endsWith("]")&&actionparams.contains("[")){
|
||||||
|
key=actionparams.substring(0,actionparams.lastIndexOf("["));
|
||||||
|
index=actionparams.substring(actionparams.lastIndexOf("[")+1, actionparams.lastIndexOf("]"));
|
||||||
|
testResult= SubString.subStrRgex(testResult, key, index);
|
||||||
|
}else{
|
||||||
|
key=actionparams;
|
||||||
|
testResult= SubString.subStrRgex(testResult, key, index);
|
||||||
|
}
|
||||||
|
LogUtil.APP.info("Action(subStrRgex):获取JSON字符串指定Key的值是:"+testResult);
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package luckyclient.caserun.publicdispose.actionkeyword;
|
||||||
|
|
||||||
|
|
||||||
|
import luckyclient.caserun.publicdispose.ChangString;
|
||||||
|
import luckyclient.publicclass.LogUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动作关键字的处理接口的实现类:线程等待时间
|
||||||
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
|
*/
|
||||||
|
@Action(name="Wait")
|
||||||
|
public class ThreadWaitAction implements ActionKeyWordParser {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param actionorder 动作关键字
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String parse(String actionorder, String testResult) {
|
||||||
|
if(ChangString.isInteger(actionorder.substring(0, actionorder.lastIndexOf("#Wait")))){
|
||||||
|
try {
|
||||||
|
// 获取步骤间等待时间
|
||||||
|
int time=Integer.parseInt(actionorder.substring(0, actionorder.lastIndexOf("#Wait")));
|
||||||
|
if (time > 0) {
|
||||||
|
LogUtil.APP.info("Action(Wait):线程等待"+time+"秒...");
|
||||||
|
Thread.sleep(time * 1000);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
LogUtil.APP.error("使用等待关键字的参数不是整数,直接跳过此动作,请检查!");
|
||||||
|
}
|
||||||
|
return testResult;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue