From 009dd3f6da0eb9dc2dc0fa0401194711f516cfe4 Mon Sep 17 00:00:00 2001 From: seagull <24163551@qq.com> Date: Wed, 20 Jun 2018 15:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DUI=E6=B5=8B=E8=AF=95=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=A2=84=E6=9C=9F=E7=BB=93=E6=9E=9C=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=86=99check,=E5=A2=9E=E5=8A=A0=E6=8F=90=E4=BE=9B=E6=88=AA?= =?UTF-8?q?=E5=8F=96=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=BB=98=E8=AE=A4=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exwebdriver/ex/WebDriverAnalyticCase.java | 5 +- .../java/luckyclient/driven/SubString.java | 127 ++++++++++++++++++ 2 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/main/java/luckyclient/driven/SubString.java diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java index 631b28d..fce525d 100644 --- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java +++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java @@ -57,7 +57,8 @@ public class WebDriverAnalyticCase { String expectedResults = subComment(resultstr); //处理check字段 - if(expectedResults.startsWith("check(")){ + if(expectedResults.toLowerCase().startsWith("check(")){ + expectedResults=expectedResults.toLowerCase(); params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("="))); params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")"))); } @@ -67,7 +68,7 @@ public class WebDriverAnalyticCase { //set wait时间 //添加步骤之间等待时间 - if(null!=step.getAction()&&step.getAction().toLowerCase().indexOf("*wait")>-1){ + if(null!=step.getAction()&&step.getAction().toLowerCase().endsWith("*wait")){ String action=step.getAction(); time=action.substring(0, action.toLowerCase().lastIndexOf("*wait")); } diff --git a/src/main/java/luckyclient/driven/SubString.java b/src/main/java/luckyclient/driven/SubString.java new file mode 100644 index 0000000..9b8256b --- /dev/null +++ b/src/main/java/luckyclient/driven/SubString.java @@ -0,0 +1,127 @@ +package luckyclient.driven; + +import java.util.regex.Pattern; + +public class SubString { + + /** + * 截取指定字符串的中间字段 + * @param str + * @param startstr + * @param endstr + * @return + */ + public static String subCentreStr(String str,String startstr,String endstr){ + String getstr=str.substring(str.indexOf(startstr)+startstr.length(), str.indexOf(endstr)); + return getstr; + } + + /** + * 截取字符串从指定字符开始 + * @param str + * @param startstr + * @return + */ + public static String subStartStr(String str,String startstr){ + String getstr=str.substring(str.indexOf(startstr)+startstr.length()); + return getstr; + } + + /** + * 截取字符串到指定字符结束 + * @param str + * @param startstr + * @return + */ + public static String subEndStr(String str,String endstr){ + String getstr=str.substring(0,str.indexOf(endstr)); + return getstr; + } + + /** + * 通过字符串位置截取指定字符串的中间字段 + * @param str + * @param startstr + * @param endstr + * @return + */ + public static String subCentreNum(String str,String startnum,String endnum){ + String getstr=""; + if(isInteger(startnum)&&isInteger(endnum)){ + int start=Integer.valueOf(startnum); + int end=Integer.valueOf(endnum); + if(start>end){ + getstr="截取字符串开始位置数字不能大于结束位置数字"; + }else if(start<0||end<0){ + getstr="截取字符串位置的数字不能小于0"; + }else if(start>str.length()||end>str.length()){ + getstr="截取字符串位置的数字不能大于字符串本身的长度【"+str.length()+"】"; + }else{ + getstr=str.substring(start,end); + } + }else{ + getstr=""; + } + + return getstr; + } + + /** + * 通过字符串位置截取字符串从指定字符开始 + * @param str + * @param startstr + * @return + */ + public static String subStartNum(String str,String startnum){ + String getstr=""; + if(isInteger(startnum)){ + int start=Integer.valueOf(startnum); + if(start<0){ + getstr="截取字符串位置的数字不能小于0"; + }else if(start>str.length()){ + getstr="截取字符串位置的数字不能大于字符串本身的长度【"+str.length()+"】"; + }else{ + getstr=str.substring(start); + } + }else{ + getstr=""; + } + + return getstr; + } + + /** + * 截取字符串到指定字符结束 + * @param str + * @param startstr + * @return + */ + public static String subEndNum(String str,String endnum){ + String getstr=""; + if(isInteger(endnum)){ + int end=Integer.valueOf(endnum); + if(end<0){ + getstr="截取字符串位置的数字不能小于0"; + }else if(end>str.length()){ + getstr="截取字符串位置的数字不能大于字符串本身的长度【"+str.length()+"】"; + }else{ + getstr=str.substring(0,end); + } + }else{ + getstr=""; + } + + return getstr; + } + + private static boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +}