1. WEB UI用例增加支持调用外部WEB UI用例

2. WEB UI用例增加支持接口步骤
3. 增加支持使用标题获取窗口句柄
4. 增加支持使用标题切换窗口
5. 合并作者最新修复问题版本(2018-03-06)
This commit is contained in:
Killua 2018-03-07 12:06:56 +08:00
commit 5df561f70a
15 changed files with 894 additions and 189 deletions

View File

@ -1,4 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/Resources/appium_config.properties=GBK
encoding//src/main/Resources/sys_config.properties=GBK
encoding//src/main/java=GBK
encoding//src/test/java=GBK

View File

@ -1,16 +1,24 @@
#===============================系统配置=====================================
<<<<<<< HEAD
#server.web.ip=localhost
server.web.ip=192.168.12.112
=======
server.web.ip=XX.XX.XX.XX
>>>>>>> origin/master
server.web.port=8080
#===============================TestLink=====================================
#TestLink URL地址
testlink.api.ip=localhost
testlink.api.ip=XX.XX.XX.XX
#TestLink DEVKEY密钥
testlink.api.devkey=40ad3f1eb4cac155a5e0704e9c5280d2
#================================数据库=============================================
#数据库地址
<<<<<<< HEAD
#mysql.db.ip=localhost
mysql.db.ip=192.168.12.94
=======
mysql.db.ip=XX.XX.XX.XX
>>>>>>> origin/master
#数据库端口
mysql.db.port=3306
#数据库名
@ -22,14 +30,14 @@ mysql.db.username=root
#mysql.db.userpwd=luckyframe
mysql.db.userpwd=Devops123
#==================================邮件============================================
#smtp邮件IP
mail.smtp.ip=smtp.qq.com
#smtp邮件端口
mail.smtp.port=465
#smtp邮件ssl连接开启
mail.smtp.ssl.enable=true
#smtp邮件IPsmtp.qq.com
mail.smtp.ip=XX.XX.XX.XX
#smtp邮件端口25
mail.smtp.port=25
#smtp邮件ssl连接开启true false
mail.smtp.ssl.enable=false
#smtp邮件用户名
mail.smtp.username=XX@qq.com
mail.smtp.username=XX@XX.com
#smtp邮件用户密码
mail.smtp.password=xxxxxx
#邮件模板路径

View File

@ -58,7 +58,7 @@ public class AppDriverAnalyticCase {
String expectedResults = subComment(resultstr);
//处理check字段
if(expectedResults.indexOf("check(")>-1){
if(expectedResults.startsWith("check(")){
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("=")));
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
}

View File

@ -12,7 +12,6 @@ import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import luckyclient.caserun.exappium.AppDriverAnalyticCase;
import luckyclient.caserun.exinterface.TestCaseExecution;
import luckyclient.caserun.exwebdriver.EncapsulateOperation;
import luckyclient.dblog.LogOperation;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
@ -244,7 +243,7 @@ public class AndroidCaseExecution extends TestCaseExecution{
caselog.caseLogDetail(taskid, casenum, result,"info", String.valueOf(stepno),"");
if(result.indexOf("获取到的值是【")>-1&&result.indexOf("")>-1){
result = result.substring(7, result.length()-1);
result = result.substring(result.indexOf("获取到的值是【")+7, result.length()-1);
}
return result;

View File

@ -243,7 +243,7 @@ public class IosCaseExecution extends TestCaseExecution{
caselog.caseLogDetail(taskid, casenum, result,"info", String.valueOf(stepno),"");
if(result.indexOf("获取到的值是【")>-1&&result.indexOf("")>-1){
result = result.substring(7, result.length()-1);
result = result.substring(result.indexOf("获取到的值是【")+7, result.length()-1);
}
return result;

View File

@ -4,36 +4,45 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.dblog.LogOperation;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.publicclass.ChangString;
import luckyclient.publicclass.InvokeMethod;
import luckyclient.publicclass.remoterinterface.HttpRequest;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: TestCaseDebug
* @Description: 针对自动化用例在编写过程中对用例脚本进行调试
* @author seagull
* @date 2014年8月24日 上午9:29:40
*
* @ClassName: TestCaseDebug
* @Description: 针对自动化用例在编写过程中对用例脚本进行调试 @author seagull
* @date 2018年3月1日
*
*/
public class ApiTestCaseDebug{
public class ApiTestCaseDebug {
private static final String ASSIGNMENT_SIGN = "$=";
private static final String FUZZY_MATCHING_SIGN = "%=";
private static final String REGULAR_MATCHING_SIGN = "~=";
/**
* 用于在本地做单条用例调试
*
* @param projectname
* @param testCaseExternalId
*/
public static void oneCaseDebug(String projectname,String testCaseExternalId){
Map<String,String> variable = new HashMap<String,String>(0);
String packagename =null;
public static void oneCaseDebug(String projectname, String testCaseExternalId) {
Map<String, String> variable = new HashMap<String, String>(0);
String packagename = null;
String functionname = null;
String expectedresults = null;
Integer setresult = 1;
@ -41,142 +50,215 @@ public class ApiTestCaseDebug{
String testnote = "初始化测试结果";
int k = 0;
ProjectCase testcaseob = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcaseob.getProjectid()));
List<PublicCaseParams> pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testcaseob.getProjectid()));
// 把公共参数加入到MAP中
for (PublicCaseParams pcp : pcplist) {
variable.put(pcp.getParamsname(), pcp.getParamsvalue());
}
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(testcaseob.getId());
if(steps.size()==0){
setresult=2;
List<ProjectCasesteps> steps = GetServerAPI.getStepsbycaseid(testcaseob.getId());
if (steps.size() == 0) {
setresult = 2;
luckyclient.publicclass.LogUtil.APP.error("用例中未找到步骤,请检查!");
testnote="用例中未找到步骤,请检查!";
testnote = "用例中未找到步骤,请检查!";
}
//进入循环解析用例所有步骤
for(int i=0;i<steps.size();i++){
Map<String,String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcaseob, steps.get(i),"888888",null);
try {
packagename = casescript.get("PackageName").toString();
packagename = ChangString.changparams(packagename, variable,"包路径");
functionname = casescript.get("FunctionName").toString();
functionname = ChangString.changparams(functionname, variable,"方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcaseob.getSign() + "解析包名或是方法名失败,请检查!");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
// 进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcaseob, steps.get(i), "888888",
null);
try {
packagename = casescript.get("PackageName").toString();
packagename = ChangString.changparams(packagename, variable, "包路径");
functionname = casescript.get("FunctionName").toString();
functionname = ChangString.changparams(functionname, variable, "方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcaseob.getSign() + "解析包名或是方法名失败,请检查!");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
}
// 用例名称解析出现异常或是单个步骤参数解析异常
if (functionname.indexOf("解析异常") > -1 || k == 1) {
k = 0;
testnote = "用例第" + (i + 1) + "步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString();
expectedresults = ChangString.changparams(expectedresults, variable, "预期结果");
// 判断方法是否带参数
if (casescript.size() > 4) {
// 获取传入参数放入对象中初始化参数对象个数
getParameterValues = new Object[casescript.size() - 4];
for (int j = 0; j < casescript.size() - 4; j++) {
if (casescript.get("FunctionParams" + (j + 1)) == null) {
k = 1;
break;
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable, "用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcaseob.getSign() + "解析包名:" + packagename
+ " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
getParameterValues[j] = parameterValues;
}
//用例名称解析出现异常或是单个步骤参数解析异常
if(functionname.indexOf("解析异常")>-1||k==1){
k=0;
testnote = "用例第"+(i+1)+"步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString();
expectedresults = ChangString.changparams(expectedresults, variable,"预期结果");
//判断方法是否带参数
if(casescript.size()>4){
//获取传入参数放入对象中初始化参数对象个数
getParameterValues = new Object[casescript.size()-4];
for(int j=0;j<casescript.size()-4;j++){
if(casescript.get("FunctionParams"+(j+1))==null){
k = 1;
break;
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable,"用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcaseob.getSign() + "解析包名:" + packagename
+ " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
getParameterValues[j] = parameterValues;
}
}else{
getParameterValues = null;
}
//调用动态方法执行测试用例
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:"+functionname+" .....");
//把预期结果前两个字符判断是否是要把结果存入变量
if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("$=")>-1){
String expectedResultVariable = casescript.get("ExpectedResults").toString().substring(2);
String temptestnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
variable.put(expectedResultVariable, temptestnote);
//把预期结果与测试结果做模糊匹配
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
if(testnote.indexOf(expectedresults.substring(2))>-1){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例第"+(i+1)+"步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error("预期结果:"+expectedresults+" 测试结果:"+testnote);
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!";
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
if(expectedresults.equals(testnote)){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例第"+(i+1)+"步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error("预期结果:"+expectedresults+" 测试结果:"+testnote);
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!";
break; //某一步骤失败后此条用例置为失败退出
}
}
//获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}
}catch(Exception e){
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!");
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(),e);
testnote = "CallCase调用出错";
e.printStackTrace();
break;
}
}
variable.clear(); //清空传参MAP
//如果调用方法过程中未出错进入设置测试结果流程
if(testnote.indexOf("CallCase调用出错")<=-1&&testnote.indexOf("解析出错啦!")<=-1){
luckyclient.publicclass.LogUtil.APP.info("用例 "+testCaseExternalId+"解析成功,并成功调用用例中方法,请继续查看执行结果!");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例 "+testCaseExternalId+"解析或是调用步骤中的方法出错!");
}
if(0==setresult){
luckyclient.publicclass.LogUtil.APP.info("用例 "+testCaseExternalId+"步骤全部执行成功!");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例 "+testCaseExternalId+"在执行过程中失败,请检查日志!");
}
} else {
getParameterValues = null;
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues,
steps.get(i).getSteptype(), steps.get(i).getAction());
if (null != expectedresults && !expectedresults.isEmpty()) {
luckyclient.publicclass.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("用例:" + testcaseob.getSign() + "" + (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(
"用例:" + testcaseob.getSign() + "" + (i + 1) + "步,模糊匹配预期结果成功!执行结果:" + testnote);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcaseob.getSign() + "" + (i + 1)
+ "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(FUZZY_MATCHING_SIGN.length())
+ ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
break; // 某一步骤失败后此条用例置为失败退出
}
}
// 正则匹配
else if (expectedresults.length() > REGULAR_MATCHING_SIGN.length()
&& expectedresults.startsWith(REGULAR_MATCHING_SIGN)) {
Pattern pattern = Pattern.compile(expectedresults.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(testnote);
if (matcher.find()) {
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info(
"用例:" + testcaseob.getSign() + "" + (i + 1) + "步,正则匹配预期结果成功!执行结果:" + testnote);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcaseob.getSign() + "" + (i + 1)
+ "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(REGULAR_MATCHING_SIGN.length())
+ ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
break; // 某一步骤失败后此条用例置为失败退出
}
}
// 完全相等
else {
if (expectedresults.equals(testnote)) {
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info(
"用例:" + testcaseob.getSign() + "" + (i + 1) + "步,精确匹配预期结果成功!执行结果:" + testnote);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcaseob.getSign() + "" + (i + 1)
+ "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote);
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
break; // 某一步骤失败后此条用例置为失败退出
}
}
}
// 获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if (waitsec != 0) {
Thread.sleep(waitsec * 1000);
}
} catch (Exception e) {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
testnote = "CallCase调用出错";
e.printStackTrace();
break;
}
}
variable.clear(); // 清空传参MAP
// 如果调用方法过程中未出错进入设置测试结果流程
if (testnote.indexOf("CallCase调用出错") <= -1 && testnote.indexOf("解析出错啦!") <= -1) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testCaseExternalId + "解析成功,并成功调用用例中方法,请继续查看执行结果!");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "解析或是调用步骤中的方法出错!");
}
if (0 == setresult) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testCaseExternalId + "步骤全部执行成功!");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "在执行过程中失败,请检查日志!");
}
}
/**
* 用于在本地做多条用例串行调试
*
* @param projectname
* @param addtestcase
*/
public static void moreCaseDebug(String projectname,Map<String,Integer> addtestcase){
public static void moreCaseDebug(String projectname, Map<String, Integer> addtestcase) {
System.out.println(addtestcase.size());
@SuppressWarnings("rawtypes")
Iterator it=addtestcase.entrySet().iterator();
while(it.hasNext()){
@SuppressWarnings("rawtypes")
Map.Entry entry=(Map.Entry)it.next();
String testCaseExternalId = (String)entry.getKey();
Integer version = (Integer)entry.getValue();
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:"+testCaseExternalId+",用例版本:"+version);
oneCaseDebug(projectname,testCaseExternalId);
}catch(Exception e){
continue;
}
Iterator it = addtestcase.entrySet().iterator();
while (it.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Map.Entry) it.next();
String testCaseExternalId = (String) entry.getKey();
Integer version = (Integer) entry.getValue();
try {
luckyclient.publicclass.LogUtil.APP
.info("开始调用方法,项目名:" + projectname + ",用例编号:" + testCaseExternalId + ",用例版本:" + version);
oneCaseDebug(projectname, testCaseExternalId);
} catch (Exception e) {
continue;
}
}
}
/**
* 获取指定任务名称以及用例号报错日志中的执行预期结果 casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogDetailExpectresult(String taskname, String caseno, int casestatus) {
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailExpectResult(taskid, caseno, casestatus);
}
/**
* 获取指定任务名称以及用例号报错日志中的执行测试结果 casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogDetailRunresult(String taskname, String caseno, int casestatus) {
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailTestResult(taskid, caseno, casestatus);
}
/**
* 更新系统中用例指定步骤的预期结果
*/
public static String setExpectedResults(String testCaseSign, int steps, String expectedResults) {
String results = "设置结果失败";
String params = "";
try {
expectedResults = expectedResults.replace("%", "BBFFHH");
expectedResults = expectedResults.replace("=", "DHDHDH");
expectedResults = expectedResults.replace("&", "ANDAND");
params = "caseno=" + testCaseSign;
params += "&stepnum=" + steps;
params += "&expectedresults=" + expectedResults;
results = HttpRequest.sendPost("/projectCasesteps/cUpdateStepExpectedResults.do", params);
} catch (TestLinkAPIException te) {
te.printStackTrace(System.err);
results = te.getMessage().toString();
return results;
}
return results;
}
public static void main(String[] args) throws Exception {
}

View File

@ -28,6 +28,7 @@ import org.openqa.selenium.WebDriver;
* =================================================================
*
* @author seagull
<<<<<<< HEAD
* @date 2017年12月1日 上午9:29:40
*/
public class TestCaseExecution {
@ -116,6 +117,98 @@ public class TestCaseExecution {
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1));
=======
* @date 2018年3月1日
*
*/
public class TestCaseExecution {
private static final String ASSIGNMENT_SIGN = "$=";
private static final String FUZZY_MATCHING_SIGN = "%=";
private static final String REGULAR_MATCHING_SIGN = "~=";
/**
* @param 项目名
* @param 用例编号
* @param 用例版本号
* 用于单条用例调试并通过日志框架写日志到UTP上用做UTP上单条用例运行
*/
public static void oneCaseExecuteForTast(String projectname, String testCaseExternalId, int version,
String taskid) {
Map<String, String> variable = new HashMap<String, String>(0);
TestControl.TASKID = taskid;
DbLink.exetype = 0;
// 初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
String packagename = null;
String functionname = null;
String expectedresults = null;
Integer setresult = 1;
Object[] getParameterValues = null;
String testnote = "初始化测试结果";
int k = 0;
// 删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid);
ProjectCase testcaseob = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcaseob.getProjectid()));
// 把公共参数加入到MAP中
for (PublicCaseParams pcp : pcplist) {
variable.put(pcp.getParamsname(), pcp.getParamsvalue());
}
List<ProjectCasesteps> steps = GetServerAPI.getStepsbycaseid(testcaseob.getId());
if(steps.size()==0){
setresult=2;
luckyclient.publicclass.LogUtil.APP.error("用例中未找到步骤,请检查!");
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid,"用例中未找到步骤,请检查!", "error", "1");
testnote="用例中未找到步骤,请检查!";
}
// 进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcaseob, steps.get(i), taskid,caselog);
try {
packagename = casescript.get("PackageName");
packagename = ChangString.changparams(packagename, variable,"包路径");
functionname = casescript.get("FunctionName");
functionname = ChangString.changparams(functionname, variable,"方法名");
} catch (Exception e) {
k = 0;
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcaseob.getSign() + "解析包名或是方法名失败,请检查!");
caselog.caseLogDetail(taskid, testcaseob.getSign(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
}
// 用例名称解析出现异常或是单个步骤参数解析异常
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
k = 0;
testnote = "用例第" + (i + 1) + "步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults");
expectedresults = ChangString.changparams(expectedresults, variable,"预期结果");
// 判断方法是否带参数
if (casescript.size() > 4) {
// 获取传入参数放入对象中初始化参数对象个数
getParameterValues = new Object[casescript.size() - 4];
for (int j = 0; j < casescript.size() - 4; j++) {
if (casescript.get("FunctionParams" + (j + 1)) == null) {
k = 1;
break;
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable,"用例参数");
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcaseob.getSign() + "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues);
caselog.caseLogDetail(taskid, testcaseob.getSign(), "解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
getParameterValues[j] = parameterValues;
}
} else {
getParameterValues = null;
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1));
>>>>>>> origin/master
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getSteptype(), steps.get(i).getAction());

View File

@ -24,7 +24,7 @@ import luckyclient.publicclass.InvokeMethod;
* @ClassName: ThreadForExecuteCase
* @Description: 线程池方式执行用例
* @author seagull
* @date 2017年7月13日 上午9:29:40
* @date 2018年3月1日
*/
public class ThreadForExecuteCase extends Thread {
private static final String ASSIGNMENT_SIGN = "$=";

View File

@ -24,13 +24,13 @@ import luckyclient.publicclass.InvokeMethod;
* @ClassName: WebTestCaseDebug
* @Description: 提供Web端调试接口
* @author seagull
* @date 2017年9月2日 上午9:29:40
* @date 2018年3月1日
*/
public class WebTestCaseDebug {
private static final String ASSIGNMENT_SIGN = "$=";
private static final String FUZZY_MATCHING_SIGN = "%=";
private static final String REGULAR_MATCHING_SIGN = "~=";
private static final String ASSIGNMENT_SIGN = "$=";
private static final String FUZZY_MATCHING_SIGN = "%=";
private static final String REGULAR_MATCHING_SIGN = "~=";
/**
* @param executor
* @param sign 用于在WEB页面上调试用例时提供的接口

View File

@ -1,3 +1,4 @@
<<<<<<< HEAD
package luckyclient.caserun.exwebdriver;
import java.util.ArrayList;
@ -459,3 +460,373 @@ public class EncapsulateOperation {
}
}
=======
package luckyclient.caserun.exwebdriver;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import luckyclient.caserun.exwebdriver.ocr.Ocr;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class EncapsulateOperation {
public static String selectOperation(WebElement we,String operation,String operationValue) throws Exception{
String result = "";
// 下拉框对象处理
Select select = new Select(we);
// 处理下拉框事件
switch (operation) {
case "selectbyvisibletext":
result = "下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operationValue + "";
select.selectByVisibleText(operationValue);
luckyclient.publicclass.LogUtil.APP.info(result);
break;
case "selectbyvalue":
result = "下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "";
select.selectByValue(operationValue);
luckyclient.publicclass.LogUtil.APP.info(result);
break;
case "selectbyindex":
result = "下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "";
select.selectByIndex(Integer.valueOf(operationValue));
luckyclient.publicclass.LogUtil.APP.info(result);
break;
case "isselect":
result = "获取到的值是【"+we.isSelected()+"";
luckyclient.publicclass.LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + we.isSelected() + "");
break;
default:
break;
}
return result;
}
public static String getOperation(WebDriver wd,WebElement we,String operation,String value) throws Exception{
String result = "";
// 获取对象处理
switch (operation) {
case "gettext":
result = "获取到的值是【"+we.getText()+"";
luckyclient.publicclass.LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "");
break; // 获取输入框内容
case "gettagname":
result = "获取到的值是【"+we.getTagName()+"";
luckyclient.publicclass.LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "");
break;
case "getattribute":
result = "获取到的值是【"+we.getAttribute(value)+"";
luckyclient.publicclass.LogUtil.APP.info("getAttribute获取对象【"+value+"】属性...【"+value+"属性值:" + result + "");
break;
case "getcssvalue":
result = "获取到的值是【"+we.getCssValue(value)+"";
luckyclient.publicclass.LogUtil.APP.info("getCssValue获取对象【"+value+"】属性...【"+value+"属性值:" + result + "");
break;
case "getcaptcha":
result = "获取到的值是【"+Ocr.getCAPTCHA(wd, we)+"";
luckyclient.publicclass.LogUtil.APP.info("getcaptcha获取验证码...【验证码值:" + result + "");
break;
default:
break;
}
return result;
}
public static String actionWeOperation(WebDriver wd,WebElement we,String operation,String operationValue,String property,String propertyValue) throws Exception{
String result = "";
Actions action = new Actions(wd);
// action处理
switch (operation) {
//鼠标左键点击
case "mouselkclick":
action.click(we).perform();
result = "mouselkclick鼠标左键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mouselkclick鼠标左键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mouserkclick":
action.contextClick(we).perform();
result = "mouserkclick鼠标右键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mouserkclick鼠标右键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mousedclick":
action.doubleClick(we).perform();
result = "mousedclick鼠标双击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mousedclick鼠标双击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mouseclickhold":
action.clickAndHold(we).perform();
result = "mouseclickhold鼠标点击对象后不释放...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mouseclickhold鼠标点击对象后不释放...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mousedrag":
String[] temp=operationValue.split(",",-1);
action.dragAndDropBy(we, Integer.valueOf(temp[0]), Integer.valueOf(temp[1])).perform();
result = "mousedrag鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp[0])
+" 坐标y"+Integer.valueOf(temp[1]);
luckyclient.publicclass.LogUtil.APP.info("mousedrag鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp[0])
+" 坐标y"+Integer.valueOf(temp[1]));
break;
case "mouseto":
String[] temp1=operationValue.split(",",-1);
action.moveToElement(we, Integer.valueOf(temp1[0]), Integer.valueOf(temp1[1])).perform();
result = "mouseto鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp1[0])
+" 坐标y"+Integer.valueOf(temp1[1]);
luckyclient.publicclass.LogUtil.APP.info("mouseto鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp1[0])
+" 坐标y"+Integer.valueOf(temp1[1]));
break;
case "mouserelease":
action.release(we).perform();
result = "mouserelease鼠标释放...";
luckyclient.publicclass.LogUtil.APP.info("mouserelease鼠标释放...");
break;
default:
break;
}
return result;
}
public static String actionOperation(WebDriver wd,String operation,String operationValue) throws Exception{
String result = "";
Actions action = new Actions(wd);
// action处理
switch (operation) {
//鼠标左键点击
case "mouselkclick":
action.click().perform();
result = "mouselkclick鼠标左键点击当前位置...";
luckyclient.publicclass.LogUtil.APP.info("mouselkclick鼠标左键点击当前位置...");
break;
case "mouserkclick":
action.contextClick().perform();
result = "mouserkclick鼠标右键点击当前位置...";
luckyclient.publicclass.LogUtil.APP.info("mouserkclick鼠标右键点击当前位置...");
break;
case "mousedclick":
action.doubleClick().perform();
result = "mousedclick鼠标双击当前位置...";
luckyclient.publicclass.LogUtil.APP.info("mousedclick鼠标双击当前位置...");
break;
case "mouseclickhold":
action.clickAndHold().perform();
result = "mouseclickhold鼠标点击当前位置后不释放...";
luckyclient.publicclass.LogUtil.APP.info("mouseclickhold鼠标点击当前位置后不释放...");
break;
case "mouseto":
String[] temp1=operationValue.split(",",-1);
action.moveByOffset(Integer.valueOf(temp1[0]), Integer.valueOf(temp1[1])).perform();
result = "mouseto鼠标移动至对象相对坐标...坐标x"+Integer.valueOf(temp1[0])
+" 坐标y"+Integer.valueOf(temp1[1]);
luckyclient.publicclass.LogUtil.APP.info("mouseto鼠标移动至对象相对坐标... 坐标x"+Integer.valueOf(temp1[0])
+" 坐标y"+Integer.valueOf(temp1[1]));
break;
case "mouserelease":
action.release().perform();
result = "mouserelease鼠标释放...";
luckyclient.publicclass.LogUtil.APP.info("mouserelease鼠标释放...");
break;
case "mousekey":
switch (operationValue) {
case "tab":
action.sendKeys(Keys.TAB).perform();
result = "键盘操作TAB键...";
luckyclient.publicclass.LogUtil.APP.info("键盘操作TAB键...");
break;
case "space":
action.sendKeys(Keys.SPACE).perform();
result = "键盘操作SPACE键...";
luckyclient.publicclass.LogUtil.APP.info("键盘操作SPACE键...");
break;
case "ctrl":
action.sendKeys(Keys.CONTROL).perform();
result = "键盘操作CONTROL键...";
luckyclient.publicclass.LogUtil.APP.info("键盘操作CONTROL键...");
break;
case "shift":
action.sendKeys(Keys.SHIFT).perform();
result = "键盘操作SHIFT键...";
luckyclient.publicclass.LogUtil.APP.info("键盘操作SHIFT键...");
break;
case "enter":
action.sendKeys(Keys.ENTER).perform();
result = "键盘操作SHIFT键...";
luckyclient.publicclass.LogUtil.APP.info("键盘操作SHIFT键...");
break;
default:
break;
}
break;
default:
break;
}
return result;
}
public static String objectOperation(WebDriver wd,WebElement we,String operation,String operationValue,String property,String propertyValue) throws Exception{
String result = "";
// 处理WebElement对象操作
switch (operation) {
case "click":
we.click();
result = "click点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("click点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "sendkeys":
we.sendKeys(operationValue);
result = "sendKeys对象输入...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"; 操作值:"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("sendkeys对象输入...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"; 操作值:"+operationValue+"");
break;
case "clear":
we.clear();
result = "clear清空输入框...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("clear清空输入框...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break; // 清空输入框
case "gotoframe":
wd.switchTo().frame(we);
luckyclient.publicclass.LogUtil.APP.info("gotoframe切换Frame...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "isenabled":
result = "获取到的值是【"+we.isEnabled()+"";
luckyclient.publicclass.LogUtil.APP.info("当前对象判断是否可用布尔值为【"+we.isEnabled()+"");
break;
case "isdisplayed":
result = "获取到的值是【"+we.isDisplayed()+"";
luckyclient.publicclass.LogUtil.APP.info("当前对象判断是否可见布尔值为【"+we.isDisplayed()+"");
break;
case "exjsob":
JavascriptExecutor jse = (JavascriptExecutor)wd;
jse.executeScript(operationValue,we);
result = "执行JS...【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【"+operationValue+"");
break;
default:
break;
}
return result;
}
public static String alertOperation(WebDriver wd,String operation) throws Exception{
String result = "";
Alert alert = wd.switchTo().alert();
switch (operation) {
case "alertaccept":
alert.accept();
luckyclient.publicclass.LogUtil.APP.info("弹出框对象点击同意...");
break;
case "alertdismiss":
alert.dismiss();
luckyclient.publicclass.LogUtil.APP.info("弹出框对象点击取消...");
break;
case "alertgettext":
result = "获取到的值是【"+alert.getText()+"";
luckyclient.publicclass.LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "");
break;
default:
break;
}
return result;
}
public static String driverOperation(WebDriver wd,String operation,String operationValue) throws Exception{
String result = "";
// 处理页面对象操作
switch (operation) {
case "open":
wd.get(operationValue);
result = "Open页面...【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("Open页面...【"+operationValue+"");
break;
case "exjs":
JavascriptExecutor jse = (JavascriptExecutor)wd;
jse.executeScript(operationValue);
result = "执行JS...【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【"+operationValue+"");
break;
case "gotodefaultcontent":
wd.switchTo().defaultContent();
luckyclient.publicclass.LogUtil.APP.info("gotodefaultcontent切换至默认页面位置...");
break;
case "gettitle":
result = "获取到的值是【"+wd.getTitle()+"";
luckyclient.publicclass.LogUtil.APP.info("获取页面Title...【"+wd.getTitle()+"");
break;
case "getwindowhandle":
Set<String> handles=wd.getWindowHandles();
int handlenum=1;
for(String handle:handles){
if(String.valueOf(handlenum).equals(operationValue)){
if(wd.getWindowHandle().equals(handle)){
result = "请注意你指定的handle就是当前页面哦获取到的值是【"+handle+"";
}else{
result = "指定handles的顺序值值是"+operationValue+",获取到的值是【"+handle+"";
}
break;
}
handlenum++;
}
luckyclient.publicclass.LogUtil.APP.info("getWindowHandle获取窗口句柄..."+result);
break;
case "gotowindow":
Set<String> gotohandles=wd.getWindowHandles();
int flag=0;
for (String handleName : gotohandles) {
if (operationValue.contains(handleName)) {
flag=1;
wd.switchTo().window(handleName);
break;
}
}
if(flag==1){
result = "切换窗口句柄至【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info(result);
}else{
result = "切换窗口失败,未找到句柄值为【"+operationValue+"】的对象";
luckyclient.publicclass.LogUtil.APP.info(result);
}
break;
case "timeout":
try {
//设置页面加载最大时长30秒
wd.manage().timeouts().pageLoadTimeout(Integer.valueOf(operationValue), TimeUnit.SECONDS);
//设置元素出现最大时长30秒
wd.manage().timeouts().implicitlyWait(Integer.valueOf(operationValue), TimeUnit.SECONDS);
result = "当前任务操作等待【"+operationValue+"】秒...";
luckyclient.publicclass.LogUtil.APP.info("当前任务操作等待【"+operationValue+"】秒...");
break;
} catch (NumberFormatException e) {
luckyclient.publicclass.LogUtil.APP.error("等待时间转换出错 ");
e.printStackTrace();
result = "【等待时间转换出错,请检查参数】";
break;
}
default:
break;
}
return result;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
>>>>>>> origin/master

View File

@ -31,10 +31,11 @@ import luckyclient.publicclass.ChangString;
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
* @date 2018年3月1日
*/
public class WebCaseExecution extends TestCaseExecution {
private static Map<String, String> variable = new HashMap<>();
<<<<<<< HEAD
// 0:成功 1:失败 2:锁定 其他锁定
private static int setresult = 0;
private static String casenote = "备注初始化";
@ -42,11 +43,19 @@ public class WebCaseExecution extends TestCaseExecution {
/*
public static void caseExcutionBak(ProjectCase testcase, List<ProjectCasesteps> steps, String taskid, WebDriver wd, LogOperation caselog, List<PublicCaseParams> pcplist)
=======
private static final String ASSIGNMENT_SIGN = "$=";
private static final String FUZZY_MATCHING_SIGN = "%=";
private static final String REGULAR_MATCHING_SIGN = "~=";
public static void caseExcution(ProjectCase testcase, List<ProjectCasesteps> steps, String taskid, WebDriver wd, LogOperation caselog, List<PublicCaseParams> pcplist)
>>>>>>> origin/master
throws InterruptedException {
// 0:成功 1:失败 2:锁定 其他锁定
int setresult = 0;
String casenote = "备注初始化";
String imagname = "";
<<<<<<< HEAD
// 把公共参数加入到MAP中
for (PublicCaseParams pcp : pcplist) {
variable.put(pcp.getParamsname(), pcp.getParamsvalue());
@ -180,6 +189,8 @@ public class WebCaseExecution extends TestCaseExecution {
*/
public static void caseExcution(ProjectCase testcase, List<ProjectCasesteps> steps, String taskid, WebDriver wd, LogOperation caselog, List<PublicCaseParams> pcplist) throws InterruptedException {
=======
>>>>>>> origin/master
// 把公共参数加入到MAP中
for (PublicCaseParams pcp : pcplist) {
variable.put(pcp.getParamsname(), pcp.getParamsvalue());
@ -208,8 +219,102 @@ public class WebCaseExecution extends TestCaseExecution {
String expectedResults = params.get("ExpectedResults");
expectedResults = ChangString.changparams(expectedResults, variable, "预期结果");
<<<<<<< HEAD
// 判断结果
if (0 != judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog)) break;
=======
// 赋值传参模式
if (expectedResults.length() > ASSIGNMENT_SIGN.length() && expectedResults.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expectedResults.substring(ASSIGNMENT_SIGN.length()), result);
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,将测试结果【" + result + "】赋值给变量【" + expectedResults.substring(ASSIGNMENT_SIGN.length()) + "");
caselog.caseLogDetail(taskid, testcase.getSign(), "将测试结果【" + result + "】赋值给变量【" + expectedResults.substring(ASSIGNMENT_SIGN.length()) + "", "info", String.valueOf(step.getStepnum()), "");
}
// WebUI检查模式
else if (params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
String checkproperty = params.get("checkproperty");
String checkPropertyValue = params.get("checkproperty_value");
WebElement we = isElementExist(wd, checkproperty, checkPropertyValue);
if (null != we) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
caselog.caseLogDetail(taskid, testcase.getSign(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepnum()), "");
} else {
casenote = "" + step.getStepnum() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.webScreenShot(wd, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
caselog.caseLogDetail(taskid, testcase.getSign(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "", "error", String.valueOf(step.getStepnum()), imagname);
break;
}
}
// 其它匹配模式
else {
// 模糊匹配预期结果模式
if (expectedResults.length() > FUZZY_MATCHING_SIGN.length() && expectedResults.startsWith(FUZZY_MATCHING_SIGN)) {
if (result.contains(expectedResults.substring(FUZZY_MATCHING_SIGN.length()))) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,模糊匹配预期结果成功!执行结果:" + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepnum()), "");
} else {
casenote = "" + step.getStepnum() + "步,模糊匹配预期结果失败!";
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.webScreenShot(wd, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,模糊匹配预期结果失败!预期结果:" + expectedResults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "模糊匹配预期结果失败!预期结果:" + expectedResults.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepnum()), imagname);
break;
}
}
// 正则匹配预期结果模式
else if (expectedResults.length() > REGULAR_MATCHING_SIGN.length() && expectedResults.startsWith(REGULAR_MATCHING_SIGN)) {
Pattern pattern = Pattern.compile(expectedResults.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(result);
if (matcher.find()) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,正则匹配预期结果成功!执行结果:" + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepnum()), "");
} else {
casenote = "" + step.getStepnum() + "步,正则匹配预期结果失败!";
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.webScreenShot(wd, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,正则匹配预期结果失败!预期结果:" + expectedResults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "正则匹配预期结果失败!预期结果:" + expectedResults.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepnum()), imagname);
break;
}
}
// 精确匹配预期结果模式
else {
if (expectedResults.equals(result)) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,精确匹配预期结果成功!执行结果:" + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepnum()), "");
} else {
casenote = "" + step.getStepnum() + "步,精确匹配预期结果失败!";
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.webScreenShot(wd, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,精确匹配预期结果失败!执行结果:" + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "精确匹配预期结果失败!执行结果:" + result, "error", String.valueOf(step.getStepnum()), imagname);
break;
}
}
}
}
} else {
casenote = (null != result) ? result : "";
setresult = 2;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.webScreenShot(wd, imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum() + "步," + result);
caselog.caseLogDetail(taskid, testcase.getSign(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + result,
"error", String.valueOf(step.getStepnum()), imagname);
break;
}
>>>>>>> origin/master
}
variable.clear();
@ -301,11 +406,16 @@ public class WebCaseExecution extends TestCaseExecution {
return "元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
<<<<<<< HEAD
if (result.contains("失败")) caselog.caseLogDetail(taskid, casenum, result, "error", String.valueOf(stepno), "");
else caselog.caseLogDetail(taskid, casenum, result, "info", String.valueOf(stepno), "");
if (result.contains("获取到的值是【") && result.contains("")) {
result = result.substring(7, result.length() - 1);
=======
if (result.indexOf("获取到的值是【") > -1 && result.indexOf("") > -1) {
result = result.substring(result.indexOf("获取到的值是【")+7, result.length() - 1);
>>>>>>> origin/master
}
return result;
@ -501,6 +611,7 @@ public class WebCaseExecution extends TestCaseExecution {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
}

View File

@ -58,7 +58,7 @@ public class WebDriverAnalyticCase {
String expectedResults = subComment(resultstr);
//处理check字段
if(expectedResults.indexOf("check(")>-1){
if(expectedResults.startsWith("check(")){
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("=")));
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
}

View File

@ -12,7 +12,7 @@ import luckyclient.dblog.LogOperation;
* =================================================================
*
* @author£º seagull
* @date 2017年12月1日 上午9:29:40
* @date 2018年3月1日
*/
public class MailSendInitialization {
@ -38,6 +38,7 @@ public class MailSendInitialization {
//ÄÚÈÝ
mailInfo.setContent(content);
mailInfo.setToAddresses(addresses);
//sms.sendHtmlMail(mailInfo);
StringBuilder stringBuilder = new StringBuilder();
for (String address : addresses) {

View File

@ -71,6 +71,7 @@ public class InvokeMethod {
return "协议模板为空,请确认用例使用的模板是否已经删除!";
}
<<<<<<< HEAD
String httpptp = HttpRequest.loadJSON("/projectTemplateParams/cgetParamsByTemplate.do?templateid=" + templateidstr);
JSONObject jsonptpObject = JSONObject.fromObject(httpptp);
JSONArray jsonarr = JSONArray.fromObject(jsonptpObject.getString("params"));
@ -101,6 +102,41 @@ public class InvokeMethod {
@SuppressWarnings("unchecked")
List<ProjectTemplateParams> paramslist = JSONArray.toList(jsonarr, new ProjectTemplateParams(),
new JsonConfig());
=======
String httpptp = HttpRequest
.loadJSON("/projectTemplateParams/cgetParamsByTemplate.do?templateid=" + templateidstr);
JSONObject jsonptpObject = JSONObject.fromObject(httpptp.toString());
JSONArray jsonarr = JSONArray.fromObject(jsonptpObject.getString("params"));
//处理json-lib 2.4版本当遇到json格式字符串时把它当成对象处理的bug
for(int i=0;i<jsonarr.size();i++){
JSONObject tempobj=(JSONObject) jsonarr.get(i);
String str=tempobj.get("param").toString();
if(str.length()>0&&"[".equals(str.substring(0, 1))&&"]".equals(str.substring(str.length()-1))){
tempobj.element("param", "***"+str);
jsonarr.set(i, tempobj);
}
}
//处理头域
Map<String, String> headmsg = new HashMap<String, String>(0);
if(null!=ppt.getHeadmsg()&&!ppt.getHeadmsg().equals("")&&ppt.getHeadmsg().indexOf("=")>0){
String headmsgtemp=ppt.getHeadmsg().replaceAll("\\\\;", "!!!fhzh");
String[] temp=headmsgtemp.split(";",-1);
for(int i=0;i<temp.length;i++){
if(null!=temp[i]&&!temp[i].equals("")&&temp[i].indexOf("=")>0){
String key=temp[i].substring(0, temp[i].indexOf("="));
String value=temp[i].substring(temp[i].indexOf("=")+1);
value=value.replaceAll("!!!fhzh",";");
headmsg.put(key, value);
}
}
}
@SuppressWarnings("unchecked")
List<ProjectTemplateParams> paramslist = JSONArray.toList(jsonarr, new ProjectTemplateParams(),
new JsonConfig());
>>>>>>> origin/master
//处理更换参数
if (null != getParameterValues) {
String booleanheadmsg = "headmsg(";
@ -215,6 +251,7 @@ public class InvokeMethod {
}
}
<<<<<<< HEAD
//处理头域
Map<String, String> headmsg = new HashMap<String, String>(0);
if (null != ppt.getHeadmsg() && !ppt.getHeadmsg().equals("") && ppt.getHeadmsg().indexOf("=") > 0) {
@ -230,6 +267,41 @@ public class InvokeMethod {
@SuppressWarnings("unchecked")
List<ProjectTemplateParams> paramslist = JSONArray.toList(jsonarr, new ProjectTemplateParams(), new JsonConfig());
=======
String httpptp = HttpRequest
.loadJSON("/projectTemplateParams/cgetParamsByTemplate.do?templateid=" + templateidstr);
JSONObject jsonptpObject = JSONObject.fromObject(httpptp.toString());
JSONArray jsonarr = JSONArray.fromObject(jsonptpObject.getString("params"));
//处理json-lib 2.4版本当遇到json格式字符串时把它当成对象处理的bug
for(int i=0;i<jsonarr.size();i++){
JSONObject tempobj=(JSONObject) jsonarr.get(i);
String str=tempobj.get("param").toString();
if(str.length()>0&&"[".equals(str.substring(0, 1))&&"]".equals(str.substring(str.length()-1))){
tempobj.element("param", "***"+str);
jsonarr.set(i, tempobj);
}
}
//处理头域
Map<String, String> headmsg = new HashMap<String, String>(0);
if(null!=ppt.getHeadmsg()&&!ppt.getHeadmsg().equals("")&&ppt.getHeadmsg().indexOf("=")>0){
String headmsgtemp=ppt.getHeadmsg().replaceAll("\\\\;", "!!!fhzh");
String[] temp=headmsgtemp.split(";",-1);
for(int i=0;i<temp.length;i++){
if(null!=temp[i]&&!temp[i].equals("")&&temp[i].indexOf("=")>0){
String key=temp[i].substring(0, temp[i].indexOf("="));
String value=temp[i].substring(temp[i].indexOf("=")+1);
value=value.replaceAll("!!!fhzh",";");
headmsg.put(key, value);
}
}
}
@SuppressWarnings("unchecked")
List<ProjectTemplateParams> paramslist = JSONArray.toList(jsonarr, new ProjectTemplateParams(),
new JsonConfig());
>>>>>>> origin/master
//处理更换参数
if (null != getParameterValues) {
String booleanheadmsg = "headmsg(";
@ -333,9 +405,15 @@ public class InvokeMethod {
return true;
}
<<<<<<< HEAD
public static void main(String[] args) {
// TODO Auto-generated method stub
}
=======
public static void main(String[] args) {
// TODO Auto-generated method stub
}
>>>>>>> origin/master
}

View File

@ -229,37 +229,6 @@ public class TestCaseApi extends TestLinkBaseApi {
}
/**
* 更新系统中用例指定步骤的预期结果
*/
public static String setExpectedResults(String testCaseSign, int steps, String expectedResults) {
String results = "设置结果失败";
String params="";
try {
expectedResults = expectedResults.replace("%", "BBFFHH");
expectedResults = expectedResults.replace("=", "DHDHDH");
expectedResults = expectedResults.replace("&", "ANDAND");
params="caseno="+testCaseSign;
params+="&stepnum="+steps;
params+="&expectedresults="+expectedResults;
results=HttpRequest.sendPost("/projectCasesteps/cUpdateStepExpectedResults.do", params);
} catch (TestLinkAPIException te) {
te.printStackTrace(System.err);
results = te.getMessage().toString();
return results;
}
return results;
}
/**
* 获取指定任务名称以及用例号报错日志中的执行测试结果
* casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogDetailRunresult(String taskname,String caseno,int casestatus){
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailTestResult(taskid, caseno,casestatus);
}
/**
* 拷贝测试用例到系统自带用例库中 接口自动化用例
@ -428,14 +397,6 @@ public class TestCaseApi extends TestLinkBaseApi {
System.out.println(testplan+"中的用例已经全部生成完毕!");
}
/**
* 获取指定任务名称以及用例号报错日志中的执行预期结果
* casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogDetailExpectresult(String taskname,String caseno,int casestatus){
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailExpectResult(taskid, caseno,casestatus);
}
public static void main(String[] args){