1:根据alibaba JAVA代码规范优化部分代码

2:增加公共参数功能
3:取消单个参数三次引用变量的限制,优化控制逻辑
4:增加包路径、方法名、参数、预期结果全路径引用参数,当遇到局部变量与全局变量同名时,优先使用局部变量 
5:其他代码逻辑结构上的优化
This commit is contained in:
seagull 2017-12-04 11:24:19 +08:00
parent b2297473df
commit c02ce414ea
80 changed files with 2126 additions and 1757 deletions

View File

@ -10,7 +10,17 @@ import luckyclient.caserun.exwebdriver.extestlink.WebBatchExecuteTestLink;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.TestTaskexcute;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class BatchCaseExecute extends TestControl{
public static void main(String[] args) {
@ -23,15 +33,18 @@ public class BatchCaseExecute extends TestControl{
TestTaskexcute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
if(task.getTestJob().getExtype()==0){
if(task.getTestJob().getProjecttype()==1){
BatchTestLinkCaseExecution.BatchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase); //½Ó¿Ú²âÊÔ
//接口测试
BatchTestLinkCaseExecution.batchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase);
}else if(task.getTestJob().getProjecttype()==0){
BatchTestCaseExecution.BatchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase);
BatchTestCaseExecution.batchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase);
}
}else if(task.getTestJob().getExtype()==1){
if(task.getTestJob().getProjecttype()==1){
WebBatchExecuteTestLink.BatchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase); //UI²âÊÔ
//UI测试
WebBatchExecuteTestLink.batchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase);
}else if(task.getTestJob().getProjecttype()==0){
WebBatchExecute.BatchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase); //UI²âÊÔ
//UI测试
WebBatchExecute.batchCaseExecuteForTast(task.getTestJob().getPlanproj(), String.valueOf(task.getId()), batchcase);
}
}

View File

@ -10,7 +10,17 @@ import luckyclient.caserun.exwebdriver.extestlink.WebOneCaseExecuteTestLink;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.TestTaskexcute;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class OneCaseExecute extends TestControl{
public static void main(String[] args) throws Exception {
@ -23,16 +33,19 @@ public class OneCaseExecute extends TestControl{
TestTaskexcute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
if(task.getTestJob().getExtype()==0){
if(task.getTestJob().getProjecttype()==1){
TestLinkCaseExecution.OneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId())); //testlink½Ó¿Ú²âÊÔ
//testlink接口测试
TestLinkCaseExecution.oneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId()));
}else if(task.getTestJob().getProjecttype()==0){
TestCaseExecution.OneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId())); //½Ó¿Ú²âÊÔ
//接口测试
TestCaseExecution.oneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId()));
}
}else if(task.getTestJob().getExtype()==1){
if(task.getTestJob().getProjecttype()==1){
WebOneCaseExecuteTestLink.OneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId())); //UI²âÊÔ
//UI测试
WebOneCaseExecuteTestLink.oneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId()));
}else if(task.getTestJob().getProjecttype()==0){
WebOneCaseExecute.OneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId())); //UI²âÊÔ
WebOneCaseExecute.oneCaseExecuteForTast(task.getTestJob().getPlanproj(), testCaseExternalId,version,String.valueOf(task.getId()));
}
}

View File

@ -7,7 +7,17 @@ import luckyclient.caserun.exwebdriver.WebTestControl;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.TestTaskexcute;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class RunAutomationTest extends TestControl{
public static void main(String[] args) {
// TODO Auto-generated method stub
@ -16,10 +26,13 @@ public class RunAutomationTest extends TestControl{
+ "\\log4j.conf");
String taskid = args[0];
TestTaskexcute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
if(task.getTestJob().getExtype()==0){
TestControl.TastExecutionPlan(taskid, task); //½Ó¿Ú²âÊÔ
//接口测试
TestControl.taskExecutionPlan(taskid, task);
}else if(task.getTestJob().getExtype()==1){
WebTestControl.TaskExecutionPlan(taskid, task); //UI²âÊÔ
//UI测试
WebTestControl.taskExecutionPlan(taskid, task);
}
} catch (Exception e) {

View File

@ -5,7 +5,17 @@ import org.apache.log4j.PropertyConfigurator;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exinterface.WebTestCaseDebug;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebDebugExecute extends TestControl{
public static void main(String[] args) throws Exception {
@ -14,6 +24,6 @@ public class WebDebugExecute extends TestControl{
+ "\\log4j.conf");
String sign = args[0];
String executor = args[1];
WebTestCaseDebug.OneCaseDebug(sign,executor);
WebTestCaseDebug.oneCaseDebug(sign,executor);
}
}

View File

@ -1,5 +1,16 @@
package luckyclient.caserun.exappium;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class AppiumForWebView {
/*
public static void FindWebView(){

View File

@ -11,6 +11,17 @@ import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.remote.Augmenter;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class BaseAppium {
/**
@ -18,7 +29,7 @@ public class BaseAppium {
* @throws IOException
* 手机报错截图
*/
public static void APPScreenShot(AppiumDriver driver,String workpath) throws IOException{
public static void aPPScreenShot(AppiumDriver driver,String workpath) throws IOException{
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
String time = timeformat.format(new Date())+".jpg";
try {

View File

@ -4,6 +4,17 @@ import io.appium.java_client.AppiumDriver;
import java.io.IOException;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class InputWord {
/**
* @param args
@ -11,7 +22,7 @@ public class InputWord {
* appium不支持中文输入 参考了robotium的以js方式为元素直接设置value的做法
* 利用Selenium中Webdriver执行js方法实现中文输入
*/
public static void SendChinese(AppiumDriver appium,String preferences,String value){
public static void sendChinese(AppiumDriver appium,String preferences,String value){
org.openqa.selenium.JavascriptExecutor jse = (org.openqa.selenium.JavascriptExecutor) appium;
jse.executeScript("document.getElementByName('"+preferences+"').value='"+value+"'");
}

View File

@ -12,21 +12,39 @@ import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class PublicAppium extends BaseAppium{
//³õʼ»¯ÔÏó
/**
* 初始化appium
*/
@SuppressWarnings("rawtypes")
public static AppiumDriver setUpAppium(String apkname,String version,String apppackage,String appactivity){
AppiumDriver appium = null;
File app=new File(System.getProperty("user.dir")+"//"+apkname); //"MobilePayment.apk"
//"MobilePayment.apk"
File app=new File(System.getProperty("user.dir")+"//"+apkname);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, version); //"4.2.2"
//"4.2.2"
capabilities.setCapability(CapabilityType.VERSION, version);
capabilities.setCapability(CapabilityType.PLATFORM, "Android");
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("app-package", apppackage); //"com.ysepay.mobileportal.activity"
capabilities.setCapability("app-activity", appactivity); //"com.ysepay.mobileportal.IndexActivity"
//"com.ysepay.mobileportal.activity"
capabilities.setCapability("app-package", apppackage);
//"com.ysepay.mobileportal.IndexActivity"
capabilities.setCapability("app-activity", appactivity);
try {
appium = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {

View File

@ -7,13 +7,24 @@ import org.openqa.selenium.JavascriptExecutor;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
class SwipeDriver {
/**
* @param args
* TouchAction 支持对触屏的部分操作
*/
private static TouchAction SwipeTouchAction(AppiumDriver appium){
private static TouchAction swipeTouchAction(AppiumDriver appium){
TouchAction swipetouch = new TouchAction(appium);
return swipetouch;
}
@ -22,14 +33,14 @@ class SwipeDriver {
* @param args
* js webview 支持4.14.4
*/
private static void webview_swipe(AppiumDriver appium, Double sX, Double sY,
private static void webViewSwipe(AppiumDriver appium, Double sX, Double sY,
Double eX, Double eY, Double duration) throws Exception {
JavascriptExecutor js;
HashMap<String, Double> swipeObject;
try {
// 滑动
js = (JavascriptExecutor) appium;
swipeObject = new HashMap<String, Double>();
swipeObject = new HashMap<String, Double>(5);
swipeObject.put("startX", sX);
swipeObject.put("startY", sY);
swipeObject.put("endX", eX);
@ -82,23 +93,23 @@ class SwipeDriver {
* @param args
* 调用 ADB直接滑动 支持4.14.4
*/
private static void adb_swipe(AppiumDriver appium, Double sX, Double sY,
private static void adbSwipe(AppiumDriver appium, Double sX, Double sY,
Double eX, Double eY) throws Exception {
int X;
int Y;
int xLine;
int yLine;
int sX2;
int sY2;
int eX2;
int eY2;
try {
// 滑动
X = appium.manage().window().getSize().getWidth();
Y = appium.manage().window().getSize().getHeight();
xLine = appium.manage().window().getSize().getWidth();
yLine = appium.manage().window().getSize().getHeight();
sX2 = (int) (X * sX);
sY2 = (int) (Y * sY);
eX2 = (int) (X * eX);
eY2 = (int) (Y * eY);
sX2 = (int) (xLine * sX);
sY2 = (int) (yLine * sY);
eX2 = (int) (xLine * eX);
eY2 = (int) (yLine * eY);
// logger.info("滑动11111111");
Runtime.getRuntime().exec(
"adb -s " + "Android" + " shell input swipe " + sX2 + " "
@ -119,7 +130,7 @@ class SwipeDriver {
*/
private static void clickScreen(AppiumDriver drivers,int x, int y, int duration) {
JavascriptExecutor js = (JavascriptExecutor) drivers;
HashMap<String, Integer> tapObject = new HashMap<String, Integer>();
HashMap<String, Integer> tapObject = new HashMap<String, Integer>(3);
tapObject.put("x", x);
tapObject.put("y", y);
tapObject.put("duration", duration);

View File

@ -5,17 +5,19 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import luckyclient.caserun.exinterface.AnalyticSteps.InterfaceAnalyticCase;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
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.DBOperation;
import luckyclient.publicclass.InvokeMethod;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: TestCaseDebug
* @Description: 针对自动化用例在编写过程中对用例脚本进行调试
@ -31,7 +33,7 @@ public class ApiTestCaseDebug{
* @param 用例版本号
* 用于在testlink上配置好用例参数后做单条用例调试
*/
public static void OneCaseDebug(String projectname,String testCaseExternalId){
public static void oneCaseDebug(String projectname,String testCaseExternalId){
Map<String,String> variable = new HashMap<String,String>();
String packagename =null;
String functionname = null;
@ -41,129 +43,48 @@ public class ApiTestCaseDebug{
String testnote = null;
int k = 0;
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());
//进入循环解析用例所有步骤
for(int i=0;i<steps.size();i++){
Map<String,String> casescript = InterfaceAnalyticCase.AnalyticCaseStep(testcaseob, steps.get(i),"888888",null); //解析单个步骤中的脚本
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
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(); //预期结果
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){ //页面转义字符转换
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
expectedresults = casescript.get("ExpectedResults").toString();
expectedresults = ChangString.changparams(expectedresults, variable,"预期结果");
//判断方法是否带参数
if(casescript.size()>4){
//获取传入参数放入对象中
getParameterValues = new Object[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;
}
if(casescript.get("FunctionParams"+(j+1)).indexOf("@")>-1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){ //如果存在传参进行处理
int keyexistidentity = 0;
//取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams"+(j+1)), "@");
String uservariable = null;
String uservariable1 = null;
String uservariable2 = null;
if(sumvariable==1){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).indexOf("@")+1);
}else if(sumvariable==2){ //单个参数中引用第二个变量
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@")+1);
}else if(sumvariable==3){
String temp = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = temp.substring(temp.indexOf("@")+1);
uservariable2 = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@")+1);
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).indexOf(uservariable1)-1);
}else{
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
String key = null;
while(keys.hasNext()){
key = (String)keys.next();
if(uservariable.indexOf(key)>-1){
keyexistidentity = 1;
uservariable = key;
break;
}
}
if(sumvariable==2||sumvariable==3){ //处理第二个传参
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
key = (String)keys.next();
if(uservariable1.indexOf(key)>-1){
keyexistidentity = 1;
uservariable1 = key;
break;
}
}
}
if(sumvariable==3){ //处理第三个传参
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
key = (String)keys.next();
if(uservariable2.indexOf(key)>-1){
keyexistidentity = 1;
uservariable2 = key;
break;
}
}
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
getParameterValues[j] = ParameterValues;
}else{
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
getParameterValues[j] = ParameterValues1;
}
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;
@ -171,12 +92,14 @@ public class ApiTestCaseDebug{
//调用动态方法执行测试用例
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(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+",与预期结果匹配成功!");
@ -188,7 +111,7 @@ public class ApiTestCaseDebug{
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
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+",与预期结果匹配成功!");
@ -200,7 +123,8 @@ public class ApiTestCaseDebug{
break; //某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); //获取步骤间等待时间
//获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}
@ -233,7 +157,7 @@ public class ApiTestCaseDebug{
* @param 用例版本号
* 用于在testlink上配置好用例参数后做多条用例串行调试
*/
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();
@ -244,7 +168,7 @@ public class ApiTestCaseDebug{
Integer version = (Integer)entry.getValue();
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:"+testCaseExternalId+",用例版本:"+version);
OneCaseDebug(projectname,testCaseExternalId);
oneCaseDebug(projectname,testCaseExternalId);
}catch(Exception e){
continue;
}

View File

@ -9,6 +9,17 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class BatchTestCaseExecution {
/**
@ -17,16 +28,18 @@ public class BatchTestCaseExecution {
* 创建线程池多线程执行用例
*/
public static void BatchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws Exception{
public static void batchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws Exception{
TestTaskexcute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
int threadcount = task.getTestJob().getThreadCount();
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 30, 3, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(1000),
new ThreadPoolExecutor.CallerRunsPolicy());
if(batchcase.indexOf("ALLFAIL")>-1){ //执行全部非成功状态用例
LogOperation caselog = new LogOperation(); //初始化写用例结果以及日志模块
String casemore = caselog.UnSucCaseUpdate(taskid);
String temp[]=casemore.split("\\#",-1);
//执行全部非成功状态用例
if(batchcase.indexOf("ALLFAIL")>-1){
//初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp=casemore.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()-1));
@ -34,7 +47,7 @@ public class BatchTestCaseExecution {
threadExecute.execute(new ThreadForBatchCase(projectname,testCaseExternalId,version,taskid));
}
}else{ //批量执行用例
String temp[]=batchcase.split("\\#",-1);
String[] temp=batchcase.split("\\#",-1);
for(int i=0;i<temp.length-1;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()));
@ -56,7 +69,6 @@ public class BatchTestCaseExecution {
public static void main(String[] args) {
// TODO Auto-generated method stub
// BatchTestCaseExecution.BatchCaseExecuteForTast("清算项目", "35", "ALLFAIL");
}
}

View File

@ -1,20 +1,30 @@
package luckyclient.caserun.exinterface;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exinterface.AnalyticSteps.InterfaceAnalyticCase;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.dblog.DbLink;
import luckyclient.dblog.LogOperation;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.publicclass.DBOperation;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.publicclass.ChangString;
import luckyclient.publicclass.InvokeMethod;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class TestCaseExecution {
/**
* @param 项目名
@ -23,12 +33,13 @@ public class TestCaseExecution {
* 用于单条用例调试并通过日志框架写日志到UTP上用做UTP上单条用例运行
*/
@SuppressWarnings("static-access")
public static void OneCaseExecuteForTast(String projectname, String testCaseExternalId, int version,
public static void oneCaseExecuteForTast(String projectname, String testCaseExternalId, int version,
String taskid) {
Map<String, String> variable = new HashMap<String, String>();
TestControl.TASKID = taskid;
DbLink.exetype = 0;
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
// 初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
String packagename = null;
String functionname = null;
String expectedresults = null;
@ -36,149 +47,56 @@ public class TestCaseExecution {
Object[] getParameterValues = null;
String testnote = null;
int k = 0;
caselog.DeleteCaseLogDetail(testCaseExternalId, taskid); // 删除旧的日志
// 删除旧的日志
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());
// 进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
Map<String, String> casescript = InterfaceAnalyticCase.AnalyticCaseStep(testcaseob, steps.get(i), taskid,caselog); // 解析单个步骤中的脚本
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcaseob, steps.get(i), taskid,caselog);
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() + "解析包名或是方法名失败,请检查!");
caselog.caseLogDetail(taskid, testcaseob.getSign(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
}
// 用例名称解析出现异常或是单个步骤参数解析异常
if (functionname.indexOf("解析异常") > -1 || k == 1) {
k = 0;
testnote = "用例第" + (i + 1) + "步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); // 预期结果
if (expectedresults.indexOf("&quot;") > -1 || expectedresults.indexOf("&#39;") > -1) { // 页面转义字符转换
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
expectedresults = casescript.get("ExpectedResults").toString();
expectedresults = ChangString.changparams(expectedresults, variable,"预期结果");
// 判断方法是否带参数
if (casescript.size() > 4) {
// 获取传入参数放入对象中
getParameterValues = new Object[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;
}
if (casescript.get("FunctionParams" + (j + 1)).indexOf("@") > -1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0) { // 如果存在传参进行处理
int keyexistidentity = 0;
// 取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams" + (j + 1)), "@");
String uservariable = null;
String uservariable1 = null;
String uservariable2 = null;
if (sumvariable == 1) {
uservariable = casescript.get("FunctionParams" + (j + 1))
.substring(casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1);
} else if (sumvariable == 2) { // 单个参数中引用第二个变量
uservariable = casescript.get("FunctionParams" + (j + 1)).substring(
casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1,
casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams" + (j + 1))
.substring(casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@") + 1);
} else if (sumvariable == 3) {
String temp = casescript.get("FunctionParams" + (j + 1)).substring(
casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1,
casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@"));
uservariable1 = temp.substring(temp.indexOf("@") + 1);
uservariable2 = casescript.get("FunctionParams" + (j + 1))
.substring(casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@") + 1);
uservariable = casescript.get("FunctionParams" + (j + 1)).substring(
casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1,
casescript.get("FunctionParams" + (j + 1)).indexOf(uservariable1) - 1);
} else {
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "你好像在一个参数中引用了超过2个以上的变量哦我处理不过来啦",
"error", String.valueOf(i + 1));
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
String key = null;
while (keys.hasNext()) {
key = (String) keys.next();
if (uservariable.indexOf(key)>-1) {
keyexistidentity = 1;
uservariable = key;
break;
}
}
if (sumvariable == 2 || sumvariable == 3) { // 处理第二个传参
keys = variable.keySet().iterator();
while (keys.hasNext()) {
keyexistidentity = 0;
key = (String) keys.next();
if (uservariable.indexOf(key)>-1) {
keyexistidentity = 1;
uservariable1 = key;
break;
}
}
}
if (sumvariable == 3) { // 处理第三个传参
keys = variable.keySet().iterator();
while (keys.hasNext()) {
keyexistidentity = 0;
key = (String) keys.next();
if (uservariable.indexOf(key)>-1) {
keyexistidentity = 1;
uservariable2 = key;
break;
}
}
}
if (keyexistidentity == 1) {
// 拼装参数传参+原有字符串
String ParameterValues = casescript.get("FunctionParams" + (j + 1))
.replaceAll("@" + uservariable, variable.get(uservariable).toString());
// 处理第二个传参
if (sumvariable == 2 || sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable1,
variable.get(uservariable1).toString());
}
// 处理第三个传参
if (sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable2,
variable.get(uservariable2).toString());
}
if (ParameterValues.indexOf("&quot;") > -1 || ParameterValues.indexOf("&#39;") > -1) { // 页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:" + packagename + " 方法名:" + functionname
+ "" + (j + 1) + "个参数:" + ParameterValues);
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "解析包名:" + packagename + " 方法名:"
+ functionname + "" + (j + 1) + "个参数:" + ParameterValues, "info",
String.valueOf(i + 1));
getParameterValues[j] = ParameterValues;
} else {
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:" + uservariable + ",第"
+ "二个变量名称是:" + uservariable1 + ",第三个变量名称是:" + uservariable2);
caselog.UpdateCaseLogDetail(testCaseExternalId,
taskid, "没有找到你要的变量哦,再找下吧!第二变量名称是:" + uservariable + ",第" + "二个变量名称是:"
+ uservariable1 + ",第三个变量名称是:" + uservariable2,
"error", String.valueOf(i + 1));
}
} else {
String ParameterValues1 = casescript.get("FunctionParams" + (j + 1));
if (ParameterValues1.indexOf("&quot;") > -1 || ParameterValues1.indexOf("&#39;") > -1 || ParameterValues1.indexOf("@@")>-1) { // 页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:" + packagename + " 方法名:" + functionname + ""
+ (j + 1) + "个参数:" + ParameterValues1);
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "解析包名:" + packagename + " 方法名:"
+ functionname + "" + (j + 1) + "个参数:" + ParameterValues1, "info",
String.valueOf(i + 1));
getParameterValues[j] = ParameterValues1;
}
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;
@ -186,23 +104,24 @@ public class TestCaseExecution {
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:" + functionname + " .....");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "开始调用方法:" + functionname + " .....", "info",
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "开始调用方法:" + functionname + " .....", "info",
String.valueOf(i + 1));
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 (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 + ",与预期结果匹配成功!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "用例执行结果是:" + testnote + ",与预期结果匹配成功!",
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "用例执行结果是:" + testnote + ",与预期结果匹配成功!",
"info", String.valueOf(i + 1));
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例第" + (i + 1) + "步执行结果与预期结果匹配失败!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid,
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid,
"用例第" + (i + 1) + "步执行结果与预期结果匹配失败!预期结果:" + expectedresults + " 测试结果:" + testnote,
"error", String.valueOf(i + 1));
luckyclient.publicclass.LogUtil.APP.error("预期结果:" + expectedresults + " 测试结果:" + testnote);
@ -210,16 +129,16 @@ public class TestCaseExecution {
break; // 某一步骤失败后此条用例置为失败退出
}
} else { // 把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename, functionname, getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
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 + ",与预期结果匹配成功!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "用例执行结果是:" + testnote + ",与预期结果匹配成功!",
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "用例执行结果是:" + testnote + ",与预期结果匹配成功!",
"info", String.valueOf(i + 1));
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例第" + (i + 1) + "步执行结果与预期结果匹配失败!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid,
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid,
"用例第" + (i + 1) + "步执行结果与预期结果匹配失败!预期结果:" + expectedresults + " 测试结果:" + testnote,
"error", String.valueOf(i + 1));
luckyclient.publicclass.LogUtil.APP.error("预期结果:" + expectedresults + " 测试结果:" + testnote);
@ -228,13 +147,14 @@ public class TestCaseExecution {
break; // 某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); // 获取步骤间等待时间
// 获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if (waitsec != 0) {
Thread.sleep(waitsec * 1000);
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid,
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid,
"调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1));
luckyclient.publicclass.LogUtil.APP.error(e, e);
testnote = "CallCase调用出错";
@ -247,29 +167,29 @@ public class TestCaseExecution {
// 如果调用方法过程中未出错进入设置测试结果流程
if (testnote.indexOf("CallCase调用出错") <= -1 && testnote.indexOf("解析出错啦!") <= -1) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testCaseExternalId + "解析成功,并成功调用用例中方法,请继续查看执行结果!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info",
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info",
"SETCASERESULT...");
// TCResult =
// TestCaseApi.setTCResult(projectname,testCaseExternalId, testnote,
// version,setresult);
caselog.UpdateCaseDetail(taskid, testCaseExternalId, setresult);
caselog.updateCaseDetail(taskid, testCaseExternalId, setresult);
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "解析或是调用步骤中的方法出错!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "解析或是调用步骤中的方法出错!", "error", "SETCASERESULT...");
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "解析或是调用步骤中的方法出错!", "error", "SETCASERESULT...");
// TCResult =
// TestCaseApi.setTCResult(projectname,testCaseExternalId, testnote,
// version,2);
caselog.UpdateCaseDetail(taskid, testCaseExternalId, 2);
caselog.updateCaseDetail(taskid, testCaseExternalId, 2);
}
if (0 == setresult) {
luckyclient.publicclass.LogUtil.APP.info("用例 " + testCaseExternalId + "步骤全部执行成功!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "步骤全部执行成功!", "info", "EXECUTECASESUC...");
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "步骤全部执行成功!", "info", "EXECUTECASESUC...");
} else {
luckyclient.publicclass.LogUtil.APP.error("用例 " + testCaseExternalId + "在执行过程中失败,请检查日志!");
caselog.UpdateCaseLogDetail(testCaseExternalId, taskid, "在执行过程中失败,请检查日志!", "error", "EXECUTECASESUC...");
LogOperation.updateCaseLogDetail(testCaseExternalId, taskid, "在执行过程中失败,请检查日志!", "error", "EXECUTECASESUC...");
}
LogOperation.UpdateTastdetail(taskid, 0);
LogOperation.updateTastdetail(taskid, 0);
}
/**
@ -278,7 +198,7 @@ public class TestCaseExecution {
* @param 用例版本号
* 用于在UI的测试过程中需要调用接口的测试用例
*/
protected static String OneCaseExecuteForWebDriver(String testCaseExternalId, String taskid,LogOperation caselog) {
protected static String oneCaseExecuteForWebDriver(String testCaseExternalId, String taskid,LogOperation caselog) {
Map<String, String> variable = new HashMap<String, String>();
String packagename = null;
String functionname = null;
@ -288,135 +208,54 @@ public class TestCaseExecution {
String testnote = null;
int k = 0;
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());
// 进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
Map<String, String> casescript = InterfaceAnalyticCase.AnalyticCaseStep(testcaseob, steps.get(i), taskid,caselog);
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcaseob, steps.get(i), taskid,caselog);
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() + "解析包名或是方法名失败,请检查!");
caselog.caseLogDetail(taskid, testcaseob.getSign(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
e.printStackTrace();
break; // 某一步骤失败后此条用例置为失败退出
}
// 用例名称解析出现异常或是单个步骤参数解析异常
if (functionname.indexOf("解析异常") > -1 || k == 1) {
k = 0;
testnote = "用例第" + (i + 1) + "步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); // 预期结果
if (expectedresults.indexOf("&quot;") > -1 || expectedresults.indexOf("&#39;") > -1) { // 页面转义字符转换
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
expectedresults = casescript.get("ExpectedResults").toString();
expectedresults = ChangString.changparams(expectedresults, variable,"预期结果");
// 判断方法是否带参数
if (casescript.size() > 4) {
// 获取传入参数放入对象中
getParameterValues = new Object[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;
}
if (casescript.get("FunctionParams" + (j + 1)).indexOf("@") > -1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0) { // 如果存在传参进行处理
int keyexistidentity = 0;
// 取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams" + (j + 1)), "@");
String uservariable = null;
String uservariable1 = null;
String uservariable2 = null;
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;
if (sumvariable == 1) {
uservariable = casescript.get("FunctionParams" + (j + 1))
.substring(casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1);
} else if (sumvariable == 2) { // 单个参数中引用第二个变量
uservariable = casescript.get("FunctionParams" + (j + 1)).substring(
casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1,
casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams" + (j + 1))
.substring(casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@") + 1);
} else if (sumvariable == 3) {
String temp = casescript.get("FunctionParams" + (j + 1)).substring(
casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1,
casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@"));
uservariable1 = temp.substring(temp.indexOf("@") + 1);
uservariable2 = casescript.get("FunctionParams" + (j + 1))
.substring(casescript.get("FunctionParams" + (j + 1)).lastIndexOf("@") + 1);
uservariable = casescript.get("FunctionParams" + (j + 1)).substring(
casescript.get("FunctionParams" + (j + 1)).indexOf("@") + 1,
casescript.get("FunctionParams" + (j + 1)).indexOf(uservariable1) - 1);
} else {
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
String key = null;
while (keys.hasNext()) {
key = (String) keys.next();
if (uservariable.indexOf(key) > -1) {
keyexistidentity = 1;
uservariable = key;
break;
}
}
if (sumvariable == 2 || sumvariable == 3) { // 处理第二个传参
keys = variable.keySet().iterator();
while (keys.hasNext()) {
keyexistidentity = 0;
key = (String) keys.next();
if (uservariable1.indexOf(key) > -1) {
keyexistidentity = 1;
uservariable1 = key;
break;
}
}
}
if (sumvariable == 3) { // 处理第三个传参
keys = variable.keySet().iterator();
while (keys.hasNext()) {
keyexistidentity = 0;
key = (String) keys.next();
if (uservariable2.indexOf(key) > -1) {
keyexistidentity = 1;
uservariable2 = key;
break;
}
}
}
if (keyexistidentity == 1) {
// 拼装参数传参+原有字符串
String ParameterValues = casescript.get("FunctionParams" + (j + 1))
.replaceAll("@" + uservariable, variable.get(uservariable).toString());
// 处理第二个传参
if (sumvariable == 2 || sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable1,
variable.get(uservariable1).toString());
}
// 处理第三个传参
if (sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable2,
variable.get(uservariable2).toString());
}
if (ParameterValues.indexOf("&quot;") > -1 || ParameterValues.indexOf("&#39;") > -1) { // 页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:" + packagename + " 方法名:" + functionname
+ "" + (j + 1) + "个参数:" + ParameterValues);
getParameterValues[j] = ParameterValues;
} else {
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:" + uservariable + ",第"
+ "二个变量名称是:" + uservariable1 + ",第三个变量名称是:" + uservariable2);
}
} else {
String ParameterValues1 = casescript.get("FunctionParams" + (j + 1));
if (ParameterValues1.indexOf("&quot;") > -1 || ParameterValues1.indexOf("&#39;") > -1 || ParameterValues1.indexOf("@@")>-1) { // 页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:" + packagename + " 方法名:" + functionname + ""
+ (j + 1) + "个参数:" + ParameterValues1);
getParameterValues[j] = ParameterValues1;
}
}
} else {
getParameterValues = null;
@ -424,12 +263,13 @@ public class TestCaseExecution {
// 调用动态方法执行测试用例
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 (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 + ",与预期结果匹配成功!");
@ -441,7 +281,7 @@ public class TestCaseExecution {
break; // 某一步骤失败后此条用例置为失败退出
}
} else { // 把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename, functionname, getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
if ("".equals(expectedresults) || testnote.equals(expectedresults)) {
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:" + testnote + ",与预期结果匹配成功!");
@ -454,7 +294,7 @@ public class TestCaseExecution {
break; // 某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); // 获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if (waitsec != 0) {
Thread.sleep(waitsec * 1000);
}

View File

@ -1,5 +1,6 @@
package luckyclient.caserun.exinterface;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -16,6 +17,7 @@ import luckyclient.mail.MailSendInitialization;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.planapi.entity.TestTaskexcute;
import luckyclient.testlinkapi.TestBuildApi;
import luckyclient.testlinkapi.TestCaseApi;
@ -23,11 +25,13 @@ import luckyclient.testlinkapi.TestCaseApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论 QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @ClassName: TestControl
* @Description: 启动扫描指定项目的用例脚本并调用脚本中的方法 @author 何彦霖
* @Description: 启动扫描指定项目的用例脚本并调用脚本中的方法
* @author seagull
* @date 2014年8月24日 上午9:29:40
*
*/
@ -41,14 +45,14 @@ public class TestControl {
* 控制台模式调度计划执行testlink用例
*/
public static void ManualExecutionTestLinkPlan(String projectname, String testplan) throws Exception {
public static void manualExecutionTestLinkPlan(String projectname, String testplan) throws Exception {
DbLink.exetype = 1;
int threadcount = 10;
// 创建线程池多线程执行用例
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
TestBuildApi.GetBuild(projectname);
TestBuildApi.getBuild(projectname);
TestCase[] testCases = TestCaseApi.getplantestcase(projectname, "NULL", testplan);
String taskid = "888888";
for (TestCase testcase : testCases) {
@ -79,7 +83,7 @@ public class TestControl {
* 控制台模式调度计划执行用例
*/
public static void ManualExecutionPlan(String planname) throws Exception {
public static void manualExecutionPlan(String planname) throws Exception {
DbLink.exetype = 1;
int threadcount = 10;
// 创建线程池多线程执行用例
@ -87,6 +91,11 @@ public class TestControl {
new ArrayBlockingQueue<Runnable>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
List<ProjectCase> testCases = GetServerAPI.getCasesbyplanname(planname);
List<PublicCaseParams> pcplist = new ArrayList<PublicCaseParams>();
if(testCases.size()!=0){
pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectid()));
}
String taskid = "888888";
for (ProjectCase testcase : testCases) {
List<ProjectCasesteps> steps = GetServerAPI.getStepsbycaseid(testcase.getId());
@ -95,7 +104,7 @@ public class TestControl {
}
Debugcount++; // 多线程计数++用于检测线程是否全部执行完
threadExecute
.execute(new ThreadForExecuteCase(testcase, steps,taskid));
.execute(new ThreadForExecuteCase(testcase, steps,taskid,pcplist));
}
// 多线程计数用于检测线程是否全部执行完
int i = 0;
@ -116,14 +125,15 @@ public class TestControl {
* 计划任务模式调度计划执行用例
*/
protected static void TastExecutionPlan(String taskid,TestTaskexcute task) throws Exception {
protected static void taskExecutionPlan(String taskid,TestTaskexcute task) throws Exception {
DbLink.exetype = 0;
TestControl.TASKID = taskid;
String restartstatus = RestartServerInitialization.RestartServerRun(taskid);
String buildstatus = BuildingInitialization.BuildingRun(taskid);
String restartstatus = RestartServerInitialization.restartServerRun(taskid);
String buildstatus = BuildingInitialization.buildingRun(taskid);
String jobname = task.getTestJob().getTaskName();
String projectname=task.getTestJob().getPlanproj();
int timeout = task.getTestJob().getTimeout();
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(task.getTestJob().getProjectid().toString());
// 判断是否要自动重启TOMCAT
if (restartstatus.indexOf("Status:true") > -1) {
// 判断是否构建是否成功
@ -135,9 +145,9 @@ public class TestControl {
int[] tastcount=null;
if(task.getTestJob().getProjecttype()==1){
TestBuildApi.GetBuild(projectname);
TestBuildApi.getBuild(projectname);
TestCase[] testCases= TestCaseApi.getplantestcase(projectname, taskid, "");
LogOperation.UpdateTastStatus(taskid, testCases.length);
LogOperation.updateTastStatus(taskid, testCases.length);
for (TestCase testcase : testCases) {
if (testcase.getSteps().size() == 0) {
continue;
@ -155,11 +165,11 @@ public class TestControl {
}
Thread.sleep(6000);
}
tastcount = LogOperation.UpdateTastdetail(taskid, testCases.length);
tastcount = LogOperation.updateTastdetail(taskid, testCases.length);
}else{
List<ProjectCase> cases=GetServerAPI.getCasesbyplanid(task.getTestJob().getPlanid());
LogOperation.UpdateTastStatus(taskid, cases.size());
LogOperation.updateTastStatus(taskid, cases.size());
for (int j=0;j<cases.size();j++) {
ProjectCase projectcase =cases.get(j);
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(projectcase.getId());
@ -168,7 +178,7 @@ public class TestControl {
}
Debugcount++; // 多线程计数++用于检测线程是否全部执行完
threadExecute.execute(
new ThreadForExecuteCase(projectcase, steps,taskid));
new ThreadForExecuteCase(projectcase, steps,taskid,pcplist));
}
// 多线程计数用于检测线程是否全部执行完
int i = 0;
@ -179,29 +189,29 @@ public class TestControl {
}
Thread.sleep(6000);
}
tastcount = LogOperation.UpdateTastdetail(taskid, cases.size());
tastcount = LogOperation.updateTastdetail(taskid, cases.size());
}
String testtime = LogOperation.GetTestTime(taskid);
MailSendInitialization.SendMailInitialization(HtmlMail.HtmlSubjectFormat(jobname),
HtmlMail.HtmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid);
String testtime = LogOperation.getTestTime(taskid);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid);
threadExecute.shutdown();
luckyclient.publicclass.LogUtil.APP.info("亲,没有下一条啦!我发现你的用例已经全部执行完毕,快去看看有没有失败的用例吧!");
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.SendMailInitialization(jobname,
MailSendInitialization.sendMailInitialization(jobname,
"构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.SendMailInitialization(jobname,
MailSendInitialization.sendMailInitialization(jobname,
"项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid);
}
}
public static void main(String[] args) throws Exception {
ManualExecutionPlan("test");
}
}

View File

@ -1,5 +1,16 @@
package luckyclient.caserun.exinterface;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ThreadForBatchCase extends Thread{
private String projectname;
@ -14,8 +25,9 @@ public class ThreadForBatchCase extends Thread{
this.tastid = tastid;
}
@Override
public void run(){
TestCaseExecution.OneCaseExecuteForTast(projectname, testCaseExternalId, version, tastid);
TestCaseExecution.oneCaseExecuteForTast(projectname, testCaseExternalId, version, tastid);
TestControl.Debugcount--; //多线程计数--用于检测线程是否全部执行完
}

View File

@ -1,283 +1,226 @@
package luckyclient.caserun.exinterface;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import luckyclient.caserun.exinterface.AnalyticSteps.InterfaceAnalyticCase;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.dblog.LogOperation;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.publicclass.DBOperation;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.publicclass.ChangString;
import luckyclient.publicclass.InvokeMethod;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: ThreadForExecuteCase
* @Description: 线程池方式执行用例
*
* @ClassName: ThreadForExecuteCase
* @Description: 线程池方式执行用例
* @author seagull
* @date 2017年7月13日 上午9:29:40
* @date 2017年7月13日 上午9:29:40
*
*/
public class ThreadForExecuteCase extends Thread{
public class ThreadForExecuteCase extends Thread {
private String caseid;
private ProjectCase testcaseob;
private String taskid;
private List<ProjectCasesteps> steps;
public ThreadForExecuteCase(ProjectCase projectcase,List<ProjectCasesteps> steps,String taskid){
private List<PublicCaseParams> pcplist;
public ThreadForExecuteCase(ProjectCase projectcase, List<ProjectCasesteps> steps, String taskid,
List<PublicCaseParams> pcplist) {
this.caseid = projectcase.getSign();
this.testcaseob = projectcase;
this.taskid = taskid;
this.steps = steps;
this.pcplist = pcplist;
}
public void run(){
Map<String,String> variable = new HashMap<String,String>();
LogOperation caselog = new LogOperation(); //初始化写用例结果以及日志模块
@Override
public void run() {
Map<String, String> variable = new HashMap<String, String>();
// 把公共参数加入到MAP中
for (PublicCaseParams pcp : pcplist) {
variable.put(pcp.getParamsname(), pcp.getParamsvalue());
}
// 初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
String functionname = null;
String packagename =null;
String packagename = null;
String expectedresults = null;
Integer setresult = null;
Object[] getParameterValues = null;
String testnote = null;
String testnote = null;
int k = 0;
//进入循环解析单个用例所有步骤
System.out.println(caseid);
caselog.AddCaseDetail(taskid, caseid, "1", testcaseob.getName(), 4); //插入开始执行的用例
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").toString();
functionname = casescript.get("FunctionName").toString();
}catch(Exception e){
k=0;
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getSign()+"解析包名或是方法名失败,请检查!");
caselog.CaseLogDetail(taskid, caseid, "解析包名或是方法名失败,请检查!","error",String.valueOf(i+1),"");
e.printStackTrace();
break; //某一步骤失败后此条用例置为失败退出
}
//用例名称解析出现异常或是单个步骤参数解析异常
if(functionname.indexOf("解析异常")>-1||k==1){
k=0;
testnote = "用例第"+(i+1)+"步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); //预期结果
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){ //页面转义字符转换
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
//判断方法是否带参数
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;
}
if(casescript.get("FunctionParams"+(j+1)).indexOf("@")>-1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){//如果存在传参进行处理
int keyexistidentity = 0;
//取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams"+(j+1)), "@");
String uservariable = null;
String uservariable1 = null;
String uservariable2 = null;
if(sumvariable==1){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).indexOf("@")+1);
}else if(sumvariable==2){ //单个参数中引用第二个变量
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@")+1);
}else if(sumvariable==3){
String temp = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = temp.substring(temp.indexOf("@")+1);
uservariable2 = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@")+1);
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).indexOf(uservariable1)-1);
}else{
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
caselog.CaseLogDetail(taskid, caseid, "你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦","error",String.valueOf(i+1),"");
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
String key = null;
while(keys.hasNext()){
key = (String)keys.next();
if(uservariable.indexOf(key)>-1){ //去判断是否字符串里面包含变量键值
keyexistidentity = 1;
uservariable = key;
break;
}
}
if(sumvariable==2||sumvariable==3){ //处理第二个传参
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
key = (String)keys.next();
if(uservariable1.indexOf(key)>-1){
keyexistidentity = 1;
uservariable1 = key;
break;
}
}
}
if(sumvariable==3){ //处理第三个传参
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
key = (String)keys.next();
if(uservariable2.indexOf(key)>-1){
keyexistidentity = 1;
uservariable2 = key;
break;
}
}
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
caselog.CaseLogDetail(taskid, caseid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues,"info",String.valueOf(i+1),"");
getParameterValues[j] = ParameterValues;
}else{
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
caselog.CaseLogDetail(taskid, caseid, "没有找到你要的变量哦,再找下吧!第二变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1,"error",String.valueOf(i+1),"");
}
// 进入循环解析单个用例所有步骤
// 插入开始执行的用例
caselog.addCaseDetail(taskid, caseid, "1", testcaseob.getName(), 4);
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").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() + "解析包名或是方法名失败,请检查!");
caselog.caseLogDetail(taskid, caseid, "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
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;
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getSign()+"解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
caselog.CaseLogDetail(taskid, caseid,"解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1,"info",String.valueOf(i+1),"");
getParameterValues[j] = ParameterValues1;
}
}
}else{
getParameterValues = null;
}
//调用动态方法执行测试用例
try{
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getSign()+"开始调用方法:"+functionname+" .....");
caselog.CaseLogDetail(taskid, caseid,"开始调用方法:"+functionname+" .....","info",String.valueOf(i+1),"");
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("用例:"+testcaseob.getSign()+"执行结果是:"+testnote+",与预期结果匹配成功!");
caselog.CaseLogDetail(taskid, caseid,"执行结果是:"+testnote+",与预期结果匹配成功!","info",String.valueOf(i+1),"");
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getSign()+""+(i+1)+"步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getSign()+"预期结果:"+expectedresults+" 测试结果:"+testnote);
caselog.CaseLogDetail(taskid, caseid,""+(i+1)+"步执行结果与预期结果匹配失败!"+"预期结果:"+expectedresults+" 测试结果:"+testnote,"error",String.valueOf(i+1),"");
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("用例:"+testcaseob.getSign()+"执行结果是:"+testnote+",与预期结果匹配成功!");
caselog.CaseLogDetail(taskid, caseid,"执行结果是:"+testnote+",与预期结果匹配成功!","info",String.valueOf(i+1),"");
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getSign()+""+(i+1)+"步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getSign()+"预期结果:"+expectedresults+" 测试结果:"+testnote);
caselog.CaseLogDetail(taskid, caseid,""+(i+1)+"步执行结果与预期结果匹配失败!"+"预期结果:"+expectedresults+" 测试结果:"+testnote,"error",String.valueOf(i+1),"");
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"+expectedresults+" 测试结果:"+testnote;
break; //某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); //获取步骤间等待时间
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getSign()+"调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!");
caselog.CaseLogDetail(taskid, caseid,"调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!","error",String.valueOf(i+1),"");
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
testnote = "CallCase调用出错调用方法过程出错方法名"+functionname+" 请重新检查脚本方法名称以及参数!";
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, caseid,
"解析包名:" + packagename + " 方法名:" + functionname + "" + (j + 1) + "个参数:" + parameterValues,
"info", String.valueOf(i + 1), "");
getParameterValues[j] = parameterValues;
}
} else {
getParameterValues = null;
}
// 调用动态方法执行测试用例
try {
luckyclient.publicclass.LogUtil.APP
.info("用例:" + testcaseob.getSign() + "开始调用方法:" + functionname + " .....");
caselog.caseLogDetail(taskid, caseid, "开始调用方法:" + functionname + " .....", "info",
String.valueOf(i + 1), "");
// 把预期结果前两个字符判断是否是要把结果存入变量
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("用例:" + testcaseob.getSign() + "执行结果是:" + testnote + ",与预期结果匹配成功!");
caselog.caseLogDetail(taskid, caseid, "执行结果是:" + testnote + ",与预期结果匹配成功!", "info",
String.valueOf(i + 1), "");
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP
.error("用例:" + testcaseob.getSign() + "" + (i + 1) + "步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error(
"用例:" + testcaseob.getSign() + "预期结果:" + expectedresults + " 测试结果:" + testnote);
caselog.caseLogDetail(taskid, caseid, "" + (i + 1) + "步执行结果与预期结果匹配失败!" + "预期结果:"
+ expectedresults + " 测试结果:" + testnote, "error", String.valueOf(i + 1), "");
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("用例:" + testcaseob.getSign() + "执行结果是:" + testnote + ",与预期结果匹配成功!");
caselog.caseLogDetail(taskid, caseid, "执行结果是:" + testnote + ",与预期结果匹配成功!", "info",
String.valueOf(i + 1), "");
} else {
setresult = 1;
luckyclient.publicclass.LogUtil.APP
.error("用例:" + testcaseob.getSign() + "" + (i + 1) + "步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error(
"用例:" + testcaseob.getSign() + "预期结果:" + expectedresults + " 测试结果:" + testnote);
caselog.caseLogDetail(taskid, caseid, "" + (i + 1) + "步执行结果与预期结果匹配失败!" + "预期结果:"
+ expectedresults + " 测试结果:" + testnote, "error", String.valueOf(i + 1), "");
testnote = "用例第" + (i + 1) + "步执行结果与预期结果匹配失败!预期结果:" + expectedresults + " 测试结果:"
+ testnote;
break; // 某一步骤失败后此条用例置为失败退出
}
}
// 获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if (waitsec != 0) {
Thread.sleep(waitsec * 1000);
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.ERROR
.error("用例:" + testcaseob.getSign() + "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!");
caselog.caseLogDetail(taskid, caseid, "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error",
String.valueOf(i + 1), "");
luckyclient.publicclass.LogUtil.ERROR.error(e, e);
testnote = "CallCase调用出错调用方法过程出错方法名" + functionname + " 请重新检查脚本方法名称以及参数!";
setresult = 1;
e.printStackTrace();
break;
}
}
//如果调用方法过程中未出错进入设置测试结果流程
try{
if(testnote.indexOf("CallCase调用出错")<=-1&&testnote.indexOf("解析出错啦!")<=-1){ //成功跟失败的用例走此流程
caselog.UpdateCaseDetail(taskid, caseid, setresult);
}else{
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getSign()+"设置执行结果为锁定,请参考错误日志查找锁定用例的原因....."); //解析用例或是调用方法出错全部把用例置为锁定
caselog.CaseLogDetail(taskid, caseid,"设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....","error","SETCASERESULT...","");
setresult = 2;
caselog.UpdateCaseDetail(taskid, caseid, setresult);
}
if(setresult==0){
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getSign()+"执行结果成功......");
caselog.CaseLogDetail(taskid, caseid,"用例步骤执行全部成功......","info","ending","");
luckyclient.publicclass.LogUtil.APP.info("******************************分割线*************************************");
}else if(setresult==1){
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getSign()+"执行结果失败......");
caselog.CaseLogDetail(taskid, caseid,"用例执行结果失败......","error","ending","");
luckyclient.publicclass.LogUtil.APP.info("******************************分割线*************************************");
}else{
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getSign()+"执行结果锁定......");
caselog.CaseLogDetail(taskid, caseid,"用例执行结果锁定......","error","ending","");
luckyclient.publicclass.LogUtil.APP.info("******************************分割线*************************************");
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getSign()+"设置执行结果过程出错......");
caselog.CaseLogDetail(taskid, caseid,"设置执行结果过程出错......","error","ending","");
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
break;
}
}
// 如果调用方法过程中未出错进入设置测试结果流程
try {
// 成功跟失败的用例走此流程
if (testnote.indexOf("CallCase调用出错") <= -1 && testnote.indexOf("解析出错啦!") <= -1) {
caselog.updateCaseDetail(taskid, caseid, setresult);
} else {
// 解析用例或是调用方法出错全部把用例置为锁定
luckyclient.publicclass.LogUtil.ERROR
.error("用例:" + testcaseob.getSign() + "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....");
caselog.caseLogDetail(taskid, caseid, "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....", "error", "SETCASERESULT...",
"");
setresult = 2;
caselog.updateCaseDetail(taskid, caseid, setresult);
}
if (setresult == 0) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcaseob.getSign() + "执行结果成功......");
caselog.caseLogDetail(taskid, caseid, "用例步骤执行全部成功......", "info", "ending", "");
luckyclient.publicclass.LogUtil.APP
.info("*********用例【"+testcaseob.getSign()+"】执行完成,测试结果:成功*********");
} else if (setresult == 1) {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcaseob.getSign() + "执行结果失败......");
caselog.caseLogDetail(taskid, caseid, "用例执行结果失败......", "error", "ending", "");
luckyclient.publicclass.LogUtil.APP
.info("*********用例【"+testcaseob.getSign()+"】执行完成,测试结果:失败*********");
} else {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcaseob.getSign() + "执行结果锁定......");
caselog.caseLogDetail(taskid, caseid, "用例执行结果锁定......", "error", "ending", "");
luckyclient.publicclass.LogUtil.APP
.info("*********用例【"+testcaseob.getSign()+"】执行完成,测试结果:锁定*********");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例:" + testcaseob.getSign() + "设置执行结果过程出错......");
caselog.caseLogDetail(taskid, caseid, "设置执行结果过程出错......", "error", "ending", "");
luckyclient.publicclass.LogUtil.ERROR.error(e, e);
e.printStackTrace();
}finally{
variable.clear(); //一条用例结束后清空变量存储空间
TestControl.Debugcount--; //多线程计数--用于检测线程是否全部执行完
}
} finally {
variable.clear(); // 一条用例结束后清空变量存储空间
TestControl.Debugcount--; // 多线程计数--用于检测线程是否全部执行完
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

View File

@ -1,21 +1,21 @@
package luckyclient.caserun.exinterface;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import luckyclient.caserun.exinterface.AnalyticSteps.InterfaceAnalyticCase;
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.publicclass.DBOperation;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.publicclass.ChangString;
import luckyclient.publicclass.InvokeMethod;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: WebTestCaseDebug
* @Description: 提供Web端调试接口
@ -30,7 +30,7 @@ public class WebTestCaseDebug{
* @param 用例编号
* 用于在WEB页面上调试用例时提供的接口
*/
public static void OneCaseDebug(String sign,String executor){
public static void oneCaseDebug(String sign,String executor){
Map<String,String> variable = new HashMap<String,String>();
String packagename =null;
String functionname = null;
@ -40,13 +40,20 @@ public class WebTestCaseDebug{
String testnote = null;
int k = 0;
ProjectCase testcaseob = GetServerAPI.cgetCaseBysign(sign);
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());
//进入循环解析用例所有步骤
for(int i=0;i<steps.size();i++){
Map<String,String> casescript = InterfaceAnalyticCase.AnalyticCaseStep(testcaseob, steps.get(i),"888888",null); //解析单个步骤中的脚本
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;
GetServerAPI.cPostDebugLog(sign, executor, "ERROR", "解析包名或是方法名失败,请检查!");
@ -59,117 +66,23 @@ public class WebTestCaseDebug{
testnote = "用例第"+(i+1)+"步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); //预期结果
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){ //页面转义字符转换
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
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++){
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;
}
if(casescript.get("FunctionParams"+(j+1)).indexOf("@")>-1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){ //如果存在传参进行处理
int keyexistidentity = 0;
//取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams"+(j+1)), "@");
String uservariable = null;
String uservariable1 = null;
String uservariable2 = null;
if(sumvariable==1){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).indexOf("@")+1);
}else if(sumvariable==2){ //单个参数中引用第二个变量
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@")+1);
}else if(sumvariable==3){
String temp = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = temp.substring(temp.indexOf("@")+1);
uservariable2 = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@")+1);
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).indexOf(uservariable1)-1);
}else{
GetServerAPI.cPostDebugLog(sign, executor, "WARNING", "你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
String key = null;
while(keys.hasNext()){
key = (String)keys.next();
if(uservariable.indexOf(key)>-1){
keyexistidentity = 1;
uservariable = key;
break;
}
}
if(sumvariable==2||sumvariable==3){ //处理第二个传参
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
key = (String)keys.next();
if(uservariable.indexOf(key)>-1){
keyexistidentity = 1;
uservariable1 = key;
break;
}
}
}
if(sumvariable==3){ //处理第三个传参
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
key = (String)keys.next();
if(uservariable.indexOf(key)>-1){
keyexistidentity = 1;
uservariable2 = key;
break;
}
}
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
}
GetServerAPI.cPostDebugLog(sign, executor, "INFO", "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
getParameterValues[j] = ParameterValues;
}else{
GetServerAPI.cPostDebugLog(sign, executor, "WARNING", "没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
}
GetServerAPI.cPostDebugLog(sign, executor, "INFO", "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
getParameterValues[j] = ParameterValues1;
}
String parameterValues = casescript.get("FunctionParams" + (j + 1));
parameterValues = ChangString.changparams(parameterValues, variable,"用例参数");
GetServerAPI.cPostDebugLog(sign, executor, "INFO", "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+parameterValues);
getParameterValues[j] = parameterValues;
}
}else{
getParameterValues = null;
@ -177,13 +90,13 @@ public class WebTestCaseDebug{
//调用动态方法执行测试用例
try{
GetServerAPI.cPostDebugLog(sign, executor, "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);
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);
GetServerAPI.cPostDebugLog(sign, executor, "INFO", "赋值变量【"+expectedresults.substring(2, expectedresults.length())+"】: "+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());
}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;
GetServerAPI.cPostDebugLog(sign, executor, "INFO", "用例执行结果是:"+testnote+",与预期结果匹配成功!");
@ -194,7 +107,7 @@ public class WebTestCaseDebug{
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,steps.get(i).getSteptype(),steps.get(i).getAction());
if(expectedresults.equals(testnote)){
setresult = 0;
GetServerAPI.cPostDebugLog(sign, executor, "INFO", "用例执行结果是:"+testnote+",与预期结果匹配成功!");
@ -205,7 +118,7 @@ public class WebTestCaseDebug{
break; //某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); //获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}

View File

@ -1,4 +1,4 @@
package luckyclient.caserun.exinterface.AnalyticSteps;
package luckyclient.caserun.exinterface.analyticsteps;
import java.util.HashMap;
import java.util.Map;
@ -11,8 +11,8 @@ import luckyclient.planapi.entity.ProjectCasesteps;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: AnalyticCase
* @Description: 解析单个用例中描述部分的脚本
@ -27,7 +27,7 @@ public class InterfaceAnalyticCase{
* @param args
*/
@SuppressWarnings("finally")
public static Map<String,String> AnalyticCaseStep(ProjectCase projectcase,ProjectCasesteps step,String taskid,LogOperation caselog){
public static Map<String,String> analyticCaseStep(ProjectCase projectcase,ProjectCasesteps step,String taskid,LogOperation caselog){
String time = "0";
Map<String,String> params = new HashMap<String,String>();
@ -36,22 +36,23 @@ public class InterfaceAnalyticCase{
String functionname = step.getOperation();
String resultstr = step.getExpectedresult();
String action = step.getAction();
params.put("PackageName", packagenage.trim()); //set包名
params.put("FunctionName", functionname.trim()); //set方法名称
String Params = step.getParameters();
String temp[]=Params.split(splitFlag,-1);
params.put("PackageName", packagenage.trim());
params.put("FunctionName", functionname.trim());
String stepParams = step.getParameters();
String[] temp=stepParams.split(splitFlag,-1);
for(int i=0;i<temp.length;i++){
if(temp[i].equals("")){
if("".equals(temp[i])){
continue;
}else{
params.put("FunctionParams"+(i+1), temp[i]); //set第N个传入参数
//set第N个传入参数
params.put("FunctionParams"+(i+1), temp[i]);
}
}
//set预期结果
if(resultstr.equals("")){
if("".equals(resultstr)){
params.put("ExpectedResults", "");
}else{
params.put("ExpectedResults", SubComment(resultstr));
params.put("ExpectedResults", subComment(resultstr));
}
//set后续操作
if(null!=action&&action.toLowerCase().indexOf("*wait")>-1){
@ -60,57 +61,71 @@ public class InterfaceAnalyticCase{
params.put("StepWait", time);
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+projectcase.getSign()+" 步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.CaseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepnum()),"");
caselog.caseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepnum()),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+projectcase.getSign()+" 步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.CaseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepnum()),"");
caselog.caseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepnum()),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
params.put("FunctionName","用例编号:"+projectcase.getSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
}finally{
return params;
return params;
}
return params;
}
public static String SubComment(String htmlStr) throws InterruptedException{
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
String regEx_space = "\t|\r|\n";//定义空格回车换行符
public static String subComment(String htmlStr) throws InterruptedException{
// 定义script的正则表达式
String regExscript = "<script[^>]*?>[\\s\\S]*?<\\/script>";
// 定义style的正则表达式
String regExstyle = "<style[^>]*?>[\\s\\S]*?<\\/style>";
// 定义HTML标签的正则表达式
String regExhtml = "<[^>]+>";
//定义空格回车换行符
String regExspace = "\t|\r|\n";
String scriptstr = null;
if (htmlStr!=null) {
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签
Pattern pScript = Pattern.compile(regExscript, Pattern.CASE_INSENSITIVE);
Matcher mScript = pScript.matcher(htmlStr);
// 过滤script标签
htmlStr = mScript.replaceAll("");
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); // 过滤style标签
Pattern pStyle = Pattern.compile(regExstyle, Pattern.CASE_INSENSITIVE);
Matcher mStyle = pStyle.matcher(htmlStr);
// 过滤style标签
htmlStr = mStyle.replaceAll("");
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签
Pattern pHtml = Pattern.compile(regExhtml, Pattern.CASE_INSENSITIVE);
Matcher mHtml = pHtml.matcher(htmlStr);
// 过滤html标签
htmlStr = mHtml.replaceAll("");
Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
Pattern pSpace = Pattern.compile(regExspace, Pattern.CASE_INSENSITIVE);
Matcher mSpace = pSpace.matcher(htmlStr);
// 过滤空格回车标签
htmlStr = mSpace.replaceAll("");
}
if(htmlStr.indexOf("/*")>-1&&htmlStr.indexOf("*/")>-1){
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"),htmlStr.indexOf("*/")+2);
scriptstr = htmlStr.replace(commentstr, ""); //去注释
//去注释
scriptstr = htmlStr.replace(commentstr, "");
}else{
scriptstr = htmlStr;
}
scriptstr = trimInnerSpaceStr(scriptstr); //去掉字符串前后的空格
scriptstr = scriptstr.replaceAll("&nbsp;", " "); //替换空格转义
scriptstr = scriptstr.replaceAll("&quot;", "\""); //转义双引号
scriptstr = scriptstr.replaceAll("&#39;", "\'"); //转义单引号
scriptstr = scriptstr.replaceAll("&amp;", "&"); //转义链接符
//去掉字符串前后的空格
scriptstr = trimInnerSpaceStr(scriptstr);
//替换空格转义
scriptstr = scriptstr.replaceAll("&nbsp;", " ");
//转义双引号
scriptstr = scriptstr.replaceAll("&quot;", "\"");
//转义单引号
scriptstr = scriptstr.replaceAll("&#39;", "\'");
//转义链接符
scriptstr = scriptstr.replaceAll("&amp;", "&");
scriptstr = scriptstr.replaceAll("&lt;", "<");
scriptstr = scriptstr.replaceAll("&gt;", ">");

View File

@ -9,6 +9,17 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class BatchTestLinkCaseExecution {
/**
@ -17,16 +28,17 @@ public class BatchTestLinkCaseExecution {
* 创建线程池多线程执行用例
*/
public static void BatchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws Exception{
public static void batchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws Exception{
TestTaskexcute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
int threadcount = task.getTestJob().getThreadCount();
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 30, 3, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(1000),
new ThreadPoolExecutor.CallerRunsPolicy());
if(batchcase.indexOf("ALLFAIL")>-1){ //执行全部非成功状态用例
LogOperation caselog = new LogOperation(); //初始化写用例结果以及日志模块
String casemore = caselog.UnSucCaseUpdate(taskid);
String temp[]=casemore.split("\\#",-1);
//执行全部非成功状态用例
if(batchcase.indexOf("ALLFAIL")>-1){
LogOperation caselog = new LogOperation();
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp=casemore.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()-1));
@ -34,7 +46,7 @@ public class BatchTestLinkCaseExecution {
threadExecute.execute(new ThreadForTestLinkBatchCase(projectname,testCaseExternalId,version,taskid));
}
}else{ //批量执行用例
String temp[]=batchcase.split("\\#",-1);
String[] temp=batchcase.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()));

View File

@ -13,8 +13,8 @@ import luckyclient.testlinkapi.TestCaseApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: TestCaseDebug
* @Description: 针对自动化用例在编写过程中对用例脚本进行调试
@ -30,7 +30,7 @@ public class TestLinkCaseDebug{
* @param 用例版本号
* 用于在testlink上配置好用例参数后做单条用例调试
*/
public static void OneCaseDebug(String projectname,String testCaseExternalId,int version){
public static void oneCaseDebug(String projectname,String testCaseExternalId,int version){
Map<String,String> variable = new HashMap<String,String>();
String packagename =null;
String functionname = null;
@ -43,7 +43,7 @@ public class TestLinkCaseDebug{
if(testcaseob.getExecutionType()==ExecutionType.AUTOMATED){
//进入循环解析用例所有步骤
for(int i=0;i<testcaseob.getSteps().size();i++){
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.AnalyticCaseStep(testcaseob, i+1,"888888",null); //解析单个步骤中的脚本
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.analyticCaseStep(testcaseob, i+1,"888888",null);
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
//用例名称解析出现异常或是单个步骤参数解析异常
@ -52,22 +52,22 @@ public class TestLinkCaseDebug{
testnote = "用例第"+(i+1)+"步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); //预期结果
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){ //页面转义字符转换
expectedresults = casescript.get("ExpectedResults").toString();
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
//判断方法是否带参数
if(casescript.size()>4){
//获取传入参数放入对象中
getParameterValues = new Object[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;
}
if(casescript.get("FunctionParams"+(j+1)).indexOf("@")>-1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){ //如果存在传参进行处理
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){
int keyexistidentity = 0;
//取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams"+(j+1)), "@");
@ -78,7 +78,7 @@ public class TestLinkCaseDebug{
if(sumvariable==1){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).indexOf("@")+1);
}else if(sumvariable==2){ //单个参数中引用第二个变量
}else if(sumvariable==2){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams"+(j+1)).substring(
@ -105,7 +105,7 @@ public class TestLinkCaseDebug{
break;
}
}
if(sumvariable==2||sumvariable==3){ //处理第二个传参
if(sumvariable==2||sumvariable==3){
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
@ -117,7 +117,7 @@ public class TestLinkCaseDebug{
}
}
}
if(sumvariable==3){ //处理第三个传参
if(sumvariable==3){
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
@ -131,37 +131,37 @@ public class TestLinkCaseDebug{
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
String parameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
if(parameterValues.indexOf("&quot;")>-1 || parameterValues.indexOf("&#39;")>-1){
parameterValues = parameterValues.replaceAll("&quot;", "\"");
parameterValues = parameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
getParameterValues[j] = ParameterValues;
+""+(j+1)+"个参数:"+parameterValues);
getParameterValues[j] = parameterValues;
}else{
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
String parameterValues1 = casescript.get("FunctionParams"+(j+1));
if(parameterValues1.indexOf("&quot;")>-1 || parameterValues1.indexOf("&#39;")>-1 || parameterValues1.indexOf("@@")>-1){
parameterValues1 = parameterValues1.replaceAll("&quot;", "\"");
parameterValues1 = parameterValues1.replaceAll("&#39;", "\'");
parameterValues1 = parameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
getParameterValues[j] = ParameterValues1;
+""+(j+1)+"个参数:"+parameterValues1);
getParameterValues[j] = parameterValues1;
}
}
}else{
@ -170,12 +170,12 @@ public class TestLinkCaseDebug{
//调用动态方法执行测试用例
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,0,"");
variable.put(ExpectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){ //把预期结果与测试结果做模糊匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
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,0,"");
variable.put(expectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(testnote.indexOf(expectedresults.substring(2))>-1){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
@ -187,7 +187,7 @@ public class TestLinkCaseDebug{
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(expectedresults.equals(testnote)){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
@ -199,7 +199,7 @@ public class TestLinkCaseDebug{
break; //某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); //获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}
@ -235,7 +235,7 @@ public class TestLinkCaseDebug{
* @param 用例版本号
* 用于在testlink上配置好用例参数后做多条用例串行调试
*/
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();
@ -246,7 +246,7 @@ public class TestLinkCaseDebug{
Integer version = (Integer)entry.getValue();
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:"+testCaseExternalId+",用例版本:"+version);
OneCaseDebug(projectname,testCaseExternalId,version);
oneCaseDebug(projectname,testCaseExternalId,version);
}catch(Exception e){
continue;
}

View File

@ -14,6 +14,17 @@ import luckyclient.publicclass.InvokeMethod;
import luckyclient.testlinkapi.InterfaceAnalyticTestLinkCase;
import luckyclient.testlinkapi.TestCaseApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class TestLinkCaseExecution{
/**
* @param 项目名
@ -22,11 +33,11 @@ public class TestLinkCaseExecution{
* 用于在testlink上配置好用例参数后做单条用例调试并通过日志框架写日志到UTP上用做UTP上单条用例运行
*/
@SuppressWarnings("static-access")
public static void OneCaseExecuteForTast(String projectname,String testCaseExternalId,int version,String tastid){
public static void oneCaseExecuteForTast(String projectname,String testCaseExternalId,int version,String tastid){
Map<String,String> variable = new HashMap<String,String>();
TestControl.TASKID = tastid;
DbLink.exetype = 0;
LogOperation caselog = new LogOperation(); //初始化写用例结果以及日志模块
LogOperation caselog = new LogOperation();
String packagename =null;
String functionname = null;
String expectedresults = null;
@ -34,12 +45,12 @@ public class TestLinkCaseExecution{
Object[] getParameterValues = null;
String testnote = null;
int k = 0;
caselog.DeleteCaseLogDetail(testCaseExternalId, tastid); //删除旧的日志
LogOperation.deleteCaseLogDetail(testCaseExternalId, tastid);
TestCase testcaseob = TestCaseApi.getTestCaseByExternalId(testCaseExternalId, version);
if(testcaseob.getExecutionType()==ExecutionType.AUTOMATED){
//进入循环解析用例所有步骤
for(int i=0;i<testcaseob.getSteps().size();i++){
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.AnalyticCaseStep(testcaseob, i+1,tastid,caselog); //解析单个步骤中的脚本
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.analyticCaseStep(testcaseob, i+1,tastid,caselog);
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
//用例名称解析出现异常或是单个步骤参数解析异常
@ -48,22 +59,22 @@ public class TestLinkCaseExecution{
testnote = "用例第"+(i+1)+"步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); //预期结果
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){ //页面转义字符转换
expectedresults = casescript.get("ExpectedResults").toString();
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
//判断方法是否带参数
if(casescript.size()>4){
//获取传入参数放入对象中
getParameterValues = new Object[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;
}
if(casescript.get("FunctionParams"+(j+1)).indexOf("@")>-1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){ //如果存在传参进行处理
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){
int keyexistidentity = 0;
//取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams"+(j+1)), "@");
@ -74,7 +85,7 @@ public class TestLinkCaseExecution{
if(sumvariable==1){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).indexOf("@")+1);
}else if(sumvariable==2){ //单个参数中引用第二个变量
}else if(sumvariable==2){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams"+(j+1)).substring(
@ -89,7 +100,7 @@ public class TestLinkCaseExecution{
casescript.get("FunctionParams"+(j+1)).indexOf(uservariable1)-1);
}else{
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "你好像在一个参数中引用了超过2个以上的变量哦我处理不过来啦", "error",String.valueOf(i+1));
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "你好像在一个参数中引用了超过2个以上的变量哦我处理不过来啦", "error",String.valueOf(i+1));
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
@ -102,7 +113,7 @@ public class TestLinkCaseExecution{
break;
}
}
if(sumvariable==2||sumvariable==3){ //处理第二个传参
if(sumvariable==2||sumvariable==3){
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
@ -114,7 +125,7 @@ public class TestLinkCaseExecution{
}
}
}
if(sumvariable==3){ //处理第三个传参
if(sumvariable==3){
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
@ -128,43 +139,43 @@ public class TestLinkCaseExecution{
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
String parameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
if(parameterValues.indexOf("&quot;")>-1 || parameterValues.indexOf("&#39;")>-1){
parameterValues = parameterValues.replaceAll("&quot;", "\"");
parameterValues = parameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues, "info",String.valueOf(i+1));
getParameterValues[j] = ParameterValues;
+""+(j+1)+"个参数:"+parameterValues);
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+parameterValues, "info",String.valueOf(i+1));
getParameterValues[j] = parameterValues;
}else{
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "没有找到你要的变量哦,再找下吧!第二变量名称是:"+uservariable+",第"
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "没有找到你要的变量哦,再找下吧!第二变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2, "error",String.valueOf(i+1));
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
String parameterValues1 = casescript.get("FunctionParams"+(j+1));
if(parameterValues1.indexOf("&quot;")>-1 || parameterValues1.indexOf("&#39;")>-1 || parameterValues1.indexOf("@@")>-1){
parameterValues1 = parameterValues1.replaceAll("&quot;", "\"");
parameterValues1 = parameterValues1.replaceAll("&#39;", "\'");
parameterValues1 = parameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1, "info",String.valueOf(i+1));
getParameterValues[j] = ParameterValues1;
+""+(j+1)+"个参数:"+parameterValues1);
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+parameterValues1, "info",String.valueOf(i+1));
getParameterValues[j] = parameterValues1;
}
}
}else{
@ -173,48 +184,48 @@ public class TestLinkCaseExecution{
//调用动态方法执行测试用例
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法:"+functionname+" .....");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "开始调用方法:"+functionname+" .....", "info",String.valueOf(i+1));
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,0,"");
variable.put(ExpectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){ //把预期结果与测试结果做模糊匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "开始调用方法:"+functionname+" .....", "info",String.valueOf(i+1));
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,0,"");
variable.put(expectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(testnote.indexOf(expectedresults.substring(2))>-1){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "用例执行结果是:"+testnote+",与预期结果匹配成功!", "info",String.valueOf(i+1));
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "用例执行结果是:"+testnote+",与预期结果匹配成功!", "info",String.valueOf(i+1));
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例第"+(i+1)+"步执行结果与预期结果匹配失败!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"+expectedresults+" 测试结果:"+testnote, "error",String.valueOf(i+1));
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"+expectedresults+" 测试结果:"+testnote, "error",String.valueOf(i+1));
luckyclient.publicclass.LogUtil.APP.error("预期结果:"+expectedresults+" 测试结果:"+testnote);
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!";
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(expectedresults.equals(testnote)){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "用例执行结果是:"+testnote+",与预期结果匹配成功!", "info",String.valueOf(i+1));
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "用例执行结果是:"+testnote+",与预期结果匹配成功!", "info",String.valueOf(i+1));
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例第"+(i+1)+"步执行结果与预期结果匹配失败!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"
+expectedresults+" 测试结果:"+testnote, "error",String.valueOf(i+1));
luckyclient.publicclass.LogUtil.APP.error("预期结果:"+expectedresults+" 测试结果:"+testnote);
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"+expectedresults+" 测试结果:"+testnote;
break; //某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); //获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.APP.error("调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!", "error",String.valueOf(i+1));
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!", "error",String.valueOf(i+1));
luckyclient.publicclass.LogUtil.APP.error(e,e);
testnote = "CallCase调用出错";
setresult = 1;
@ -226,28 +237,28 @@ public class TestLinkCaseExecution{
//如果调用方法过程中未出错进入设置测试结果流程
if(testnote.indexOf("CallCase调用出错")<=-1&&testnote.indexOf("解析出错啦!")<=-1){
luckyclient.publicclass.LogUtil.APP.info("用例 "+testCaseExternalId+"解析成功,并成功调用用例中方法,请继续查看执行结果!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info","SETCASERESULT...");
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info","SETCASERESULT...");
//TCResult = TestCaseApi.setTCResult(projectname,testCaseExternalId, testnote, version,setresult);
caselog.UpdateCaseDetail(tastid, testCaseExternalId, setresult);
caselog.updateCaseDetail(tastid, testCaseExternalId, setresult);
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例 "+testCaseExternalId+"解析或是调用步骤中的方法出错!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "解析或是调用步骤中的方法出错!", "error","SETCASERESULT...");
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "解析或是调用步骤中的方法出错!", "error","SETCASERESULT...");
// TCResult = TestCaseApi.setTCResult(projectname,testCaseExternalId, testnote, version,2);
caselog.UpdateCaseDetail(tastid, testCaseExternalId, 2);
caselog.updateCaseDetail(tastid, testCaseExternalId, 2);
}
if(0==setresult){
luckyclient.publicclass.LogUtil.APP.info("用例 "+testCaseExternalId+"步骤全部执行成功!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "步骤全部执行成功!", "info","EXECUTECASESUC...");
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "步骤全部执行成功!", "info","EXECUTECASESUC...");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例 "+testCaseExternalId+"在执行过程中失败,请检查日志!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "在执行过程中失败,请检查日志!", "error","EXECUTECASESUC...");
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "在执行过程中失败,请检查日志!", "error","EXECUTECASESUC...");
}
}else{
luckyclient.publicclass.LogUtil.APP.error("用例 "+testCaseExternalId+"不是一个自动化的用例哦!先去把它设置一下吧!");
caselog.UpdateCaseLogDetail(testCaseExternalId, tastid, "不是一个自动化的用例哦!先去把它设置一下吧!", "error","EXECUTECASEFAIL...");
LogOperation.updateCaseLogDetail(testCaseExternalId, tastid, "不是一个自动化的用例哦!先去把它设置一下吧!", "error","EXECUTECASEFAIL...");
}
LogOperation.UpdateTastdetail(tastid, 0);
LogOperation.updateTastdetail(tastid, 0);
}
@ -257,7 +268,7 @@ public class TestLinkCaseExecution{
* @param 用例版本号
* 用于在UI的测试过程中需要调用接口的测试用例
*/
protected static String OneCaseExecuteForWebDriver(String testCaseExternalId,int version,String tastid,LogOperation caselog){
protected static String oneCaseExecuteForWebDriver(String testCaseExternalId,int version,String tastid,LogOperation caselog){
Map<String,String> variable = new HashMap<String,String>();
String packagename =null;
String functionname = null;
@ -270,7 +281,7 @@ public class TestLinkCaseExecution{
if(testcaseob.getExecutionType()==ExecutionType.AUTOMATED){
//进入循环解析用例所有步骤
for(int i=0;i<testcaseob.getSteps().size();i++){
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.AnalyticCaseStep(testcaseob, i+1,tastid,caselog); //解析单个步骤中的脚本
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.analyticCaseStep(testcaseob, i+1,tastid,caselog);
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
//用例名称解析出现异常或是单个步骤参数解析异常
@ -279,22 +290,22 @@ public class TestLinkCaseExecution{
testnote = "用例第"+(i+1)+"步解析出错啦!";
break;
}
expectedresults = casescript.get("ExpectedResults").toString(); //预期结果
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){ //页面转义字符转换
expectedresults = casescript.get("ExpectedResults").toString();
if(expectedresults.indexOf("&quot;")>-1||expectedresults.indexOf("&#39;")>-1){
expectedresults = expectedresults.replaceAll("&quot;", "\"");
expectedresults = expectedresults.replaceAll("&#39;", "\'");
}
//判断方法是否带参数
if(casescript.size()>4){
//获取传入参数放入对象中
getParameterValues = new Object[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;
}
if(casescript.get("FunctionParams"+(j+1)).indexOf("@")>-1
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){ //如果存在传参进行处理
&&casescript.get("FunctionParams"+(j+1)).indexOf("@@")<0){
int keyexistidentity = 0;
//取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(casescript.get("FunctionParams"+(j+1)), "@");
@ -305,7 +316,7 @@ public class TestLinkCaseExecution{
if(sumvariable==1){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(
casescript.get("FunctionParams"+(j+1)).indexOf("@")+1);
}else if(sumvariable==2){ //单个参数中引用第二个变量
}else if(sumvariable==2){
uservariable = casescript.get("FunctionParams"+(j+1)).substring(casescript.get("FunctionParams"+(j+1)).indexOf("@")+1,
casescript.get("FunctionParams"+(j+1)).lastIndexOf("@"));
uservariable1 = casescript.get("FunctionParams"+(j+1)).substring(
@ -332,7 +343,7 @@ public class TestLinkCaseExecution{
break;
}
}
if(sumvariable==2||sumvariable==3){ //处理第二个传参
if(sumvariable==2||sumvariable==3){
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
@ -344,7 +355,7 @@ public class TestLinkCaseExecution{
}
}
}
if(sumvariable==3){ //处理第三个传参
if(sumvariable==3){
keys = variable.keySet().iterator();
while(keys.hasNext()){
keyexistidentity = 0;
@ -358,37 +369,37 @@ public class TestLinkCaseExecution{
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
String parameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
if(parameterValues.indexOf("&quot;")>-1 || parameterValues.indexOf("&#39;")>-1){
parameterValues = parameterValues.replaceAll("&quot;", "\"");
parameterValues = parameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
getParameterValues[j] = ParameterValues;
+""+(j+1)+"个参数:"+parameterValues);
getParameterValues[j] = parameterValues;
}else{
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
String parameterValues1 = casescript.get("FunctionParams"+(j+1));
if(parameterValues1.indexOf("&quot;")>-1 || parameterValues1.indexOf("&#39;")>-1 || parameterValues1.indexOf("@@")>-1){
parameterValues1 = parameterValues1.replaceAll("&quot;", "\"");
parameterValues1 = parameterValues1.replaceAll("&#39;", "\'");
parameterValues1 = parameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
getParameterValues[j] = ParameterValues1;
+""+(j+1)+"个参数:"+parameterValues1);
getParameterValues[j] = parameterValues1;
}
}
}else{
@ -397,12 +408,12 @@ public class TestLinkCaseExecution{
//调用动态方法执行测试用例
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,0,"");
variable.put(ExpectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){ //把预期结果与测试结果做模糊匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
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,0,"");
variable.put(expectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(testnote.indexOf(expectedresults.substring(2))>-1){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
@ -414,7 +425,7 @@ public class TestLinkCaseExecution{
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if("".equals(expectedresults)||testnote.equals(expectedresults)){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例执行结果是:"+testnote+",与预期结果匹配成功!");
@ -426,7 +437,7 @@ public class TestLinkCaseExecution{
break; //某一步骤失败后此条用例置为失败退出
}
}
int waitsec = Integer.parseInt(casescript.get("StepWait").toString()); //获取步骤间等待时间
int waitsec = Integer.parseInt(casescript.get("StepWait").toString());
if(waitsec!=0){
Thread.sleep(waitsec*1000);
}

View File

@ -2,6 +2,17 @@ package luckyclient.caserun.exinterface.testlink;
import luckyclient.caserun.exinterface.TestControl;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ThreadForTestLinkBatchCase extends Thread{
private String projectname;
@ -16,8 +27,9 @@ public class ThreadForTestLinkBatchCase extends Thread{
this.tastid = tastid;
}
@Override
public void run(){
TestLinkCaseExecution.OneCaseExecuteForTast(projectname, testCaseExternalId, version, tastid);
TestLinkCaseExecution.oneCaseExecuteForTast(projectname, testCaseExternalId, version, tastid);
TestControl.Debugcount--; //多线程计数--用于检测线程是否全部执行完
}

View File

@ -13,8 +13,8 @@ import luckyclient.testlinkapi.InterfaceAnalyticTestLinkCase;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: ThreadForExecuteCase
* @Description: 线程池方式执行用例
@ -33,6 +33,7 @@ public class ThreadForTestLinkExecuteCase extends Thread{
this.tastid = tastid;
}
@Override
public void run(){
Map<String,String> variable = new HashMap<String,String>();
LogOperation caselog = new LogOperation(); //初始化写用例结果以及日志模块
@ -45,16 +46,16 @@ public class ThreadForTestLinkExecuteCase extends Thread{
int k = 0;
//进入循环解析单个用例所有步骤
System.out.println(caseid);
caselog.AddCaseDetail(tastid, testcaseob.getFullExternalId(), testcaseob.getVersion().toString(), testcaseob.getName(), 4); //插入开始执行的用例
caselog.addCaseDetail(tastid, testcaseob.getFullExternalId(), testcaseob.getVersion().toString(), testcaseob.getName(), 4); //插入开始执行的用例
for(int i=0;i<testcaseob.getSteps().size();i++){
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.AnalyticCaseStep(testcaseob, i+1,tastid,caselog); //解析单个步骤中的脚本
Map<String,String> casescript = InterfaceAnalyticTestLinkCase.analyticCaseStep(testcaseob, i+1,tastid,caselog); //解析单个步骤中的脚本
try{
packagename = casescript.get("PackageName").toString();
functionname = casescript.get("FunctionName").toString();
}catch(Exception e){
k=0;
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getFullExternalId()+"解析包名或是方法名失败,请检查!");
caselog.CaseLogDetail(tastid, caseid, "解析包名或是方法名失败,请检查!","error",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid, "解析包名或是方法名失败,请检查!","error",String.valueOf(i+1),"");
e.printStackTrace();
break; //某一步骤失败后此条用例置为失败退出
}
@ -105,7 +106,7 @@ public class ThreadForTestLinkExecuteCase extends Thread{
casescript.get("FunctionParams"+(j+1)).indexOf(uservariable1)-1);
}else{
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
caselog.CaseLogDetail(tastid, caseid, "你好像在一个参数中引用了超过2个以上的变量哦我处理不过来啦","error",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid, "你好像在一个参数中引用了超过2个以上的变量哦我处理不过来啦","error",String.valueOf(i+1),"");
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
@ -144,43 +145,43 @@ public class ThreadForTestLinkExecuteCase extends Thread{
}
if(keyexistidentity == 1){
//拼装参数传参+原有字符串
String ParameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
String parameterValues =casescript.get("FunctionParams"+(j+1)).replaceAll("@"+uservariable, variable.get(uservariable).toString());
//处理第二个传参
if(sumvariable==2||sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable1, variable.get(uservariable1).toString());
}
//处理第三个传参
if(sumvariable==3){
ParameterValues = ParameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
parameterValues = parameterValues.replaceAll("@"+uservariable2, variable.get(uservariable2).toString());
}
if(ParameterValues.indexOf("&quot;")>-1 || ParameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
ParameterValues = ParameterValues.replaceAll("&quot;", "\"");
ParameterValues = ParameterValues.replaceAll("&#39;", "\'");
if(parameterValues.indexOf("&quot;")>-1 || parameterValues.indexOf("&#39;")>-1){ //页面转义字符转换
parameterValues = parameterValues.replaceAll("&quot;", "\"");
parameterValues = parameterValues.replaceAll("&#39;", "\'");
}
luckyclient.publicclass.LogUtil.APP.info("解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues);
caselog.CaseLogDetail(tastid, caseid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues,"info",String.valueOf(i+1),"");
getParameterValues[j] = ParameterValues;
+""+(j+1)+"个参数:"+parameterValues);
caselog.caseLogDetail(tastid, caseid, "解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+parameterValues,"info",String.valueOf(i+1),"");
getParameterValues[j] = parameterValues;
}else{
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1+",第三个变量名称是:"+uservariable2);
caselog.CaseLogDetail(tastid, caseid, "没有找到你要的变量哦,再找下吧!第二变量名称是:"+uservariable+",第"
caselog.caseLogDetail(tastid, caseid, "没有找到你要的变量哦,再找下吧!第二变量名称是:"+uservariable+",第"
+ "二个变量名称是:"+uservariable1,"error",String.valueOf(i+1),"");
}
}else{
String ParameterValues1 = casescript.get("FunctionParams"+(j+1));
if(ParameterValues1.indexOf("&quot;")>-1 || ParameterValues1.indexOf("&#39;")>-1 || ParameterValues1.indexOf("@@")>-1){ //页面转义字符转换
ParameterValues1 = ParameterValues1.replaceAll("&quot;", "\"");
ParameterValues1 = ParameterValues1.replaceAll("&#39;", "\'");
ParameterValues1 = ParameterValues1.replaceAll("@@", "@");
String parameterValues1 = casescript.get("FunctionParams"+(j+1));
if(parameterValues1.indexOf("&quot;")>-1 || parameterValues1.indexOf("&#39;")>-1 || parameterValues1.indexOf("@@")>-1){ //页面转义字符转换
parameterValues1 = parameterValues1.replaceAll("&quot;", "\"");
parameterValues1 = parameterValues1.replaceAll("&#39;", "\'");
parameterValues1 = parameterValues1.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getFullExternalId()+"解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1);
caselog.CaseLogDetail(tastid, caseid,"解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+ParameterValues1,"info",String.valueOf(i+1),"");
getParameterValues[j] = ParameterValues1;
+""+(j+1)+"个参数:"+parameterValues1);
caselog.caseLogDetail(tastid, caseid,"解析包名:"+packagename+" 方法名:"+functionname
+""+(j+1)+"个参数:"+parameterValues1,"info",String.valueOf(i+1),"");
getParameterValues[j] = parameterValues1;
}
}
}else{
@ -189,36 +190,36 @@ public class ThreadForTestLinkExecuteCase extends Thread{
//调用动态方法执行测试用例
try{
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getFullExternalId()+"开始调用方法:"+functionname+" .....");
caselog.CaseLogDetail(tastid, caseid,"开始调用方法:"+functionname+" .....","info",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid,"开始调用方法:"+functionname+" .....","info",String.valueOf(i+1),"");
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,0,"");
variable.put(ExpectedResultVariable, temptestnote);
String expectedResultVariable = casescript.get("ExpectedResults").toString().substring(2);
String temptestnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
variable.put(expectedResultVariable, temptestnote);
}else if(expectedresults.length()>2 && expectedresults.substring(0, 2).indexOf("%=")>-1){ //把预期结果与测试结果做模糊匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(testnote.indexOf(expectedresults.substring(2))>-1){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getFullExternalId()+"执行结果是:"+testnote+",与预期结果匹配成功!");
caselog.CaseLogDetail(tastid, caseid,"执行结果是:"+testnote+",与预期结果匹配成功!","info",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid,"执行结果是:"+testnote+",与预期结果匹配成功!","info",String.valueOf(i+1),"");
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getFullExternalId()+""+(i+1)+"步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getFullExternalId()+"预期结果:"+expectedresults+" 测试结果:"+testnote);
caselog.CaseLogDetail(tastid, caseid,""+(i+1)+"步执行结果与预期结果匹配失败!"+"预期结果:"+expectedresults+" 测试结果:"+testnote,"error",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid,""+(i+1)+"步执行结果与预期结果匹配失败!"+"预期结果:"+expectedresults+" 测试结果:"+testnote,"error",String.valueOf(i+1),"");
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!";
break; //某一步骤失败后此条用例置为失败退出
}
}else{ //把预期结果与测试结果做精确匹配
testnote = InvokeMethod.CallCase(packagename,functionname,getParameterValues,0,"");
testnote = InvokeMethod.callCase(packagename,functionname,getParameterValues,0,"");
if(expectedresults.equals(testnote)){
setresult = 0;
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getFullExternalId()+"执行结果是:"+testnote+",与预期结果匹配成功!");
caselog.CaseLogDetail(tastid, caseid,"执行结果是:"+testnote+",与预期结果匹配成功!","info",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid,"执行结果是:"+testnote+",与预期结果匹配成功!","info",String.valueOf(i+1),"");
}else{
setresult = 1;
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getFullExternalId()+""+(i+1)+"步执行结果与预期结果匹配失败!");
luckyclient.publicclass.LogUtil.APP.error("用例:"+testcaseob.getFullExternalId()+"预期结果:"+expectedresults+" 测试结果:"+testnote);
caselog.CaseLogDetail(tastid, caseid,""+(i+1)+"步执行结果与预期结果匹配失败!"+"预期结果:"+expectedresults+" 测试结果:"+testnote,"error",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid,""+(i+1)+"步执行结果与预期结果匹配失败!"+"预期结果:"+expectedresults+" 测试结果:"+testnote,"error",String.valueOf(i+1),"");
testnote = "用例第"+(i+1)+"步执行结果与预期结果匹配失败!预期结果:"+expectedresults+" 测试结果:"+testnote;
break; //某一步骤失败后此条用例置为失败退出
}
@ -229,7 +230,7 @@ public class ThreadForTestLinkExecuteCase extends Thread{
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getFullExternalId()+"调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!");
caselog.CaseLogDetail(tastid, caseid,"调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!","error",String.valueOf(i+1),"");
caselog.caseLogDetail(tastid, caseid,"调用方法过程出错,方法名:"+functionname+" 请重新检查脚本方法名称以及参数!","error",String.valueOf(i+1),"");
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
testnote = "CallCase调用出错调用方法过程出错方法名"+functionname+" 请重新检查脚本方法名称以及参数!";
setresult = 1;
@ -241,32 +242,32 @@ public class ThreadForTestLinkExecuteCase extends Thread{
try{
if(testnote.indexOf("CallCase调用出错")<=-1&&testnote.indexOf("解析出错啦!")<=-1){ //成功跟失败的用例走此流程
//luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getFullExternalId()+"开始设置测试用例执行结果 .....");
//caselog.CaseLogDetail(tastid, caseid,"开始设置测试用例执行结果 .....","info","SETCASERESULT...");
//caselog.caseLogDetail(tastid, caseid,"开始设置测试用例执行结果 .....","info","SETCASERESULT...");
//TCResult = TestCaseApi.setTCResult(projectname,caseid, testnote, testcaseob.getVersion(),setresult);
caselog.UpdateCaseDetail(tastid, caseid, setresult);
caselog.updateCaseDetail(tastid, caseid, setresult);
}else{
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getFullExternalId()+"设置执行结果为锁定,请参考错误日志查找锁定用例的原因....."); //解析用例或是调用方法出错全部把用例置为锁定
caselog.CaseLogDetail(tastid, caseid,"设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....","error","SETCASERESULT...","");
caselog.caseLogDetail(tastid, caseid,"设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....","error","SETCASERESULT...","");
//TCResult = TestCaseApi.setTCResult(projectname,caseid, testnote, testcaseob.getVersion(),2);
setresult = 2;
caselog.UpdateCaseDetail(tastid, caseid, setresult);
caselog.updateCaseDetail(tastid, caseid, setresult);
}
if(setresult==0){
luckyclient.publicclass.LogUtil.APP.info("用例:"+testcaseob.getFullExternalId()+"执行结果成功......");
caselog.CaseLogDetail(tastid, caseid,"用例步骤执行全部成功......","info","ending","");
caselog.caseLogDetail(tastid, caseid,"用例步骤执行全部成功......","info","ending","");
luckyclient.publicclass.LogUtil.APP.info("******************************分割线*************************************");
}else if(setresult==1){
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getFullExternalId()+"执行结果失败......");
caselog.CaseLogDetail(tastid, caseid,"用例执行结果失败......","error","ending","");
caselog.caseLogDetail(tastid, caseid,"用例执行结果失败......","error","ending","");
luckyclient.publicclass.LogUtil.APP.info("******************************分割线*************************************");
}else{
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getFullExternalId()+"执行结果锁定......");
caselog.CaseLogDetail(tastid, caseid,"用例执行结果锁定......","error","ending","");
caselog.caseLogDetail(tastid, caseid,"用例执行结果锁定......","error","ending","");
luckyclient.publicclass.LogUtil.APP.info("******************************分割线*************************************");
}
}catch(Exception e){
luckyclient.publicclass.LogUtil.ERROR.error("用例:"+testcaseob.getFullExternalId()+"设置执行结果过程出错......");
caselog.CaseLogDetail(tastid, caseid,"设置执行结果过程出错......","error","ending","");
caselog.caseLogDetail(tastid, caseid,"设置执行结果过程出错......","error","ending","");
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
e.printStackTrace();
}finally{

View File

@ -9,6 +9,17 @@ import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class BaseWebDrive {
/**
@ -16,7 +27,7 @@ public class BaseWebDrive {
* @throws IOException
* @throws IOException
*/
public static Boolean WebScreenShot(WebDriver driver,String imgname) {
public static Boolean webScreenShot(WebDriver driver,String imgname) {
Boolean result = false;
String relativelyPath = System.getProperty("user.dir");

View File

@ -12,18 +12,31 @@ import luckyclient.dblog.LogOperation;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class CaseLocalDebug{
public static void OneCasedebug(WebDriver wd,String testCaseExternalId){
public static void oneCasedebug(WebDriver wd,String testCaseExternalId){
DbLink.exetype = 1; //不记录日志到数据库
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
try {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectid()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(testcase.getId());
WebCaseExecution.CaseExcution(testcase,steps, "888888",wd,caselog);
WebCaseExecution.caseExcution(testcase,steps, "888888",wd,caselog,pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【"+testcase.getSign()+"】执行完成......进入下一条");
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
@ -39,7 +52,7 @@ public class CaseLocalDebug{
* @param 用例版本号
* 用于在testlink上配置好用例参数后做多条用例串行调试
*/
public static void MoreCaseDebug(WebDriver wd,String projectname,Map<String,Integer> addtestcase){
public static void moreCaseDebug(WebDriver wd,String projectname,Map<String,Integer> addtestcase){
System.out.println(addtestcase.size());
@SuppressWarnings("rawtypes")
Iterator it=addtestcase.entrySet().iterator();
@ -50,7 +63,7 @@ public class CaseLocalDebug{
Integer version = (Integer)entry.getValue();
try{
luckyclient.publicclass.LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:"+testCaseExternalId+",用例版本:"+version);
OneCasedebug(wd,testCaseExternalId);
oneCasedebug(wd,testCaseExternalId);
}catch(Exception e){
continue;
}

View File

@ -10,10 +10,20 @@ 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 operation_value) throws Exception{
public static String selectOperation(WebElement we,String operation,String operationValue) throws Exception{
String result = "";
// 下拉框对象处理
Select select = new Select(we);
@ -21,16 +31,16 @@ public class EncapsulateOperation {
// 处理下拉框事件
switch (operation) {
case "selectbyvisibletext":
select.selectByVisibleText(operation_value);
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operation_value + "");
select.selectByVisibleText(operationValue);
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operationValue + "");
break;
case "selectbyvalue":
select.selectByValue(operation_value);
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:" + operation_value + "");
select.selectByValue(operationValue);
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "");
break;
case "selectbyindex":
select.selectByIndex(Integer.valueOf(operation_value));
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:" + operation_value + "");
select.selectByIndex(Integer.valueOf(operationValue));
luckyclient.publicclass.LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "");
break;
case "isselect":
result = "获取到的值是【"+we.isSelected()+"";
@ -42,7 +52,7 @@ public class EncapsulateOperation {
return result;
}
public static String GetOperation(WebDriver wd,WebElement we,String operation) throws Exception{
public static String getOperation(WebDriver wd,WebElement we,String operation) throws Exception{
String result = "";
// 获取对象处理
switch (operation) {
@ -64,45 +74,45 @@ public class EncapsulateOperation {
return result;
}
public static String ActionWeOperation(WebDriver wd,WebElement we,String operation,String operation_value,String property,String property_value) throws Exception{
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+"; 定位属性值:"+property_value+"";
luckyclient.publicclass.LogUtil.APP.info("mouselkclick鼠标左键点击对象...【对象定位属性:"+property+"; 定位属性值:"+property_value+"");
result = "mouselkclick鼠标左键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mouselkclick鼠标左键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mouserkclick":
action.contextClick(we).perform();
result = "mouserkclick鼠标右键点击对象...【对象定位属性:"+property+"; 定位属性值:"+property_value+"";
luckyclient.publicclass.LogUtil.APP.info("mouserkclick鼠标右键点击对象...【对象定位属性:"+property+"; 定位属性值:"+property_value+"");
result = "mouserkclick鼠标右键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mouserkclick鼠标右键点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mousedclick":
action.doubleClick(we).perform();
result = "mousedclick鼠标双击对象...【对象定位属性:"+property+"; 定位属性值:"+property_value+"";
luckyclient.publicclass.LogUtil.APP.info("mousedclick鼠标双击对象...【对象定位属性:"+property+"; 定位属性值:"+property_value+"");
result = "mousedclick鼠标双击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mousedclick鼠标双击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mouseclickhold":
action.clickAndHold(we).perform();
result = "mouseclickhold鼠标点击对象后不释放...【对象定位属性:"+property+"; 定位属性值:"+property_value+"";
luckyclient.publicclass.LogUtil.APP.info("mouseclickhold鼠标点击对象后不释放...【对象定位属性:"+property+"; 定位属性值:"+property_value+"");
result = "mouseclickhold鼠标点击对象后不释放...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("mouseclickhold鼠标点击对象后不释放...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "mousedrag":
String temp[]=operation_value.split(",",-1);
String[] temp=operationValue.split(",",-1);
action.dragAndDropBy(we, Integer.valueOf(temp[0]), Integer.valueOf(temp[1])).perform();
result = "mousedrag鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+property_value+"】 坐标x"+Integer.valueOf(temp[0])
result = "mousedrag鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp[0])
+" 坐标y"+Integer.valueOf(temp[1]);
luckyclient.publicclass.LogUtil.APP.info("mousedrag鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+property_value+"】 坐标x"+Integer.valueOf(temp[0])
luckyclient.publicclass.LogUtil.APP.info("mousedrag鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp[0])
+" 坐标y"+Integer.valueOf(temp[1]));
break;
case "mouseto":
String temp1[]=operation_value.split(",",-1);
String[] temp1=operationValue.split(",",-1);
action.moveToElement(we, Integer.valueOf(temp1[0]), Integer.valueOf(temp1[1])).perform();
result = "mouseto鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+property_value+"】 坐标x"+Integer.valueOf(temp1[0])
result = "mouseto鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp1[0])
+" 坐标y"+Integer.valueOf(temp1[1]);
luckyclient.publicclass.LogUtil.APP.info("mouseto鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+property_value+"】 坐标x"+Integer.valueOf(temp1[0])
luckyclient.publicclass.LogUtil.APP.info("mouseto鼠标移动至对象相对坐标...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"】 坐标x"+Integer.valueOf(temp1[0])
+" 坐标y"+Integer.valueOf(temp1[1]));
break;
case "mouserelease":
@ -116,7 +126,7 @@ public class EncapsulateOperation {
return result;
}
public static String ActionOperation(WebDriver wd,String operation,String operation_value) throws Exception{
public static String actionOperation(WebDriver wd,String operation,String operationValue) throws Exception{
String result = "";
Actions action = new Actions(wd);
// action处理
@ -142,7 +152,7 @@ public class EncapsulateOperation {
luckyclient.publicclass.LogUtil.APP.info("mouseclickhold鼠标点击当前位置后不释放...");
break;
case "mouseto":
String temp1[]=operation_value.split(",",-1);
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]);
@ -155,7 +165,7 @@ public class EncapsulateOperation {
luckyclient.publicclass.LogUtil.APP.info("mouserelease鼠标释放...");
break;
case "mousekey":
switch (operation_value) {
switch (operationValue) {
case "tab":
action.sendKeys(Keys.TAB).perform();
result = "键盘操作TAB键...";
@ -191,28 +201,28 @@ public class EncapsulateOperation {
return result;
}
public static String ObjectOperation(WebDriver wd,WebElement we,String operation,String operation_value,String property,String property_value) throws Exception{
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+"; 定位属性值:"+property_value+"";
luckyclient.publicclass.LogUtil.APP.info("click点击对象...【对象定位属性:"+property+"; 定位属性值:"+property_value+"");
result = "click点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"";
luckyclient.publicclass.LogUtil.APP.info("click点击对象...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "sendkeys":
we.sendKeys(operation_value);
result = "sendKeys对象输入...【对象定位属性:"+property+"; 定位属性值:"+property_value+"; 操作值:"+operation_value+"";
luckyclient.publicclass.LogUtil.APP.info("sendkeys对象输入...【对象定位属性:"+property+"; 定位属性值:"+property_value+"; 操作值:"+operation_value+"");
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+"; 定位属性值:"+property_value+"";
luckyclient.publicclass.LogUtil.APP.info("clear清空输入框...【对象定位属性:"+property+"; 定位属性值:"+property_value+"");
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+"; 定位属性值:"+property_value+"");
luckyclient.publicclass.LogUtil.APP.info("gotoframe切换Frame...【对象定位属性:"+property+"; 定位属性值:"+propertyValue+"");
break;
case "isenabled":
result = "获取到的值是【"+we.isEnabled()+"";
@ -224,9 +234,9 @@ public class EncapsulateOperation {
break;
case "exjsob":
JavascriptExecutor jse = (JavascriptExecutor)wd;
jse.executeScript(operation_value,we);
result = "执行JS...【"+operation_value+"";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【"+operation_value+"");
jse.executeScript(operationValue,we);
result = "执行JS...【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【"+operationValue+"");
break;
default:
break;
@ -234,7 +244,7 @@ public class EncapsulateOperation {
return result;
}
public static String AlertOperation(WebDriver wd,String operation) throws Exception{
public static String alertOperation(WebDriver wd,String operation) throws Exception{
String result = "";
Alert alert = wd.switchTo().alert();
switch (operation) {
@ -256,21 +266,21 @@ public class EncapsulateOperation {
return result;
}
public static String DriverOperation(WebDriver wd,String operation,String operation_value) throws Exception{
public static String driverOperation(WebDriver wd,String operation,String operationValue) throws Exception{
String result = "";
// 处理页面对象操作
switch (operation) {
case "open":
operation_value = "http://"+operation_value;
wd.get(operation_value);
result = "Open页面...【"+operation_value+"";
luckyclient.publicclass.LogUtil.APP.info("Open页面...【"+operation_value+"");
operationValue = "http://"+operationValue;
wd.get(operationValue);
result = "Open页面...【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("Open页面...【"+operationValue+"");
break;
case "exjs":
JavascriptExecutor jse = (JavascriptExecutor)wd;
jse.executeScript(operation_value);
result = "执行JS...【"+operation_value+"";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【"+operation_value+"");
jse.executeScript(operationValue);
result = "执行JS...【"+operationValue+"";
luckyclient.publicclass.LogUtil.APP.info("执行JS...【"+operationValue+"");
break;
case "gotodefaultcontent":
wd.switchTo().defaultContent();
@ -285,14 +295,14 @@ public class EncapsulateOperation {
luckyclient.publicclass.LogUtil.APP.info("getWindowHandle获取窗口句柄...【句柄值:" + result + "");
break;
case "gotowindow":
wd.switchTo().window(operation_value);
wd.switchTo().window(operationValue);
luckyclient.publicclass.LogUtil.APP.info("gotowindow切换句柄指定窗口...");
break;
case "wait":
try {
wd.wait(Integer.valueOf(operation_value) * 1000);
result = "当前任务操作等待【"+operation_value+"】秒...";
luckyclient.publicclass.LogUtil.APP.info("当前任务操作等待【"+operation_value+"】秒...");
wd.wait(Integer.valueOf(operationValue) * 1000);
result = "当前任务操作等待【"+operationValue+"】秒...";
luckyclient.publicclass.LogUtil.APP.info("当前任务操作等待【"+operationValue+"】秒...");
break;
} catch (NumberFormatException | InterruptedException e) {
luckyclient.publicclass.LogUtil.APP.error("等待时间转换出错 ");

View File

@ -12,7 +12,17 @@ import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebDriverInitialization{
/**
* @param args

View File

@ -1,6 +1,7 @@
package luckyclient.caserun.exwebdriver;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.PropertyConfigurator;
@ -20,10 +21,22 @@ import luckyclient.mail.MailSendInitialization;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.planapi.entity.TestTaskexcute;
import luckyclient.testlinkapi.TestBuildApi;
import luckyclient.testlinkapi.TestCaseApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebTestControl{
/**
@ -32,7 +45,7 @@ public class WebTestControl{
* 控制台模式调度计划执行用例
*/
public static void ManualExecutionPlan(String planname){
public static void manualExecutionPlan(String planname){
DbLink.exetype = 1; //不记日志到数据库
String taskid = "888888";
WebDriver wd = null;
@ -44,6 +57,10 @@ public class WebTestControl{
}
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
List<ProjectCase> testCases=GetServerAPI.getCasesbyplanname(planname);
List<PublicCaseParams> pcplist = new ArrayList<PublicCaseParams>();
if(testCases.size()!=0){
pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectid()));
}
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 "+testCases.size()+"");
int i=0;
for(ProjectCase testcase:testCases){
@ -54,7 +71,7 @@ public class WebTestControl{
i++;
luckyclient.publicclass.LogUtil.APP.info("开始执行第"+i+"条用例:【"+testcase.getSign()+"】......");
try {
WebCaseExecution.CaseExcution(testcase,steps,taskid,wd,caselog);
WebCaseExecution.caseExcution(testcase,steps,taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
@ -67,15 +84,16 @@ public class WebTestControl{
wd.quit();
}
public static void TaskExecutionPlan(String taskid,TestTaskexcute task) throws InterruptedException {
public static void taskExecutionPlan(String taskid,TestTaskexcute task) throws InterruptedException {
DbLink.exetype = 0; // 记录日志到数据库
TestControl.TASKID = taskid;
String restartstatus = RestartServerInitialization.RestartServerRun(taskid);
String buildstatus = BuildingInitialization.BuildingRun(taskid);
String restartstatus = RestartServerInitialization.restartServerRun(taskid);
String buildstatus = BuildingInitialization.buildingRun(taskid);
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(task.getTestJob().getProjectid().toString());
String projectname=task.getTestJob().getPlanproj();
task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
String jobname = task.getTestJob().getTaskName();
int drivertype = LogOperation.Querydrivertype(taskid);
int drivertype = LogOperation.querydrivertype(taskid);
// 判断是否要自动重启TOMCAT
if (restartstatus.indexOf("Status:true") > -1) {
// 判断是否构建是否成功
@ -93,10 +111,10 @@ public class WebTestControl{
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
int[] tastcount=null;
if(task.getTestJob().getProjecttype()==1){
TestBuildApi.GetBuild(projectname);
TestBuildApi.getBuild(projectname);
TestCase[] testCases = TestCaseApi.getplantestcase(projectname, taskid,"");
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + testCases.length + "");
LogOperation.UpdateTastStatus(taskid,testCases.length);
LogOperation.updateTastStatus(taskid,testCases.length);
for (TestCase testcase : testCases) {
if (testcase.getSteps().size() == 0) {
@ -104,7 +122,7 @@ public class WebTestControl{
}
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testcase.getFullExternalId() + "】......");
try {
WebCaseExecutionTestLink.CaseExcution(projectname, testcase, taskid, wd, caselog);
WebCaseExecutionTestLink.caseExcution(projectname, testcase, taskid, wd, caselog);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
@ -112,11 +130,11 @@ public class WebTestControl{
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getFullExternalId() + "】执行完成......进入下一条");
}
tastcount = LogOperation.UpdateTastdetail(taskid, testCases.length);
tastcount = LogOperation.updateTastdetail(taskid, testCases.length);
}else if(task.getTestJob().getProjecttype()==0){
List<ProjectCase> cases=GetServerAPI.getCasesbyplanid(task.getTestJob().getPlanid());
luckyclient.publicclass.LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + "");
LogOperation.UpdateTastStatus(taskid,cases.size());
LogOperation.updateTastStatus(taskid,cases.size());
for (ProjectCase testcase : cases) {
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(testcase.getId());
@ -125,7 +143,7 @@ public class WebTestControl{
}
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【" + testcase.getSign() + "】......");
try {
WebCaseExecution.CaseExcution(testcase, steps, taskid, wd, caselog);
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog,pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
@ -133,22 +151,22 @@ public class WebTestControl{
}
luckyclient.publicclass.LogUtil.APP.info("当前用例:【" + testcase.getSign() + "】执行完成......进入下一条");
}
tastcount = LogOperation.UpdateTastdetail(taskid, cases.size());
tastcount = LogOperation.updateTastdetail(taskid, cases.size());
}
String testtime = LogOperation.GetTestTime(taskid);
String testtime = LogOperation.getTestTime(taskid);
luckyclient.publicclass.LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
MailSendInitialization.SendMailInitialization(HtmlMail.HtmlSubjectFormat(jobname),
HtmlMail.HtmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime,jobname), taskid);
// 关闭浏览器
wd.quit();
} else {
luckyclient.publicclass.LogUtil.APP.error("项目构建失败自动化测试自动退出请前往JENKINS中检查项目构建情况。");
MailSendInitialization.SendMailInitialization(jobname,
MailSendInitialization.sendMailInitialization(jobname,
"构建项目过程中失败自动化测试自动退出请前去JENKINS查看构建情况", taskid);
}
} else {
luckyclient.publicclass.LogUtil.APP.error("项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况。");
MailSendInitialization.SendMailInitialization(jobname,
MailSendInitialization.sendMailInitialization(jobname,
"项目TOMCAT重启失败自动化测试自动退出请检查项目TOMCAT运行情况", taskid);
}
}

View File

@ -13,15 +13,28 @@ 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.planapi.entity.TestTaskexcute;
import luckyclient.testlinkapi.TestBuildApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebBatchExecute{
@SuppressWarnings("static-access")
public static void BatchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws IOException{
public static void batchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws IOException{
DbLink.exetype = 0; //记录日志到数据库
TestControl.TASKID = taskid;
int drivertype = LogOperation.Querydrivertype(taskid);
int drivertype = LogOperation.querydrivertype(taskid);
WebDriver wd = null;
try {
wd = WebDriverInitialization.setWebDriverForTask(taskid,drivertype);
@ -30,19 +43,21 @@ public class WebBatchExecute{
e1.printStackTrace();
}
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
TestBuildApi.GetBuild(projectname);
TestBuildApi.getBuild(projectname);
TestTaskexcute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(task.getTestJob().getProjectid().toString());
if(batchcase.indexOf("ALLFAIL")>-1){ //执行全部非成功状态用例
String casemore = caselog.UnSucCaseUpdate(taskid);
String temp[]=casemore.split("\\#",-1);
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp=casemore.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
//int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()-1));
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(testcase.getId());
caselog.DeleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
caselog.DeleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
LogOperation.deleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
try {
WebCaseExecution.CaseExcution(testcase, steps, taskid,wd,caselog);
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
@ -50,14 +65,14 @@ public class WebBatchExecute{
}
}
}else{ //批量执行用例
String temp[]=batchcase.split("\\#",-1);
String[] temp=batchcase.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
//int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()));
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(testcase.getId());
try {
WebCaseExecution.CaseExcution(testcase, steps,taskid,wd,caselog);
WebCaseExecution.caseExcution(testcase, steps,taskid,wd,caselog,pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);

View File

@ -2,7 +2,6 @@ package luckyclient.caserun.exwebdriver.ex;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -16,21 +15,37 @@ import luckyclient.caserun.exwebdriver.EncapsulateOperation;
import luckyclient.dblog.LogOperation;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.publicclass.DBOperation;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.publicclass.ChangString;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebCaseExecution extends TestCaseExecution{
static Map<String, String> variable = new HashMap<String, String>();
public static void CaseExcution(ProjectCase testcase, List<ProjectCasesteps> steps,String taskid, WebDriver wd,LogOperation caselog)
public static void caseExcution(ProjectCase testcase, List<ProjectCasesteps> steps,String taskid, WebDriver wd,LogOperation caselog,List<PublicCaseParams> pcplist)
throws InterruptedException {
int setresult = 0; // 0:成功 1:失败 2:锁定 其他锁定
String casenote = "备注初始化";
String imagname = "";
// 把公共参数加入到MAP中
for (PublicCaseParams pcp : pcplist) {
variable.put(pcp.getParamsname(), pcp.getParamsvalue());
}
caselog.AddCaseDetail(taskid, testcase.getSign(), "1", testcase.getName(), 4); //插入开始执行的用例
caselog.addCaseDetail(taskid, testcase.getSign(), "1", testcase.getName(), 4); //插入开始执行的用例
for (ProjectCasesteps step : steps) {
Map<String, String> params = WebDriverAnalyticCase.AnalyticCaseStep(testcase, step, taskid,caselog);
Map<String, String> params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog);
if(params.get("exception")!=null&&params.get("exception").toString().indexOf("解析异常")>-1){
setresult = 2;
@ -40,6 +55,7 @@ public class WebCaseExecution extends TestCaseExecution{
String result = WebCaseExecution.runStep(params, wd, taskid, testcase.getSign(), step.getStepnum(), caselog);
String expectedResults = params.get("ExpectedResults").toString();
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
if (result.indexOf("出错") < 0 && result.indexOf("失败") < 0) { // 运行结果正常
int waitsec = Integer.parseInt(params.get("StepWait").toString()); // 获取步骤间等待时间
@ -48,25 +64,25 @@ public class WebCaseExecution extends TestCaseExecution{
Thread.sleep(waitsec * 1000);
}
if (!expectedResults.equals("")) { // 有预期结果
if (!"".equals(expectedResults)) { // 有预期结果
// 判断传参
luckyclient.publicclass.LogUtil.APP.info("expectedResults=【"+expectedResults+"");
if (expectedResults.length() > 2 && expectedResults.substring(0, 2).indexOf("$=") > -1) {
String ExpectedResultVariable = expectedResults.substring(2);
variable.put(ExpectedResultVariable, result);
String expectedResultVariable = expectedResults.substring(2);
variable.put(expectedResultVariable, result);
continue;
}
// 判断预期结果-检查模式
if (params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
String checkproperty = params.get("checkproperty").toString();
String checkproperty_value = params.get("checkproperty_value").toString();
String checkPropertyValue = params.get("checkproperty_value").toString();
WebElement we = isElementExist(wd, checkproperty, 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(), "在当前页面中找到预期结果中对象。当前步骤执行成功!",
caselog.caseLogDetail(taskid, testcase.getSign(), "在当前页面中找到预期结果中对象。当前步骤执行成功!",
"info", String.valueOf(step.getStepnum()),"");
continue;
} else {
@ -74,11 +90,11 @@ public class WebCaseExecution extends TestCaseExecution{
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum()
+ "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
caselog.CaseLogDetail(taskid, testcase.getSign(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!"
+ "checkproperty【"+checkproperty+"】 checkproperty_value【"+checkproperty_value+"","error", String.valueOf(step.getStepnum()),imagname);
caselog.caseLogDetail(taskid, testcase.getSign(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!"
+ "checkproperty【"+checkproperty+"】 checkproperty_value【"+checkPropertyValue+"","error", String.valueOf(step.getStepnum()),imagname);
break;
}
@ -88,7 +104,7 @@ public class WebCaseExecution extends TestCaseExecution{
if(result.indexOf(expectedResults.substring(2))>-1){
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getSign() + "" + step.getStepnum()
+ "步,模糊匹配预期结果成功!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getSign(), "步骤模糊匹配预期结果成功!",
caselog.caseLogDetail(taskid, testcase.getSign(), "步骤模糊匹配预期结果成功!",
"info", String.valueOf(step.getStepnum()),"");
continue;
}else{
@ -96,17 +112,17 @@ public class WebCaseExecution extends TestCaseExecution{
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum()
+ "步,模糊匹配预期结果失败!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getSign(), "步骤模糊匹配预期结果失败!执行结果:"+result,
caselog.caseLogDetail(taskid, testcase.getSign(), "步骤模糊匹配预期结果失败!执行结果:"+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(), "步骤直接匹配预期结果成功!",
caselog.caseLogDetail(taskid, testcase.getSign(), "步骤直接匹配预期结果成功!",
"info", String.valueOf(step.getStepnum()),"");
continue;
} else {
@ -114,10 +130,10 @@ public class WebCaseExecution extends TestCaseExecution{
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum()
+ "步,直接匹配预期结果失败!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getSign(), "步骤直接匹配预期结果失败!执行结果:"+result,
caselog.caseLogDetail(taskid, testcase.getSign(), "步骤直接匹配预期结果失败!执行结果:"+result,
"error", String.valueOf(step.getStepnum()),imagname);
break;
}
@ -129,9 +145,9 @@ public class WebCaseExecution extends TestCaseExecution{
setresult = 2;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getSign() + "" + step.getStepnum() + "步,"+result);
caselog.CaseLogDetail(taskid, testcase.getSign(), "当前步骤在执行过程中解析|定位元素|操作对象失败!"+result,
caselog.caseLogDetail(taskid, testcase.getSign(), "当前步骤在执行过程中解析|定位元素|操作对象失败!"+result,
"error", String.valueOf(step.getStepnum()),imagname);
break;
}
@ -139,13 +155,13 @@ public class WebCaseExecution extends TestCaseExecution{
}
variable.clear();
caselog.UpdateCaseDetail(taskid, testcase.getSign(), setresult);
caselog.updateCaseDetail(taskid, testcase.getSign(), setresult);
if(setresult==0){
luckyclient.publicclass.LogUtil.APP.info("用例【"+testcase.getSign()+"】全部步骤执行结果成功...");
caselog.CaseLogDetail(taskid, testcase.getSign(), "用例全部步骤执行结果成功","info", "ending","");
caselog.caseLogDetail(taskid, testcase.getSign(), "用例全部步骤执行结果成功","info", "ending","");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getSign()+"】步骤执行过程中失败或是锁定...请查看具体原因!"+casenote);
caselog.CaseLogDetail(taskid, testcase.getSign(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
caselog.caseLogDetail(taskid, testcase.getSign(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
}
//LogOperation.UpdateTastdetail(taskid, 0);
}
@ -153,47 +169,24 @@ public class WebCaseExecution extends TestCaseExecution{
private static String runStep(Map<String, String> params, WebDriver wd,String taskid,String casenum,int stepno,LogOperation caselog) {
String result = "";
String property;
String property_value;
String propertyValue;
String operation;
String operation_value;
String operationValue;
try {
property = params.get("property");
property_value = params.get("property_value");
propertyValue = params.get("property_value");
operation = params.get("operation");
operation_value = params.get("operation_value");
operationValue = params.get("operation_value");
// 处理值传递
if (property_value != null && property_value.indexOf("@") > -1 && property_value.indexOf("[@") < 0
&& property_value.indexOf("@@") < 0) {
property_value = SettingParameter(property_value);
// 判断传参是否存在问题
if (property_value.indexOf("Set parameter error") > -1) {
caselog.CaseLogDetail(taskid, casenum, "当前步骤解析出现异常或是对象为空!---"+property,
"error", String.valueOf(stepno),"");
return "处理传参过程出错:" + property_value;
}
}else if(property_value != null && (property_value.indexOf("&quot;")>-1
|| property_value.indexOf("&#39;")>-1 || property_value.indexOf("@@")>-1)){
property_value = property_value.replaceAll("&quot;", "\"");
property_value = property_value.replaceAll("&#39;", "\'");
property_value = property_value.replaceAll("@@", "@");
}
if (operation_value != null && operation_value.indexOf("@") > -1 && operation_value.indexOf("@@") < 0) {
operation_value = SettingParameter(operation_value);
if (operation_value.indexOf("Set parameter error") > -1) {
return "处理传参过程出错:" + property_value;
}
}else if(operation_value != null && (operation_value.indexOf("&quot;")>-1
|| operation_value.indexOf("&#39;")>-1 || operation_value.indexOf("@@")>-1)){
operation_value = operation_value.replaceAll("&quot;", "\"");
operation_value = operation_value.replaceAll("&#39;", "\'");
operation_value = operation_value.replaceAll("@@", "@");
}
property = ChangString.changparams(property, variable,"定位方式");
propertyValue=ChangString.changparams(propertyValue, variable,"定位路径");
operation=ChangString.changparams(operation, variable,"操作");
operationValue=ChangString.changparams(operationValue, variable,"操作参数");
luckyclient.publicclass.LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
caselog.CaseLogDetail(taskid, casenum, "对象操作:"+operation+"; 操作值:"+operation_value,"info", String.valueOf(stepno),"");
caselog.caseLogDetail(taskid, casenum, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
} catch (Exception e) {
e.printStackTrace();
@ -203,9 +196,9 @@ public class WebCaseExecution extends TestCaseExecution{
try {
//调用接口用例
if(null != operation&&null != operation_value&&"runcase".equals(operation)){
String temp[]=operation_value.split(",",-1);
String ex = TestCaseExecution.OneCaseExecuteForWebDriver(temp[0],taskid,caselog);
if(null != operation&&null != operationValue&&"runcase".equals(operation)){
String[] temp=operationValue.split(",",-1);
String ex = TestCaseExecution.oneCaseExecuteForWebDriver(temp[0],taskid,caselog);
if(ex.indexOf("CallCase调用出错")<=-1&&ex.indexOf("解析出错啦!")<=-1&&ex.indexOf("匹配失败")<=-1){
return ex;
}else{
@ -215,8 +208,8 @@ public class WebCaseExecution extends TestCaseExecution{
WebElement we = null;
if (null != property && null != property_value) { // 页面元素层
we = isElementExist(wd, property, property_value);
if (null != property && null != propertyValue) { // 页面元素层
we = isElementExist(wd, property, propertyValue);
// 判断此元素是否存在
if (null==we) {
luckyclient.publicclass.LogUtil.APP.error("定位对象失败isElementExist为null!");
@ -224,22 +217,22 @@ public class WebCaseExecution extends TestCaseExecution{
}
if (operation.indexOf("select") > -1) {
result = EncapsulateOperation.SelectOperation(we, operation, operation_value);
result = EncapsulateOperation.selectOperation(we, operation, operationValue);
} else if (operation.indexOf("get") > -1){
result = EncapsulateOperation.GetOperation(wd, we, operation);
result = EncapsulateOperation.getOperation(wd, we, operation);
} else if (operation.indexOf("mouse") > -1){
result = EncapsulateOperation.ActionWeOperation(wd, we, operation, operation_value, property, property_value);
result = EncapsulateOperation.actionWeOperation(wd, we, operation, operationValue, property, propertyValue);
} else {
result = EncapsulateOperation.ObjectOperation(wd, we, operation, operation_value, property, property_value);
result = EncapsulateOperation.objectOperation(wd, we, operation, operationValue, property, propertyValue);
}
} else if (null==property && null != operation) { // Driver层操作
// 处理弹出框事件
if (operation.indexOf("alert") > -1){
result = EncapsulateOperation.AlertOperation(wd, operation);
result = EncapsulateOperation.alertOperation(wd, operation);
}else if(operation.indexOf("mouse") > -1){
result = EncapsulateOperation.ActionOperation(wd, operation, operation_value);
result = EncapsulateOperation.actionOperation(wd, operation, operationValue);
}else{
result = EncapsulateOperation.DriverOperation(wd, operation, operation_value);
result = EncapsulateOperation.driverOperation(wd, operation, operationValue);
}
}else{
luckyclient.publicclass.LogUtil.APP.error("元素操作过程失败!");
@ -249,7 +242,7 @@ public class WebCaseExecution extends TestCaseExecution{
luckyclient.publicclass.LogUtil.APP.error("元素定位过程或是操作过程失败或异常!"+e.getMessage());
return "元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
caselog.CaseLogDetail(taskid, casenum, result,"info", String.valueOf(stepno),"");
caselog.caseLogDetail(taskid, casenum, result,"info", String.valueOf(stepno),"");
if(result.indexOf("获取到的值是【")>-1&&result.indexOf("")>-1){
result = result.substring(7, result.length()-1);
@ -258,119 +251,29 @@ public class WebCaseExecution extends TestCaseExecution{
}
private static String SettingParameter(String parameter) {
int keyexistidentity = 0;
if (parameter.indexOf("&quot;") > -1 || parameter.indexOf("&#39;") > -1) { // 页面转义字符转换
parameter = parameter.replaceAll("&quot;", "\"");
parameter = parameter.replaceAll("&#39;", "\'");
}
//处理参数字符串中带@的情况
if(parameter.indexOf("\\@")>-1){
return parameter.replace("\\@", "@");
}
// 取单个参数中引用变量次数
int sumvariable = DBOperation.sumString(parameter, "@");
String uservariable = null;
String uservariable1 = null;
String uservariable2 = null;
if (sumvariable == 1) {
uservariable = parameter.substring(parameter.indexOf("@") + 1);
} else if (sumvariable == 2) { // 单个参数中引用第二个变量
uservariable = parameter.substring(parameter.indexOf("@") + 1, parameter.lastIndexOf("@"));
uservariable1 = parameter.substring(parameter.lastIndexOf("@") + 1);
} else if (sumvariable == 3) {
String temp = parameter.substring(parameter.indexOf("@") + 1, parameter.lastIndexOf("@"));
uservariable1 = temp.substring(temp.indexOf("@") + 1);
uservariable2 = parameter.substring(parameter.lastIndexOf("@") + 1);
uservariable = parameter.substring(parameter.indexOf("@") + 1, parameter.indexOf(uservariable1) - 1);
} else {
luckyclient.publicclass.LogUtil.APP.error("你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦");
return "你好像在一个参数中引用了超过3个以上的变量哦我处理不过来啦【Set parameter error】";
}
@SuppressWarnings("rawtypes")
Iterator keys = variable.keySet().iterator();
String key = null;
while (keys.hasNext()) {
key = (String) keys.next();
if (uservariable.indexOf(key) > -1) {
keyexistidentity = 1;
uservariable = key;
break;
}
}
if (sumvariable == 2 || sumvariable == 3) { // 处理第二个传参
keys = variable.keySet().iterator();
while (keys.hasNext()) {
keyexistidentity = 0;
key = (String) keys.next();
if (uservariable1.indexOf(key) > -1) {
keyexistidentity = 1;
uservariable1 = key;
break;
}
}
}
if (sumvariable == 3) { // 处理第三个传参
keys = variable.keySet().iterator();
while (keys.hasNext()) {
keyexistidentity = 0;
key = (String) keys.next();
if (uservariable2.indexOf(key) > -1) {
keyexistidentity = 1;
uservariable2 = key;
break;
}
}
}
if (keyexistidentity == 1) {
// 拼装参数传参+原有字符串
String ParameterValues = parameter.replaceAll("@" + uservariable, variable.get(uservariable).toString());
// 处理第二个传参
if (sumvariable == 2 || sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable1,
variable.get(uservariable1).toString());
}
// 处理第三个传参
if (sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable2,
variable.get(uservariable2).toString());
}
return ParameterValues;
} else {
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:" + uservariable + ",第" + "二个变量名称是:" + uservariable1
+ ",第三个变量名称是:" + uservariable2);
return "【Set parameter error】没有找到你要的变量哦再找下吧第一个变量名称是" + uservariable + ",第" + "二个变量名称是:" + uservariable1
+ ",第三个变量名称是:" + uservariable2;
}
}
public static WebElement isElementExist(WebDriver wd, String property, String property_value) {
public static WebElement isElementExist(WebDriver wd, String property, String propertyValue) {
try {
WebElement we = null;
// 处理WebElement对象定位
switch (property) {
case "id":
we = wd.findElement(By.id(property_value));
we = wd.findElement(By.id(propertyValue));
break;
case "name":
we = wd.findElement(By.name(property_value));
we = wd.findElement(By.name(propertyValue));
break;
case "xpath":
we = wd.findElement(By.xpath(property_value));
we = wd.findElement(By.xpath(propertyValue));
break;
case "linktext":
we = wd.findElement(By.linkText(property_value));
we = wd.findElement(By.linkText(propertyValue));
break;
case "tagname":
we = wd.findElement(By.tagName(property_value));
we = wd.findElement(By.tagName(propertyValue));
break;
case "cssselector":
we = wd.findElement(By.cssSelector(property_value));
we = wd.findElement(By.cssSelector(propertyValue));
break;
default:
break;

View File

@ -11,8 +11,8 @@ import luckyclient.planapi.entity.ProjectCasesteps;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: AnalyticCase
* @Description: 解析单个用例中描述部分的脚本
@ -27,7 +27,7 @@ public class WebDriverAnalyticCase {
* @param args
*/
@SuppressWarnings("finally")
public static Map<String,String> AnalyticCaseStep(ProjectCase projectcase,ProjectCasesteps step,String taskid,LogOperation caselog){
public static Map<String,String> analyticCaseStep(ProjectCase projectcase,ProjectCasesteps step,String taskid,LogOperation caselog){
String time = "0";
Map<String,String> params = new HashMap<String,String>();
@ -35,11 +35,11 @@ public class WebDriverAnalyticCase {
try {
if(null!=step.getPath()&&step.getPath().indexOf("=")>-1){
String property = step.getPath().substring(0, step.getPath().indexOf("="));
String property_value = step.getPath().substring(step.getPath().indexOf("=")+1, step.getPath().length());
String propertyValue = step.getPath().substring(step.getPath().indexOf("=")+1, step.getPath().length());
params.put("property", property.trim().toLowerCase()); //set属性
params.put("property_value", property_value.trim()); //set属性值
luckyclient.publicclass.LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+property_value.trim());
params.put("property_value", propertyValue.trim()); //set属性值
luckyclient.publicclass.LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+propertyValue.trim());
}
params.put("operation", step.getOperation().toLowerCase()); //set操作方法
if(null!=step.getParameters()&&!"".equals(step.getParameters())){
@ -52,15 +52,15 @@ public class WebDriverAnalyticCase {
if(null!=resultstr&&"".equals(resultstr)){
params.put("ExpectedResults", "");
}else if(null!=resultstr){
String ExpectedResults = SubComment(resultstr);
String expectedResults = subComment(resultstr);
//处理check字段
if(ExpectedResults.indexOf("check(")>-1){
params.put("checkproperty", ExpectedResults.substring(ExpectedResults.indexOf("check(")+6, ExpectedResults.indexOf("=")));
params.put("checkproperty_value", ExpectedResults.substring(ExpectedResults.indexOf("=")+1, ExpectedResults.lastIndexOf(")")));
if(expectedResults.indexOf("check(")>-1){
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("=")));
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
}
params.put("ExpectedResults", ExpectedResults);
luckyclient.publicclass.LogUtil.APP.info("预期结果解析ExpectedResults:"+ExpectedResults);
params.put("ExpectedResults", expectedResults);
luckyclient.publicclass.LogUtil.APP.info("预期结果解析ExpectedResults:"+expectedResults);
}
//set wait时间
@ -72,43 +72,43 @@ public class WebDriverAnalyticCase {
params.put("StepWait", time);
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+projectcase.getSign()+" 步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.CaseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepnum()),"");
caselog.caseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepnum()),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+projectcase.getSign()+" 步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.CaseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepnum()),"");
caselog.caseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepnum()),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
params.put("exception","用例编号:"+projectcase.getSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
}finally{
return params;
return params;
}
return params;
}
private static String SubComment(String htmlStr) throws InterruptedException{
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
String regEx_space = "\t|\r|\n";//定义空格回车换行符
private static String subComment(String htmlStr) throws InterruptedException{
String regExScript = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regExStyle = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regExHtml = "<[^>]+>"; // 定义HTML标签的正则表达式
String regExSpace = "\t|\r|\n";//定义空格回车换行符
String scriptstr = null;
if (htmlStr!=null) {
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
Matcher mScript = pScript.matcher(htmlStr);
htmlStr = mScript.replaceAll(""); // 过滤script标签
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); // 过滤style标签
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
Matcher mStyle = pStyle.matcher(htmlStr);
htmlStr = mStyle.replaceAll(""); // 过滤style标签
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
Matcher mHtml = pHtml.matcher(htmlStr);
htmlStr = mHtml.replaceAll(""); // 过滤html标签
Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
Matcher mSpace = pSpace.matcher(htmlStr);
htmlStr = mSpace.replaceAll(""); // 过滤空格回车标签
}
if(htmlStr.indexOf("/*")>-1&&htmlStr.indexOf("*/")>-1){

View File

@ -12,14 +12,26 @@ import luckyclient.dblog.LogOperation;
import luckyclient.planapi.api.GetServerAPI;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebOneCaseExecute{
@SuppressWarnings("static-access")
public static void OneCaseExecuteForTast(String projectname,String testCaseExternalId,int version,String taskid){
public static void oneCaseExecuteForTast(String projectname,String testCaseExternalId,int version,String taskid){
DbLink.exetype = 0; //记录日志到数据库
TestControl.TASKID = taskid;
int drivertype = LogOperation.Querydrivertype(taskid);
int drivertype = LogOperation.querydrivertype(taskid);
WebDriver wd = null;
try {
wd = WebDriverInitialization.setWebDriverForTask(taskid,drivertype);
@ -28,13 +40,14 @@ public class WebOneCaseExecute{
e1.printStackTrace();
}
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
caselog.DeleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
caselog.DeleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
LogOperation.deleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List<PublicCaseParams> pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectid()));
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
try {
List<ProjectCasesteps> steps=GetServerAPI.getStepsbycaseid(testcase.getId());
WebCaseExecution.CaseExcution(testcase, steps, taskid,wd,caselog);
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【"+testcase.getSign()+"】执行完成......进入下一条");
} catch (InterruptedException e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);

View File

@ -13,13 +13,24 @@ import luckyclient.dblog.LogOperation;
import luckyclient.testlinkapi.TestBuildApi;
import luckyclient.testlinkapi.TestCaseApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebBatchExecuteTestLink{
@SuppressWarnings("static-access")
public static void BatchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws IOException{
public static void batchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws IOException{
DbLink.exetype = 0; //记录日志到数据库
TestControl.TASKID = taskid;
int drivertype = LogOperation.Querydrivertype(taskid);
int drivertype = LogOperation.querydrivertype(taskid);
WebDriver wd = null;
try {
wd = WebDriverInitialization.setWebDriverForTask(taskid,drivertype);
@ -28,18 +39,18 @@ public class WebBatchExecuteTestLink{
e1.printStackTrace();
}
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
TestBuildApi.GetBuild(projectname);
TestBuildApi.getBuild(projectname);
if(batchcase.indexOf("ALLFAIL")>-1){ //执行全部非成功状态用例
String casemore = caselog.UnSucCaseUpdate(taskid);
String temp[]=casemore.split("\\#",-1);
String casemore = caselog.unSucCaseUpdate(taskid);
String[] temp=casemore.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()-1));
TestCase testcase = TestCaseApi.getTestCaseByExternalId(testCaseExternalId, version);
caselog.DeleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
caselog.DeleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
LogOperation.deleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
try {
WebCaseExecutionTestLink.CaseExcution(projectname,testcase, taskid,wd,caselog);
WebCaseExecutionTestLink.caseExcution(projectname,testcase, taskid,wd,caselog);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);
@ -47,13 +58,13 @@ public class WebBatchExecuteTestLink{
}
}
}else{ //批量执行用例
String temp[]=batchcase.split("\\#",-1);
String[] temp=batchcase.split("\\#",-1);
for(int i=0;i<temp.length;i++){
String testCaseExternalId = temp[i].substring(0, temp[i].indexOf("%"));
int version = Integer.parseInt(temp[i].substring(temp[i].indexOf("%")+1,temp[i].length()));
TestCase testcase = TestCaseApi.getTestCaseByExternalId(testCaseExternalId, version);
try {
WebCaseExecutionTestLink.CaseExcution(projectname,testcase, taskid,wd,caselog);
WebCaseExecutionTestLink.caseExcution(projectname,testcase, taskid,wd,caselog);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);

View File

@ -18,19 +18,30 @@ import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.DBOperation;
import luckyclient.testlinkapi.WebDriverAnalyticTestLinkCase;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
static Map<String, String> variable = new HashMap<String, String>();
public static void CaseExcution(String projectname, TestCase testcase, String taskid, WebDriver wd,LogOperation caselog)
public static void caseExcution(String projectname, TestCase testcase, String taskid, WebDriver wd,LogOperation caselog)
throws InterruptedException {
int setresult = 0; // 0:成功 1:失败 2:锁定 其他锁定
String casenote = "备注初始化";
String imagname = "";
caselog.AddCaseDetail(taskid, testcase.getFullExternalId(), testcase.getVersion().toString(), testcase.getName(), 4); //插入开始执行的用例
caselog.addCaseDetail(taskid, testcase.getFullExternalId(), testcase.getVersion().toString(), testcase.getName(), 4); //插入开始执行的用例
for (TestCaseStep step : testcase.getSteps()) {
Map<String, String> params = WebDriverAnalyticTestLinkCase.AnalyticCaseStep(testcase, step.getNumber(), taskid,caselog);
Map<String, String> params = WebDriverAnalyticTestLinkCase.analyticCaseStep(testcase, step.getNumber(), taskid,caselog);
if(params.get("exception")!=null&&params.get("exception").toString().indexOf("解析异常")>-1){
setresult = 2;
@ -48,25 +59,25 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
Thread.sleep(waitsec * 1000);
}
if (!expectedResults.equals("")) { // 有预期结果
if (!"".equals(expectedResults)) { // 有预期结果
// 判断传参
luckyclient.publicclass.LogUtil.APP.info("expectedResults=【"+expectedResults+"");
if (expectedResults.length() > 2 && expectedResults.substring(0, 2).indexOf("$=") > -1) {
String ExpectedResultVariable = expectedResults.substring(2);
variable.put(ExpectedResultVariable, result);
String expectedResultVariable = expectedResults.substring(2);
variable.put(expectedResultVariable, result);
continue;
}
// 判断预期结果-检查模式
if (params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
String checkproperty = params.get("checkproperty").toString();
String checkproperty_value = params.get("checkproperty_value").toString();
String checkPropertyValue = params.get("checkproperty_value").toString();
WebElement we = isElementExist(wd, checkproperty, checkproperty_value);
WebElement we = isElementExist(wd, checkproperty, checkPropertyValue);
if (we != null) {
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getFullExternalId() + "" + step.getNumber()
+ "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!",
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!",
"info", String.valueOf(step.getNumber()),"");
continue;
} else {
@ -74,11 +85,11 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getFullExternalId() + "" + step.getNumber()
+ "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!"
+ "checkproperty【"+checkproperty+"】 checkproperty_value【"+checkproperty_value+"","error", String.valueOf(step.getNumber()),imagname);
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!"
+ "checkproperty【"+checkproperty+"】 checkproperty_value【"+checkPropertyValue+"","error", String.valueOf(step.getNumber()),imagname);
break;
}
@ -88,7 +99,7 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
if(result.indexOf(expectedResults.substring(2))>-1){
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getFullExternalId() + "" + step.getNumber()
+ "步,模糊匹配预期结果成功!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "步骤模糊匹配预期结果成功!",
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "步骤模糊匹配预期结果成功!",
"info", String.valueOf(step.getNumber()),"");
continue;
}else{
@ -96,17 +107,17 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getFullExternalId() + "" + step.getNumber()
+ "步,模糊匹配预期结果失败!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "步骤模糊匹配预期结果失败!执行结果:"+result,
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "步骤模糊匹配预期结果失败!执行结果:"+result,
"error", String.valueOf(step.getNumber()),imagname);
break;
}
}else if(expectedResults.equals(result)) { // 直接匹配预期结果模式
luckyclient.publicclass.LogUtil.APP.info("用例:" + testcase.getFullExternalId() + "" + step.getNumber()
+ "步,直接匹配预期结果成功!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "步骤直接匹配预期结果成功!",
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "步骤直接匹配预期结果成功!",
"info", String.valueOf(step.getNumber()),"");
continue;
} else {
@ -114,10 +125,10 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
setresult = 1;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getFullExternalId() + "" + step.getNumber()
+ "步,直接匹配预期结果失败!执行结果:"+result);
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "步骤直接匹配预期结果失败!执行结果:"+result,
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "步骤直接匹配预期结果失败!执行结果:"+result,
"error", String.valueOf(step.getNumber()),imagname);
break;
}
@ -129,9 +140,9 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
setresult = 2;
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
imagname = timeformat.format(new Date());
BaseWebDrive.WebScreenShot(wd,imagname);
BaseWebDrive.webScreenShot(wd,imagname);
luckyclient.publicclass.LogUtil.APP.error("用例:" + testcase.getFullExternalId() + "" + step.getNumber() + "步,"+result);
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!"+result,
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!"+result,
"error", String.valueOf(step.getNumber()),imagname);
break;
}
@ -139,13 +150,13 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
}
variable.clear();
caselog.UpdateCaseDetail(taskid, testcase.getFullExternalId(), setresult);
caselog.updateCaseDetail(taskid, testcase.getFullExternalId(), setresult);
if(setresult==0){
luckyclient.publicclass.LogUtil.APP.info("用例【"+testcase.getFullExternalId()+"】全部步骤执行结果成功...");
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "用例全部步骤执行结果成功","info", "ending","");
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "用例全部步骤执行结果成功","info", "ending","");
}else{
luckyclient.publicclass.LogUtil.APP.error("用例【"+testcase.getFullExternalId()+"】步骤执行过程中失败或是锁定...请查看具体原因!"+casenote);
caselog.CaseLogDetail(taskid, testcase.getFullExternalId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
caselog.caseLogDetail(taskid, testcase.getFullExternalId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
}
//LogOperation.UpdateTastdetail(taskid, 0);
}
@ -153,53 +164,53 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
private static String runStep(Map<String, String> params, WebDriver wd,String taskid,String casenum,int stepno,LogOperation caselog) {
String result = "";
String property;
String property_value;
String propertyValue;
String operation;
String operation_value;
String operationValue;
try {
property = params.get("property");
property_value = params.get("property_value");
propertyValue = params.get("property_value");
operation = params.get("operation");
operation_value = params.get("operation_value");
operationValue = params.get("operation_value");
// 用例名称解析出现异常或是单个步骤参数解析异常
if (property_value != null && property.indexOf("解析异常") > -1) {
if (propertyValue != null && property.indexOf("解析异常") > -1) {
luckyclient.publicclass.LogUtil.APP.error("当前步骤解析出现异常或是对象为空!---"+property);
return "用例解析出错啦!";
}
// 处理值传递
if (property_value != null && property_value.indexOf("@") > -1 && property_value.indexOf("[@") < 0
&& property_value.indexOf("@@") < 0) {
property_value = SettingParameter(property_value);
if (propertyValue != null && propertyValue.indexOf("@") > -1 && propertyValue.indexOf("[@") < 0
&& propertyValue.indexOf("@@") < 0) {
propertyValue = settingParameter(propertyValue);
// 判断传参是否存在问题
if (property_value.indexOf("Set parameter error") > -1) {
caselog.CaseLogDetail(taskid, casenum, "当前步骤解析出现异常或是对象为空!---"+property,
if (propertyValue.indexOf("Set parameter error") > -1) {
caselog.caseLogDetail(taskid, casenum, "当前步骤解析出现异常或是对象为空!---"+property,
"error", String.valueOf(stepno),"");
return "处理传参过程出错:" + property_value;
return "处理传参过程出错:" + propertyValue;
}
}else if(property_value != null && (property_value.indexOf("&quot;")>-1
|| property_value.indexOf("&#39;")>-1 || property_value.indexOf("@@")>-1)){
property_value = property_value.replaceAll("&quot;", "\"");
property_value = property_value.replaceAll("&#39;", "\'");
property_value = property_value.replaceAll("@@", "@");
}else if(propertyValue != null && (propertyValue.indexOf("&quot;")>-1
|| propertyValue.indexOf("&#39;")>-1 || propertyValue.indexOf("@@")>-1)){
propertyValue = propertyValue.replaceAll("&quot;", "\"");
propertyValue = propertyValue.replaceAll("&#39;", "\'");
propertyValue = propertyValue.replaceAll("@@", "@");
}
if (operation_value != null && operation_value.indexOf("@") > -1 && operation_value.indexOf("@@") < 0) {
operation_value = SettingParameter(operation_value);
if (operation_value.indexOf("Set parameter error") > -1) {
return "处理传参过程出错:" + property_value;
if (operationValue != null && operationValue.indexOf("@") > -1 && operationValue.indexOf("@@") < 0) {
operationValue = settingParameter(operationValue);
if (operationValue.indexOf("Set parameter error") > -1) {
return "处理传参过程出错:" + propertyValue;
}
}else if(operation_value != null && (operation_value.indexOf("&quot;")>-1
|| operation_value.indexOf("&#39;")>-1 || operation_value.indexOf("@@")>-1)){
operation_value = operation_value.replaceAll("&quot;", "\"");
operation_value = operation_value.replaceAll("&#39;", "\'");
operation_value = operation_value.replaceAll("@@", "@");
}else if(operationValue != null && (operationValue.indexOf("&quot;")>-1
|| operationValue.indexOf("&#39;")>-1 || operationValue.indexOf("@@")>-1)){
operationValue = operationValue.replaceAll("&quot;", "\"");
operationValue = operationValue.replaceAll("&#39;", "\'");
operationValue = operationValue.replaceAll("@@", "@");
}
luckyclient.publicclass.LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
caselog.CaseLogDetail(taskid, casenum, "对象操作:"+operation+"; 操作值:"+operation_value,"info", String.valueOf(stepno),"");
caselog.caseLogDetail(taskid, casenum, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
} catch (Exception e) {
e.printStackTrace();
@ -209,9 +220,9 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
try {
//调用接口用例
if(operation!=null&&operation_value!=null&&"runcase".equals(operation)){
String temp[]=operation_value.split(",",-1);
String ex = TestLinkCaseExecution.OneCaseExecuteForWebDriver(temp[0], Integer.valueOf(temp[1]),taskid,caselog);
if(operation!=null&&operationValue!=null&&"runcase".equals(operation)){
String[] temp=operationValue.split(",",-1);
String ex = TestLinkCaseExecution.oneCaseExecuteForWebDriver(temp[0], Integer.valueOf(temp[1]),taskid,caselog);
if(ex.indexOf("CallCase调用出错")<=-1&&ex.indexOf("解析出错啦!")<=-1&&ex.indexOf("匹配失败")<=-1){
return ex;
}else{
@ -221,8 +232,8 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
WebElement we = null;
if (property != null && property_value != null) { // 页面元素层
we = isElementExist(wd, property, property_value);
if (property != null && propertyValue != null) { // 页面元素层
we = isElementExist(wd, property, propertyValue);
// 判断此元素是否存在
if (we == null) {
luckyclient.publicclass.LogUtil.APP.error("定位对象失败isElementExist为null!");
@ -230,22 +241,22 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
}
if (operation.indexOf("select") > -1) {
result = EncapsulateOperation.SelectOperation(we, operation, operation_value);
result = EncapsulateOperation.selectOperation(we, operation, operationValue);
} else if (operation.indexOf("get") > -1){
result = EncapsulateOperation.GetOperation(wd, we, operation);
result = EncapsulateOperation.getOperation(wd, we, operation);
} else if (operation.indexOf("mouse") > -1){
result = EncapsulateOperation.ActionWeOperation(wd, we, operation, operation_value, property, property_value);
result = EncapsulateOperation.actionWeOperation(wd, we, operation, operationValue, property, propertyValue);
} else {
result = EncapsulateOperation.ObjectOperation(wd, we, operation, operation_value, property, property_value);
result = EncapsulateOperation.objectOperation(wd, we, operation, operationValue, property, propertyValue);
}
} else if (property == null && operation != null) { // Driver层操作
// 处理弹出框事件
if (operation.indexOf("alert") > -1){
result = EncapsulateOperation.AlertOperation(wd, operation);
result = EncapsulateOperation.alertOperation(wd, operation);
}else if(operation.indexOf("mouse") > -1){
result = EncapsulateOperation.ActionOperation(wd, operation, operation_value);
result = EncapsulateOperation.actionOperation(wd, operation, operationValue);
}else{
result = EncapsulateOperation.DriverOperation(wd, operation, operation_value);
result = EncapsulateOperation.driverOperation(wd, operation, operationValue);
}
}else{
luckyclient.publicclass.LogUtil.APP.error("元素操作过程失败!");
@ -255,7 +266,7 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
luckyclient.publicclass.LogUtil.APP.error("元素定位过程或是操作过程失败或异常!"+e.getMessage());
return "元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
caselog.CaseLogDetail(taskid, casenum, result,"info", String.valueOf(stepno),"");
caselog.caseLogDetail(taskid, casenum, result,"info", String.valueOf(stepno),"");
if(result.indexOf("获取到的值是【")>-1&&result.indexOf("")>-1){
result = result.substring(7, result.length()-1);
@ -264,7 +275,7 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
}
private static String SettingParameter(String parameter) {
private static String settingParameter(String parameter) {
int keyexistidentity = 0;
if (parameter.indexOf("&quot;") > -1 || parameter.indexOf("&#39;") > -1) { // 页面转义字符转换
parameter = parameter.replaceAll("&quot;", "\"");
@ -333,19 +344,19 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
}
if (keyexistidentity == 1) {
// 拼装参数传参+原有字符串
String ParameterValues = parameter.replaceAll("@" + uservariable, variable.get(uservariable).toString());
String parameterValues = parameter.replaceAll("@" + uservariable, variable.get(uservariable).toString());
// 处理第二个传参
if (sumvariable == 2 || sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable1,
parameterValues = parameterValues.replaceAll("@" + uservariable1,
variable.get(uservariable1).toString());
}
// 处理第三个传参
if (sumvariable == 3) {
ParameterValues = ParameterValues.replaceAll("@" + uservariable2,
parameterValues = parameterValues.replaceAll("@" + uservariable2,
variable.get(uservariable2).toString());
}
return ParameterValues;
return parameterValues;
} else {
luckyclient.publicclass.LogUtil.APP.error("没有找到你要的变量哦,再找下吧!第一个变量名称是:" + uservariable + ",第" + "二个变量名称是:" + uservariable1
+ ",第三个变量名称是:" + uservariable2);
@ -354,29 +365,29 @@ public class WebCaseExecutionTestLink extends TestLinkCaseExecution{
}
}
public static WebElement isElementExist(WebDriver wd, String property, String property_value) {
public static WebElement isElementExist(WebDriver wd, String property, String propertyValue) {
try {
WebElement we = null;
// 处理WebElement对象定位
switch (property) {
case "id":
we = wd.findElement(By.id(property_value));
we = wd.findElement(By.id(propertyValue));
break;
case "name":
we = wd.findElement(By.name(property_value));
we = wd.findElement(By.name(propertyValue));
break;
case "xpath":
we = wd.findElement(By.xpath(property_value));
we = wd.findElement(By.xpath(propertyValue));
break;
case "linktext":
we = wd.findElement(By.linkText(property_value));
we = wd.findElement(By.linkText(propertyValue));
break;
case "tagname":
we = wd.findElement(By.tagName(property_value));
we = wd.findElement(By.tagName(propertyValue));
break;
case "cssselector":
we = wd.findElement(By.cssSelector(property_value));
we = wd.findElement(By.cssSelector(propertyValue));
break;
default:
break;

View File

@ -12,13 +12,24 @@ import luckyclient.dblog.LogOperation;
import luckyclient.testlinkapi.TestBuildApi;
import luckyclient.testlinkapi.TestCaseApi;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class WebOneCaseExecuteTestLink{
@SuppressWarnings("static-access")
public static void OneCaseExecuteForTast(String projectname,String testCaseExternalId,int version,String taskid){
public static void oneCaseExecuteForTast(String projectname,String testCaseExternalId,int version,String taskid){
DbLink.exetype = 0; //记录日志到数据库
TestControl.TASKID = taskid;
int drivertype = LogOperation.Querydrivertype(taskid);
int drivertype = LogOperation.querydrivertype(taskid);
WebDriver wd = null;
try {
wd = WebDriverInitialization.setWebDriverForTask(taskid,drivertype);
@ -27,13 +38,13 @@ public class WebOneCaseExecuteTestLink{
e1.printStackTrace();
}
LogOperation caselog = new LogOperation(); // 初始化写用例结果以及日志模块
caselog.DeleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
caselog.DeleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
TestBuildApi.GetBuild(projectname);
LogOperation.deleteCaseDetail(testCaseExternalId, taskid); //删除旧的用例
LogOperation.deleteCaseLogDetail(testCaseExternalId, taskid); //删除旧的日志
TestBuildApi.getBuild(projectname);
TestCase testcase = TestCaseApi.getTestCaseByExternalId(testCaseExternalId, version);
luckyclient.publicclass.LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
try {
WebCaseExecutionTestLink.CaseExcution(projectname,testcase, taskid,wd,caselog);
WebCaseExecutionTestLink.caseExcution(projectname,testcase, taskid,wd,caselog);
luckyclient.publicclass.LogUtil.APP.info("当前用例:【"+testcase.getFullExternalId()+"】执行完成......进入下一条");
} catch (InterruptedException e) {
luckyclient.publicclass.LogUtil.APP.error("用户执行过程中抛出异常!", e);

View File

@ -18,6 +18,17 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.Augmenter;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class Ocr {
private static String readtextpath = System.getProperty("user.dir")+"\\CAPTCHA.txt"; //默认读取工程根目录下的文件
private static String screenshotpath = System.getProperty("user.dir")+"\\CAPTCHA.png"; //默认把截图放在工程根目录

View File

@ -4,6 +4,17 @@ import java.util.Properties;
import luckyclient.publicclass.DBOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class DbLink {
/**
@ -18,13 +29,13 @@ public class DbLink {
* @date 2015年4月20日 上午9:29:40
*
*/
public static DBOperation DbLogLink(){
public static DBOperation dbLogLink(){
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
String url_base = "jdbc:mysql://"+properties.getProperty("mysql.db.ip")+":"+properties.getProperty("mysql.db.port")
String urlBase = "jdbc:mysql://"+properties.getProperty("mysql.db.ip")+":"+properties.getProperty("mysql.db.port")
+"/"+properties.getProperty("mysql.db.dbname")+"?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false";
String username_base = properties.getProperty("mysql.db.username");
String password_base = properties.getProperty("mysql.db.userpwd");
return new DBOperation(url_base, username_base, password_base);
String userNameBase = properties.getProperty("mysql.db.username");
String passwordBase = properties.getProperty("mysql.db.userpwd");
return new DBOperation(urlBase, userNameBase, passwordBase);
}
public static int exetype; //任务执行类型 0 任务调度模式 1 控制台模式

View File

@ -8,8 +8,8 @@ import luckyclient.publicclass.DBOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: LogOperation
* @Description: 日志写入数据库
@ -18,14 +18,14 @@ import luckyclient.publicclass.DBOperation;
*
*/
public class LogOperation {
public static DBOperation dbt = DbLink.DbLogLink();
public static DBOperation dbt = DbLink.dbLogLink();
static int exetype = DbLink.exetype;
/*
* 插入用例执行状态
* casestatus pass:0 fail:1 lock:2 unexecute:4
*/
public void AddCaseDetail(String taskid,String caseno,String caseversion,String casename,Integer casestatus){
public void addCaseDetail(String taskid,String caseno,String caseversion,String casename,Integer casestatus){
if(0 == exetype){
int taskidtoint = Integer.parseInt(taskid);
casename = casename.replace("'", "''");
@ -46,7 +46,7 @@ public class LogOperation {
* 更新用例执行状态
* casestatus pass:0 fail:1 lock:2 unexecute:4
*/
public void UpdateCaseDetail(String taskid,String caseno,Integer casestatus){
public void updateCaseDetail(String taskid,String caseno,Integer casestatus){
if(0 == exetype){
int taskidtoint = Integer.parseInt(taskid);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式
@ -63,7 +63,7 @@ public class LogOperation {
/*
* 插入用例执行日志
*/
public void CaseLogDetail(String taskid,String caseno,String detail,String loggrade,String step,String imgname) {
public void caseLogDetail(String taskid,String caseno,String detail,String loggrade,String step,String imgname) {
if(0 == exetype){
if(detail.indexOf("'")>-1){
detail = detail.replaceAll("'", "''");
@ -102,7 +102,7 @@ public class LogOperation {
/*
*更新本次任务的执行统计情况
*/
public static int[] UpdateTastdetail(String taskid,int casecount){
public static int[] updateTastdetail(String taskid,int casecount){
int[] taskcount = null;
if(0 == exetype){
try {
@ -146,7 +146,7 @@ public class LogOperation {
/*
*更新本次任务的执行状态
*/
public static void UpdateTastStatus(String taskid,int casecount){
public static void updateTastStatus(String taskid,int casecount){
if(0 == exetype){
try {
int id = Integer.parseInt(taskid);
@ -163,7 +163,7 @@ public class LogOperation {
/*
*更新本次任务的单条用例执行日志
*/
public static void UpdateCaseLogDetail(String caseno,String taskid,String detail,String loggrade,String step) {
public static void updateCaseLogDetail(String caseno,String taskid,String detail,String loggrade,String step) {
try {
if(detail.indexOf("'")>-1){
detail = detail.replaceAll("'", "''");
@ -192,7 +192,7 @@ public class LogOperation {
/*
* 删除单次任务指定的用例日志明细
*/
public static void DeleteCaseLogDetail(String caseno,String taskid){
public static void deleteCaseLogDetail(String caseno,String taskid){
int inttaskid = Integer.parseInt(taskid);
String casesidsql;
try {
@ -208,7 +208,7 @@ public class LogOperation {
/*
* 删除单次任务指定的用例明细
*/
public static void DeleteCaseDetail(String caseno, String taskid) {
public static void deleteCaseDetail(String caseno, String taskid) {
int inttaskid = Integer.parseInt(taskid);
try {
dbt.executeSql("delete from TEST_CASEDETAIL where caseno = '" + caseno + "' and taskid = " + inttaskid); // 删除原来的用例
@ -221,7 +221,7 @@ public class LogOperation {
/*
* 取出指定任务ID中的不属于成功状态的用例编写以及版本号
*/
public String UnSucCaseUpdate(String taskid){
public String unSucCaseUpdate(String taskid){
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
try {
@ -239,14 +239,14 @@ public class LogOperation {
eMailer varchar(100) ; --收件人
*/
@SuppressWarnings("finally")
public static String[] GetEmailAddress(String taskid){
public static String[] getEmailAddress(String taskid){
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
String address[] = null;
String[] address = null;
try {
casesidsql = dbt.executeQuery("select t.issendmail,t.emailer from TEST_JOBS t where id in (select jobid from TEST_TASKEXCUTE t where t.id = "+inttaskid+")");
String status = casesidsql.substring(0, casesidsql.indexOf("%"));
if(status.equals("1")){
if("1".equals(status)){
String temp = casesidsql.substring(casesidsql.indexOf("%")+1,casesidsql.length()-1);
if(temp.indexOf(";")>-1&&temp.substring(temp.length()-1, temp.length()).indexOf(";")>-1){ //清除最后一个;
temp = temp.substring(0, temp.length()-1);
@ -261,9 +261,9 @@ public class LogOperation {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
return address;
}
return address;
}
/*
@ -272,14 +272,14 @@ public class LogOperation {
BuildName varchar(100) ; --构建项目名称
*/
@SuppressWarnings("finally")
public static String[] GetBuildName(String taskid){
public static String[] getBuildName(String taskid){
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
String buildname[] = null;
String[] buildname = null;
try {
casesidsql = dbt.executeQuery("select t.isbuilding,t.buildname from TEST_JOBS t where id in (select jobid from TEST_TASKEXCUTE t where t.id = "+inttaskid+")");
String status = casesidsql.substring(0, casesidsql.indexOf("%"));
if(status.equals("1")){
if("1".equals(status)){
String temp = casesidsql.substring(casesidsql.indexOf("%")+1,casesidsql.length()-1);
if(temp.indexOf(";")>-1&&temp.substring(temp.length()-1, temp.length()).indexOf(";")>-1){ //清除最后一个;
temp = temp.substring(0, temp.length()-1);
@ -294,9 +294,9 @@ public class LogOperation {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
return buildname;
}
return buildname;
}
/*
@ -307,14 +307,14 @@ public class LogOperation {
10.211.19.72;pospsettle;pospsettle;22;cd /home/pospsettle/tomcat-7.0-7080/bin&&./restart.sh;
*/
@SuppressWarnings("finally")
public static String[] Getrestartcomm(String taskid){
public static String[] getrestartcomm(String taskid){
int inttaskid = Integer.parseInt(taskid);
String casesidsql = null;
String command[] = null;
String[] command = null;
try {
casesidsql = dbt.executeQuery("select t.isrestart,t.restartcomm from TEST_JOBS t where id in (select jobid from TEST_TASKEXCUTE t where t.id = "+inttaskid+")");
String status = casesidsql.substring(0, casesidsql.indexOf("%"));
if(status.equals("1")){
if("1".equals(status)){
String temp = casesidsql.substring(casesidsql.indexOf("%")+1,casesidsql.length()-1);
if(temp.indexOf(";")>-1&&temp.substring(temp.length()-1, temp.length()).indexOf(";")>-1){ //清除最后一个;
temp = temp.substring(0, temp.length()-1);
@ -329,9 +329,10 @@ public class LogOperation {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
return command;
}
return command;
}
@ -339,7 +340,7 @@ public class LogOperation {
* 获取测试计划名称
*/
@SuppressWarnings("finally")
public static String GetTestPlanName(String taskid) {
public static String getTestPlanName(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String testplanname = "NULL";
try {
@ -350,18 +351,18 @@ public class LogOperation {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
return testplanname;
}
return testplanname;
}
/*
* 获取任务测试时长
*/
@SuppressWarnings("finally")
public static String GetTestTime(String taskid) {
public static String getTestTime(String taskid) {
int inttaskid = Integer.parseInt(taskid);
String Destime = "计算测试时长出错!";
String desTime = "计算测试时长出错!";
try {
String sql = dbt.executeQuery("select date_format(t.createtime,'%Y-%m-%d %T'),date_format(t.finishtime,'%Y-%m-%d %T') from TEST_TASKEXCUTE t where t.id= "+inttaskid);
String starttime = sql.substring(0, sql.indexOf("%"));
@ -374,19 +375,19 @@ public class LogOperation {
long hour=(l/(60*60*1000)-day*24);
long min=((l/(60*1000))-day*24*60-hour*60);
long s=(l/1000-day*24*60*60-hour*60*60-min*60);
Destime = "<font color='#2828FF'>"+hour+"</font>小时<font color='#2828FF'>"+min+"</font>分<font color='#2828FF'>"+s+"</font>秒";
desTime = "<font color='#2828FF'>"+hour+"</font>小时<font color='#2828FF'>"+min+"</font>分<font color='#2828FF'>"+s+"</font>秒";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
return Destime;
return desTime;
}
return desTime;
}
/*
* 查询web执行浏览器类型
*/
public static int Querydrivertype(String taskid) {
public static int querydrivertype(String taskid) {
int taskidtoint = Integer.parseInt(taskid);
int drivertype=0;
try {
@ -403,7 +404,7 @@ public class LogOperation {
/*
* 查询任务中用例步骤日志执行实际结果
*/
public static String getlogdetail_testresult(int taskid,String caseno,int casestatus) {
public static String getLogDetailTestResult(int taskid,String caseno,int casestatus) {
String sqlresult="";
try {
sqlresult = dbt.executeQuery("select detail from test_logdetail where logid=(select MIN(logid) from test_logdetail "
@ -424,7 +425,7 @@ public class LogOperation {
/*
* 根据任务名称查询任务ID
*/
public static int gettaskexcute_taskid(String taskname) {
public static int getTaskExcuteTaskid(String taskname) {
String sqlresult="";
try {
sqlresult = dbt.executeQuery("select id from test_taskexcute t where t.taskid='"+taskname+"'");
@ -441,7 +442,7 @@ public class LogOperation {
* 查询任务中用例步骤日志预期结果
* 2017-09-16
*/
public static String getlogdetail_expectresult(int taskid,String caseno,int casestatus) {
public static String getLogDetailExpectResult(int taskid,String caseno,int casestatus) {
String sqlresult="";
try {
sqlresult = dbt.executeQuery("select detail from test_logdetail where logid=(select MIN(logid) from test_logdetail "

View File

@ -2,15 +2,26 @@ package luckyclient.jenkinsapi;
import luckyclient.dblog.LogOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class BuildingInitialization {
public static String BooleanBuildingOver(String[] buildname) throws InterruptedException{
public static String booleanBuildingOver(String[] buildname) throws InterruptedException{
String buildresult = "Status:true"+" 项目全部构建成功!";
int k;
for(int i=0;i<300;i++){
k=0;
for(int j=0;j<buildname.length;j++){
String result = JenkinsBuilding.BuildingResult(buildname[i]);
String result = JenkinsBuilding.buildingResult(buildname[i]);
if(result.indexOf("alt=\"Failed\"")>-1){
buildresult = "项目"+buildname[i]+"构建失败,自动化测试退出!";
luckyclient.publicclass.LogUtil.APP.error("项目"+buildname[i]+"构建失败,自动化测试退出!");
@ -32,10 +43,10 @@ public class BuildingInitialization {
}
@SuppressWarnings("finally")
public static String BuildingRun(String tastid) throws InterruptedException{
public static String buildingRun(String tastid) throws InterruptedException{
String result = "Status:true"+" 当前任务没有找到需要构建的项目!";
try{
String[] buildname = LogOperation.GetBuildName(tastid);
String[] buildname = LogOperation.getBuildName(tastid);
if(buildname!=null){
luckyclient.publicclass.LogUtil.APP.info("准备将配置的测试项目进行构建!请稍等。。。。");
@ -43,7 +54,7 @@ public class BuildingInitialization {
JenkinsBuilding.sendBuilding(buildname[i], 0);
}
Thread.sleep(10000); //等待构建检查
result = BooleanBuildingOver(buildname);
result = booleanBuildingOver(buildname);
}else{
luckyclient.publicclass.LogUtil.APP.info("当前任务没有找到需要构建的项目!");
}
@ -51,9 +62,9 @@ public class BuildingInitialization {
luckyclient.publicclass.LogUtil.APP.error("项目构建过程中出现异常");
luckyclient.publicclass.LogUtil.APP.error(e);
result = "项目构建过程中出现异常";
}finally{
return result;
}
return result;
}

View File

@ -7,6 +7,17 @@ import java.net.URLConnection;
import java.util.List;
import java.util.Map;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class JenkinsBuilding {
/**
* 向指定URL发送GET方法的请求
@ -75,7 +86,7 @@ public class JenkinsBuilding {
*
* alt="Success" alt="In progress" alt="Failed"
*/
public static String BuildingResult(String buildname) {
public static String buildingResult(String buildname) {
String result = "";
BufferedReader in = null;
try {
@ -124,11 +135,7 @@ public class JenkinsBuilding {
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//发送 GET 请求
//http://10.211.19.19:18080/jenkins/job/72_deploy_settle_check_server/lastBuild/
String s=JenkinsBuilding.BuildingResult("deploy-abc-b2cApi");
System.out.println(s);
}
}

View File

@ -2,13 +2,24 @@ package luckyclient.jenkinsapi;
import luckyclient.dblog.LogOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class RestartServerInitialization {
@SuppressWarnings("finally")
public static String RestartServerRun(String tastid){
public static String restartServerRun(String tastid){
String result = "Status:true"+" 重启命令执行成功!";
try{
String[] command = LogOperation.Getrestartcomm(tastid);
String[] command = LogOperation.getrestartcomm(tastid);
if(command!=null){
luckyclient.publicclass.LogUtil.APP.info("准备重启指定的TOMCAT请稍等。。。参数个数"+command.length);
if(command.length==5){
@ -27,15 +38,14 @@ public class RestartServerInitialization {
luckyclient.publicclass.LogUtil.APP.error("重启TOMCAT过程中出现异常");
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(),e);
result = "重启TOMCAT过程中出现异常";
}finally{
return result;
}
return result;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
RestartServerRun("1460");
}
}

View File

@ -102,11 +102,12 @@ public class RmtShellExecutor {
} catch (Exception e) {
result = "重启TOMCAT过程中出现异常";
e.printStackTrace();
return result;
} finally {
session.disconnect();
channel.disconnect();
return result;
}
return result;
}
public static void main(String args[]) throws Exception {

View File

@ -3,10 +3,21 @@ package luckyclient.mail;
import java.util.HashMap;
import java.util.Map;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class HtmlMail {
static FreemarkerEmailTemplate fet=new FreemarkerEmailTemplate();
public static String HtmlContentFormat(int[] taskcount,String taskid,String buildstatus,String restartstatus,String time,String jobname){
public static String htmlContentFormat(int[] taskcount,String taskid,String buildstatus,String restartstatus,String time,String jobname){
Map<Object, Object> parameters = new HashMap<Object, Object>();
parameters.put("buildstatus", buildstatus);
parameters.put("restartstatus", restartstatus);
@ -17,7 +28,7 @@ public class HtmlMail {
return fet.getText("task-body", parameters);
}
public static String HtmlSubjectFormat(String jobname){
public static String htmlSubjectFormat(String jobname){
Map<Object, Object> parameters = new HashMap<Object, Object>();
parameters.put("jobname", jobname);
return fet.getText("task-title", parameters);

View File

@ -4,10 +4,21 @@ import java.util.Properties;
import luckyclient.dblog.LogOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class MailSendInitialization {
public static void SendMailInitialization(String subject,String content,String taskid){
String[] addresses = LogOperation.GetEmailAddress(taskid);
public static void sendMailInitialization(String subject,String content,String taskid){
String[] addresses = LogOperation.getEmailAddress(taskid);
Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
if(addresses!=null){
luckyclient.publicclass.LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等。。。。");
@ -37,9 +48,6 @@ public class MailSendInitialization {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] taskcount = {79,78,1,0,0};
String test = HtmlMail.HtmlContentFormat(taskcount, "220", "Status:true 当前任务没有找到需要构建的项目!", "Status:true 当前任务没有找到需要重启的TOMCAT命令", "0小时1分1秒","testtask");
MailSendInitialization.SendMailInitialization("test", test, "220");
}
}

View File

@ -1,9 +1,17 @@
package luckyclient.mail;
import java.util.Properties;
/**
* 发送邮件需要使用的基本信息
*/
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class MailSenderInfo {
// 发送邮件的服务器的IP和端口
private String mailServerHost;

View File

@ -2,16 +2,29 @@ package luckyclient.mail;
import javax.mail.*;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class MyAuthenticator extends Authenticator{
String userName=null;
String password=null;
public MyAuthenticator(){
}
}
public MyAuthenticator(String username, String password) {
this.userName = username;
this.password = password;
}
}
@Override
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userName, password);
}

View File

@ -14,11 +14,18 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
/**
* 简单邮件不带附件的邮件发送器
http://www.bt285.cn BT下载
*/
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class SimpleMailSender {
/**
* 以文本格式发送邮件

View File

@ -5,12 +5,24 @@ import java.util.List;
import luckyclient.planapi.entity.ProjectCase;
import luckyclient.planapi.entity.ProjectCasesteps;
import luckyclient.planapi.entity.PublicCaseParams;
import luckyclient.planapi.entity.TestTaskexcute;
import luckyclient.publicclass.remoterInterface.HttpRequest;
import luckyclient.publicclass.remoterinterface.HttpRequest;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class GetServerAPI {
@SuppressWarnings("unchecked")
@ -54,6 +66,15 @@ public class GetServerAPI {
return pc;
}
public static List<PublicCaseParams> cgetParamsByProjectid(String projectid) {
String result = HttpRequest.loadJSON("/publicCaseParams/cgetParamsByProjectid.do?projectid="+projectid);
JSONObject jsonObject = JSONObject.fromObject(result.toString());
JSONArray jsonarr = JSONArray.fromObject(jsonObject.getString("params"));
@SuppressWarnings("unchecked")
List<PublicCaseParams> list = JSONArray.toList(jsonarr, new PublicCaseParams(), new JsonConfig());
return list;
}
public static void cPostDebugLog(String sign, String executor, String loglevel, String detail){
sign = sign.replace("%","BBFFHH");
sign = sign.replace("=","DHDHDH");

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ProjectCase implements java.io.Serializable{
/**
*

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ProjectCasesteps implements java.io.Serializable{
/**
*

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ProjectPlan implements java.io.Serializable{
/**
*

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ProjectPlanCase implements java.io.Serializable{
/**
*

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ProjectProtocolTemplate{
/**
*

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ProjectTemplateParams{
/**
*
@ -9,6 +20,14 @@ public class ProjectTemplateParams{
private int templateid;
private String paramname;
private String param;
private int paramtype;
public int getParamtype() {
return paramtype;
}
public void setParamtype(int paramtype) {
this.paramtype = paramtype;
}
public int getId() {
return id;
}

View File

@ -0,0 +1,63 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class PublicCaseParams implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String paramsname;
private String paramsvalue;
private String remark;
private int projectid;
private String projectname;
public String getProjectname() {
return projectname;
}
public void setProjectname(String projectname) {
this.projectname = projectname;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getParamsname() {
return paramsname;
}
public void setParamsname(String paramsname) {
this.paramsname = paramsname;
}
public String getParamsvalue() {
return paramsvalue;
}
public void setParamsvalue(String paramsvalue) {
this.paramsvalue = paramsvalue;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public int getProjectid() {
return projectid;
}
public void setProjectid(int projectid) {
this.projectid = projectid;
}
}

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class TestJobs implements java.io.Serializable {
/**

View File

@ -1,5 +1,16 @@
package luckyclient.planapi.entity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class TestTaskexcute implements java.io.Serializable {
/**

View File

@ -0,0 +1,73 @@
package luckyclient.publicclass;
import java.util.Map;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class ChangString {
public static String changparams(String str,Map<String,String> variable,String changname){
try{
if(null==str){
return null;
}
str = str.replaceAll("&quot;", "\"");
str = str.replaceAll("&#39;", "\'");
//@@用来注释@的引用作用
int varcount=counter(str,"@")-counter(str,"@@")*2;
if(varcount>0){//如果存在传参进行处理
luckyclient.publicclass.LogUtil.APP.info(""+changname+""+str+"】中找到"+varcount+"个可替换参数");
int changcount=0;
//从参数列表中查找匹配变量
for (Map.Entry<String, String> entry : variable.entrySet()) {
if(str.indexOf("@"+entry.getKey())>-1){
if(str.indexOf("@@"+entry.getKey())>-1){
str=str.replaceAll("@@"+entry.getKey(), "////CHANG////");
}
int viewcount=counter(str,"@"+entry.getKey());
str=str.replaceAll("@"+entry.getKey(), entry.getValue());
luckyclient.publicclass.LogUtil.APP.info(""+changname+"引用变量【@"+entry.getKey()+"】替换成值【"+entry.getValue()+"");
str=str.replaceAll("////CHANG////","@@"+entry.getKey());
changcount=changcount+viewcount;
}
}
if(varcount!=changcount){
luckyclient.publicclass.LogUtil.APP.error(changname+"有引用变量未在参数列中找到,请检查!处理结果【"+str+"");
}
}
str=str.replaceAll("@@","@");
return str;
}catch(Exception e){
e.printStackTrace();
return "";
}
}
public static int counter(String str1,String str2){
int total = 0;
for (String tmp = str1; tmp != null&&tmp.length()>=str2.length();){
if(tmp.indexOf(str2) == 0){
total ++;
tmp = tmp.substring(str2.length());
}else{
tmp = tmp.substring(1);
}
}
return total;
}
public static void main(String[] args) {
}
}

View File

@ -7,8 +7,8 @@ import java.sql.SQLException;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: DBOperation
* @Description: 封装自动化过程中对数据库的部分操作
@ -22,8 +22,8 @@ public class DBOperation {
/**
* 创建链接池注意此方法不能new多次会导致多次创建链接池最好放在任务启动方法中
*/
public DBOperation(String url_base,String username_base,String password_base) {
dbt = new DBToolkit(url_base,username_base,password_base);
public DBOperation(String urlBase,String usernameBase,String passwordBase) {
dbt = new DBToolkit(urlBase,usernameBase,passwordBase);
}
@ -90,8 +90,9 @@ public class DBOperation {
}catch(Exception e){
throw e;
}finally{
if(rs!=null)
rs.close();
if(rs!=null){
rs.close();
}
DBToolkit.closeConnection(conn);
}
}
@ -142,7 +143,7 @@ public class DBOperation {
* @return int
* @throws
*/
public static void Wait(String s) throws InterruptedException{
public static void stepWait(String s) throws InterruptedException{
int second = Integer.parseInt(s);
Thread.sleep(second*1000);
}

View File

@ -11,8 +11,8 @@ import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: DBToolkit
* @Description: 创建与关闭数据库链接
@ -26,11 +26,11 @@ public class DBToolkit {
*/
public ComboPooledDataSource cpds=null;
public DBToolkit(String url_base,String username_base,String password_base){
public DBToolkit(String urlBase,String usernameBase,String passwordBase){
cpds=new ComboPooledDataSource();
cpds.setUser(username_base);
cpds.setPassword(password_base);
cpds.setJdbcUrl(url_base);
cpds.setUser(usernameBase);
cpds.setPassword(passwordBase);
cpds.setJdbcUrl(urlBase);
try {
cpds.setDriverClass("com.mysql.cj.jdbc.Driver");
} catch (PropertyVetoException e) {
@ -113,7 +113,9 @@ public class DBToolkit {
}
public static void closeConnection(Connection conn) {
if (conn == null) return;
if (conn == null){
return;
}
try {
if (!conn.isClosed()) {
//关闭数据库连接

View File

@ -7,8 +7,8 @@ import java.util.Map;
import luckyclient.planapi.entity.ProjectProtocolTemplate;
import luckyclient.planapi.entity.ProjectTemplateParams;
import luckyclient.publicclass.remoterInterface.HttpClientHelper;
import luckyclient.publicclass.remoterInterface.HttpRequest;
import luckyclient.publicclass.remoterinterface.HttpClientHelper;
import luckyclient.publicclass.remoterinterface.HttpRequest;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
@ -16,12 +16,14 @@ import net.sf.json.JsonConfig;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论 QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @ClassName: InvokeMethod
* @Description: 动态调用方法 @author seagull
* @date 2014年6月24日 上午9:29:40
* @Description: 动态调用方法
* @author seagull
* @date 2017年9月24日 上午9:29:40
*
*/
public class InvokeMethod {
@ -30,7 +32,7 @@ public class InvokeMethod {
* @param args
* @throws Throwable
*/
public static String CallCase(String packagename, String functionname, Object[] getParameterValues, int steptype,
public static String callCase(String packagename, String functionname, Object[] getParameterValues, int steptype,
String action) {
String result = "调用异常,请查看错误日志!";
try {
@ -49,7 +51,7 @@ public class InvokeMethod {
Method method = getMethod(server.getClass().getMethods(), functionname, getParameterTypes);
if (method == null) {
throw new Exception(
"客户端本地lib目录下没有在包名为【" + packagename + "】中找到被调用的方法【" + functionname + "】,请检查方法名称以及参数个数是否一致!");
"客户端本地驱动目录下没有在包名为【" + packagename + "】中找到被调用的方法【" + functionname + "】,请检查方法名称以及参数个数是否一致!");
}
Object str = method.invoke(server, getParameterValues);
if (str == null) {
@ -107,12 +109,23 @@ public class InvokeMethod {
if(ptp.getParam().indexOf("***[")>-1&&"***[".equals(ptp.getParam().substring(0, 4))){
ptp.setParam(ptp.getParam().substring(3));
}
params.put(ptp.getParamname().replaceAll("&quot;", "\""), ptp.getParam().replaceAll("&quot;", "\""));
//处理参数对象
if(ptp.getParamtype()==1){
String tempparam=ptp.getParam().replaceAll("&quot;", "\"");
JSONObject json= JSONObject.fromObject(tempparam);
params.put(ptp.getParamname().replaceAll("&quot;", "\""), json);
}else if(ptp.getParamtype()==2){
String tempparam=ptp.getParam().replaceAll("&quot;", "\"");
JSONArray jarr=JSONArray.fromObject(tempparam);
params.put(ptp.getParamname().replaceAll("&quot;", "\""), jarr);
}else{
params.put(ptp.getParamname().replaceAll("&quot;", "\""), ptp.getParam().replaceAll("&quot;", "\""));
}
}
//处理头域
Map<String, String> headmsg = new HashMap<String, String>();
if(null!=ppt.getHeadmsg()&&!ppt.getHeadmsg().equals("")&&ppt.getHeadmsg().indexOf("=")>0){
String temp[]=ppt.getHeadmsg().split(";",-1);
String[] temp=ppt.getHeadmsg().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("="));
@ -213,12 +226,23 @@ public class InvokeMethod {
if(ptp.getParam().indexOf("***[")>-1&&"***[".equals(ptp.getParam().substring(0, 4))){
ptp.setParam(ptp.getParam().substring(3));
}
params.put(ptp.getParamname().replaceAll("&quot;", "\""), ptp.getParam().replaceAll("&quot;", "\""));
//处理参数对象
if(ptp.getParamtype()==1){
String tempparam=ptp.getParam().replaceAll("&quot;", "\"");
JSONObject json= JSONObject.fromObject(tempparam);
params.put(ptp.getParamname().replaceAll("&quot;", "\""), json);
}else if(ptp.getParamtype()==2){
String tempparam=ptp.getParam().replaceAll("&quot;", "\"");
JSONArray jarr=JSONArray.fromObject(tempparam);
params.put(ptp.getParamname().replaceAll("&quot;", "\""), jarr);
}else{
params.put(ptp.getParamname().replaceAll("&quot;", "\""), ptp.getParam().replaceAll("&quot;", "\""));
}
}
//处理头域
Map<String, String> headmsg = new HashMap<String, String>();
if(null!=ppt.getHeadmsg()&&!ppt.getHeadmsg().equals("")&&ppt.getHeadmsg().indexOf("=")>0){
String temp[]=ppt.getHeadmsg().split(";",-1);
String[] temp=ppt.getHeadmsg().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("="));
@ -249,10 +273,13 @@ public class InvokeMethod {
public static Method getMethod(Method[] methods, String methodName, @SuppressWarnings("rawtypes") Class[] parameterTypes) {
for (int i = 0; i < methods.length; i++) {
if (!methods[i].getName().equals(methodName))
if (!methods[i].getName().equals(methodName)){
continue;
if (compareParameterTypes(parameterTypes, methods[i].getParameterTypes()))
}
if (compareParameterTypes(parameterTypes, methods[i].getParameterTypes())){
return methods[i];
}
}
return null;
}
@ -260,22 +287,28 @@ public class InvokeMethod {
public static boolean compareParameterTypes(@SuppressWarnings("rawtypes") Class[] parameterTypes, @SuppressWarnings("rawtypes") Class[] orgParameterTypes) {
// parameterTypes 里面int->Integer
// orgParameterTypes是原始参数类型
if (parameterTypes == null && orgParameterTypes == null)
if (parameterTypes == null && orgParameterTypes == null){
return true;
}
if (parameterTypes == null && orgParameterTypes != null) {
if (orgParameterTypes.length == 0)
if (orgParameterTypes.length == 0){
return true;
else
}else{
return false;
}
}
if (parameterTypes != null && orgParameterTypes == null) {
if (parameterTypes.length == 0)
if (parameterTypes.length == 0){
return true;
else
}else{
return false;
}
}
if (parameterTypes.length != orgParameterTypes.length)
if (parameterTypes.length != orgParameterTypes.length){
return false;
}
return true;
}

View File

@ -3,9 +3,20 @@ package luckyclient.publicclass;
import java.io.File;
import java.util.Enumeration;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class JarClassFind {
private static void FindClassInLocalSystem(String path,String classname) {
private static void findClassInLocalSystem(String path,String classname) {
int count = 0;
//String path = "D:\\web_task\\TestFrame\\lib\\"; //Ö¸¨²éÕÒ·¾
classname = classname.replace('.', '/') + ".class";
@ -58,7 +69,7 @@ public class JarClassFind {
static public void main(String[] args) {
String path = args[0];
String classname = args[1];
FindClassInLocalSystem(path,classname);
findClassInLocalSystem(path,classname);
}
}

View File

@ -43,13 +43,15 @@ public class LogUtil {
for(Field field:fieldArray){
field.setAccessible(true);
obj = field.get(bean);
if(!(obj instanceof List) && !field.getName().equals("serialVersionUID")){
if(indexId>0)
if(!(obj instanceof List) && !"serialVersionUID".equals(field.getName())){
if(indexId>0){
sb.append(",");
if(obj != null)
sb.append(field.getName()).append("=").append( obj.toString());
else
}
if(obj != null){
sb.append(field.getName()).append("=").append( obj.toString());
}else{
sb.append(field.getName()).append("=");
}
indexId += 1;
}
}

View File

@ -5,7 +5,7 @@ import java.util.Properties;
/**
* 系统配置参数
* @author Administrator
* @author seagull
*
*/
public class SysConfig {

View File

@ -1,4 +1,4 @@
package luckyclient.publicclass.remoterInterface;
package luckyclient.publicclass.remoterinterface;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -12,33 +12,44 @@ import java.util.Map;
import com.caucho.hessian.client.HessianProxyFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class HessianTestUtil {
private static final ObjectMapper mapper = new ObjectMapper();
private static final int connect_time_out = 30 * 1000;
private static final Map<String, Class<?>> base_type = new HashMap<String, Class<?>>();
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final int CONNECT_TIME_OUT = 30 * 1000;
private static final Map<String, Class<?>> BASE_TYPE = new HashMap<String, Class<?>>();
static {
base_type.put("long.class", long.class);
base_type.put("long.class", long.class);
base_type.put("float.class", float.class);
base_type.put("boolean.class", boolean.class);
base_type.put("char.class", char.class);
base_type.put("byte.class", byte.class);
// base_type.put("void.class", void.class);
base_type.put("short.class", short.class);
base_type.put("long", long.class);
base_type.put("float", float.class);
base_type.put("boolean", boolean.class);
base_type.put("char", char.class);
base_type.put("byte", byte.class);
// base_type.put("void", void.class);
base_type.put("short", short.class);
BASE_TYPE.put("long.class", long.class);
BASE_TYPE.put("long.class", long.class);
BASE_TYPE.put("float.class", float.class);
BASE_TYPE.put("boolean.class", boolean.class);
BASE_TYPE.put("char.class", char.class);
BASE_TYPE.put("byte.class", byte.class);
// BASE_TYPE.put("void.class", void.class);
BASE_TYPE.put("short.class", short.class);
BASE_TYPE.put("long", long.class);
BASE_TYPE.put("float", float.class);
BASE_TYPE.put("boolean", boolean.class);
BASE_TYPE.put("char", char.class);
BASE_TYPE.put("byte", byte.class);
// BASE_TYPE.put("void", void.class);
BASE_TYPE.put("short", short.class);
}
public static Map<String, Object> startInvoke(InterfaceObject object)
throws Exception {
// 获取带请求参数列表将参数类型参数值数组转成InterfaceParamObject数组
InterfaceParamObject[] paramContent = mapper
InterfaceParamObject[] paramContent = MAPPER
.readValue(object.getParams(), InterfaceParamObject[].class);
Map<String, Object> resultMap = hessianInvoke(object.getRemoteUrl(),
object.getInterfaceClass(), object.getInterfaceMethod(),
@ -51,15 +62,15 @@ public class HessianTestUtil {
String className, String methodName,
InterfaceParamObject[] interfaceParamArray) throws Exception {
HessianProxyFactory factory = new HessianProxyFactory();
factory.setReadTimeout(connect_time_out);
factory.setReadTimeout(CONNECT_TIME_OUT);
// factory.setConnectTimeout(connect_time_out);
// factory.setReadTimeout(read_time_out);
Object InterfaceObject = null;
Class<?> allRequstParasClass[] = new Class[interfaceParamArray.length];
Object interfaceObject = null;
Class<?>[] allRequstParasClass = new Class[interfaceParamArray.length];
Object[] allRequstParas = new Object[interfaceParamArray.length];
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
InterfaceObject = factory.create(Class.forName(className),remoteUrl);
interfaceObject = factory.create(Class.forName(className),remoteUrl);
} catch (Exception ex) {
throw ex;
}
@ -71,15 +82,15 @@ public class HessianTestUtil {
.getClassname();
if (isBaseTypeForArray(tempParaClassName)) {
// 如果是基础数据类型那么mapper转换再获取类类型就会有问题所以值和类分开
allRequstParasClass[index] = base_type
allRequstParasClass[index] = BASE_TYPE
.get(tempParaClassName);
allRequstParas[index] = mapper.readValue(
allRequstParas[index] = MAPPER.readValue(
interfaceParamArray[index].getValue(),
base_type.get(tempParaClassName));
BASE_TYPE.get(tempParaClassName));
} else {
allRequstParasClass[index] = Class
.forName(tempParaClassName);
allRequstParas[index] = mapper.readValue(
allRequstParas[index] = MAPPER.readValue(
interfaceParamArray[index].getValue(),
allRequstParasClass[index]);
}
@ -90,10 +101,10 @@ public class HessianTestUtil {
}
try {
Method method = InterfaceObject.getClass().getMethod(methodName,
Method method = interfaceObject.getClass().getMethod(methodName,
allRequstParasClass);
Class<?> returnClass = method.getReturnType();
Object result = method.invoke(InterfaceObject, allRequstParas);
Object result = method.invoke(interfaceObject, allRequstParas);
if (returnClass == void.class) {
resultMap.put("参数返回类型为void", "执行结束,没有返回值");
@ -133,9 +144,9 @@ public class HessianTestUtil {
public static Map<String, Object> objectToMap(Object obj) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String ObjClass = obj.getClass().getName();
if (isBaseTypeForArray(ObjClass)) {
map.put(ObjClass, obj.toString());
String objClass = obj.getClass().getName();
if (isBaseTypeForArray(objClass)) {
map.put(objClass, obj.toString());
} else {
// Field[] allField = obj.getClass().getDeclaredFields();
Field[] allField = getAllFields(obj);
@ -161,11 +172,11 @@ public class HessianTestUtil {
return fields;
}
private static boolean isBaseTypeForArray(String ObjClassName) {
private static boolean isBaseTypeForArray(String objClassName) {
boolean isBase = false;
if (ObjClassName != null) {
isBase = base_type.get(ObjClassName) != null ? true : false;
if (objClassName != null) {
isBase = BASE_TYPE.get(objClassName) != null ? true : false;
}
return isBase;
}

View File

@ -1,4 +1,4 @@
package luckyclient.publicclass.remoterInterface;
package luckyclient.publicclass.remoterinterface;
import java.io.BufferedReader;
import java.io.FileOutputStream;
@ -13,18 +13,15 @@ import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import javax.xml.bind.DatatypeConverter;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@ -32,16 +29,21 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import net.sf.json.JSONObject;
/**
* @Description:·¢ËÍhttpÇëÇó°ïÖúÀà
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class HttpClientHelper {
/**
@ -76,9 +78,10 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
//value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -164,9 +167,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -248,9 +251,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -328,9 +331,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -397,9 +400,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@ -442,9 +445,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@ -494,9 +497,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@ -578,9 +581,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
httpGet.setHeader(key, value);
}else{
httpGet.setHeader(key, value);
@ -644,9 +647,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
sb.append(key+": "+value+" \r\n");
}else{
sb.append(key+": "+value+" \r\n");
@ -675,7 +678,7 @@ public class HttpClientHelper {
contentLength = Integer.parseInt(line.split(":")[1].trim());
}
// 如果遇到了一个单独的回车换行则表示请求头结束
} while (!line.equals("\r\n"));
} while (!"\r\n".equals(line));
// 读取出响应体数据就是你要的数据
result = readLine(is, contentLength, charset);
} catch (Exception e) {
@ -753,9 +756,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
sb.append(key+": "+value+" \r\n");
}else{
sb.append(key+": "+value+" \r\n");
@ -784,7 +787,7 @@ public class HttpClientHelper {
contentLength = Integer.parseInt(line.split(":")[1].trim());
}
// 如果遇到了一个单独的回车换行则表示请求头结束
} while (!line.equals("\r\n"));
} while (!"\r\n".equals(line));
// 读取出响应体数据就是你要的数据
result = readLine(is, contentLength, charset);
} catch (Exception e) {
@ -887,9 +890,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
con.setRequestProperty(key,value);
}else{
con.setRequestProperty(key,value);
@ -960,9 +963,9 @@ public class HttpClientHelper {
for (Map.Entry<String, String> m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
if(null!=value&&value.indexOf("Base64(")>0){
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + Base64.encode((valuesub).getBytes());
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
httpput.setHeader(key,value);
}else{
httpput.setHeader(key,value);

View File

@ -1,4 +1,4 @@
package luckyclient.publicclass.remoterInterface;
package luckyclient.publicclass.remoterinterface;
import java.io.BufferedReader;
import java.io.IOException;
@ -12,10 +12,21 @@ import java.util.Properties;
import luckyclient.publicclass.LogUtil;
import luckyclient.publicclass.SysConfig;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class HttpRequest {
final static Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
private final static String Web_URL = "http://" + properties.getProperty("server.web.ip") + ":"
+ properties.getProperty("server.web.port");
final static Properties PROPERTIES = luckyclient.publicclass.SysConfig.getConfiguration();
private final static String WEB_URL = "http://" + PROPERTIES.getProperty("server.web.ip") + ":"
+ PROPERTIES.getProperty("server.web.port");
/**
* 字符串参数
@ -27,7 +38,7 @@ public class HttpRequest {
StringBuilder json = new StringBuilder();
URL url=null;
try {
url = new URL(Web_URL+repath);
url = new URL(WEB_URL+repath);
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine = null;
@ -58,7 +69,7 @@ public class HttpRequest {
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(Web_URL+repath);
URL realUrl = new URL(WEB_URL+repath);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性

View File

@ -1,5 +1,16 @@
package luckyclient.publicclass.remoterInterface;
package luckyclient.publicclass.remoterinterface;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class InterfaceObject {
/**
* ½Ó¿ÚÀà

View File

@ -1,5 +1,16 @@
package luckyclient.publicclass.remoterInterface;
package luckyclient.publicclass.remoterinterface;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class InterfaceParamObject {
/**
* 参数类

View File

@ -1,4 +1,4 @@
package luckyclient.publicclass.remoterInterface;
package luckyclient.publicclass.remoterinterface;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@ -16,27 +16,38 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class InterfaceTestUtil {
private static Logger log = LoggerFactory
.getLogger(InterfaceTestUtil.class);
private static final ObjectMapper map = new ObjectMapper();
private static final int read_time_out = 30 * 1000;
private static final Map<String, Class<?>> base_type = new HashMap<String, Class<?>>();
private static final ObjectMapper MAP = new ObjectMapper();
private static final int READ_TIME_OUT = 30 * 1000;
private static final Map<String, Class<?>> BASE_TYPE = new HashMap<String, Class<?>>();
static {
base_type.put("long", long.class);
base_type.put("double", double.class);
base_type.put("float", float.class);
base_type.put("bool", boolean.class);
base_type.put("char", char.class);
base_type.put("byte", byte.class);
base_type.put("void", void.class);
base_type.put("short", short.class);
BASE_TYPE.put("long", long.class);
BASE_TYPE.put("double", double.class);
BASE_TYPE.put("float", float.class);
BASE_TYPE.put("bool", boolean.class);
BASE_TYPE.put("char", char.class);
BASE_TYPE.put("byte", byte.class);
BASE_TYPE.put("void", void.class);
BASE_TYPE.put("short", short.class);
}
public static Map<String, Object> doTest(InterfaceObject object)
throws Exception {
// 获取带请求参数列表将参数类型参数值数组转成InterfaceParamObject数组
InterfaceParamObject[] paramContent = map.readValue(object.getParams(),
InterfaceParamObject[] paramContent = MAP.readValue(object.getParams(),
InterfaceParamObject[].class);
Object result = hessian(object.getRemoteUrl(),
object.getInterfaceClass(), object.getInterfaceMethod(),
@ -54,9 +65,9 @@ public class InterfaceTestUtil {
public static Map<String, Object> objectToMap(Object obj) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String ObjClass = obj.getClass().getName();
if (isBaseTypeForArray(ObjClass)) {
map.put(ObjClass, obj.toString());
String objClass = obj.getClass().getName();
if (isBaseTypeForArray(objClass)) {
map.put(objClass, obj.toString());
} else {
// Field[] allField = obj.getClass().getDeclaredFields();
Field[] allField = getAllFields(obj);
@ -85,25 +96,25 @@ public class InterfaceTestUtil {
return fields;
}
private static boolean isBaseTypeForArray(String ObjClassName) {
private static boolean isBaseTypeForArray(String objClassName) {
boolean isBase = false;
if (ObjClassName != null) {
isBase = base_type.get(ObjClassName) != null ? true : false;
if (objClassName != null) {
isBase = BASE_TYPE.get(objClassName) != null ? true : false;
}
return isBase;
}
public static String genJsonStr(Object object)
throws JsonProcessingException {
return map.writeValueAsString(object);
return MAP.writeValueAsString(object);
}
private static Object hessian(String remoteUrl, String className,
String methodName, InterfaceParamObject[] paramContent)
throws Exception {
HessianProxyFactory factory = new HessianProxyFactory();
factory.setReadTimeout(read_time_out);
factory.setReadTimeout(READ_TIME_OUT);
Object interfaceObj = null;
Class<?> interfaceClassName = null;
@ -162,7 +173,7 @@ public class InterfaceTestUtil {
Object[] allRequstParas) {
int totalRequestParam = allRequstParas.length;
Class<?> allRequstParasClass[] = null;
Class<?>[] allRequstParasClass = null;
if (allRequstParas != null) {// 存在
int len = allRequstParas.length;
allRequstParasClass = new Class[len];
@ -201,12 +212,12 @@ public class InterfaceTestUtil {
* @see
*/
private static Class<?> getBaseTypeClassByName(String className) {
return base_type.get(className);
return BASE_TYPE.get(className);
}
private static Boolean isBaseType(String className) {
Boolean istrue = false;
for (String key : base_type.keySet()) {
for (String key : BASE_TYPE.keySet()) {
istrue = className.equals(key) ? true : false;
}
return istrue;

View File

@ -12,8 +12,8 @@ import luckyclient.dblog.LogOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: AnalyticCase
* @Description: 解析单个用例中描述部分的脚本
@ -28,7 +28,7 @@ public class InterfaceAnalyticTestLinkCase{
* @param args
*/
@SuppressWarnings("finally")
public static Map<String,String> AnalyticCaseStep(TestCase testcase,Integer ordersteps,String tastid,LogOperation caselog){
public static Map<String,String> analyticCaseStep(TestCase testcase,Integer ordersteps,String tastid,LogOperation caselog){
String time = "0";
Map<String,String> params = new HashMap<String,String>();
@ -36,13 +36,13 @@ public class InterfaceAnalyticTestLinkCase{
try {
List<TestCaseStep> testcasesteps = (List<TestCaseStep>) testcase.getSteps();
String stepsstr = testcasesteps.get(ordersteps-1).getActions(); //获取actions字符串
String scriptstr = SubComment(stepsstr);
String scriptstr = subComment(stepsstr);
if(scriptstr.substring(scriptstr.length()-6, scriptstr.length()).indexOf("*Wait;")>-1){ //添加步骤之间等待时间
time = scriptstr.substring(scriptstr.lastIndexOf("|")+1,scriptstr.lastIndexOf("*Wait;"));
scriptstr = scriptstr.substring(0, scriptstr.lastIndexOf("|")+1);
}
resultstr = testcasesteps.get(ordersteps-1).getExpectedResults(); //获取预期结果字符串
String temp[]=scriptstr.split(splitFlag,-1);
String[] temp=scriptstr.split(splitFlag,-1);
for(int i=0;i<temp.length;i++){
if(i==0){
String packagenage = temp[i].substring(0, temp[i].indexOf("#"));
@ -50,58 +50,58 @@ public class InterfaceAnalyticTestLinkCase{
// String functionname = temp[i].substring(0, temp[i].indexOf(";"));
params.put("PackageName", packagenage.trim()); //set包名
params.put("FunctionName", functionname.trim()); //set方法名称
}else if(temp[i].equals("")){
}else if("".equals(temp[i])){
continue;
}else{
params.put("FunctionParams"+i, temp[i]); //set第N个传入参数
}
}
//set预期结果
if(resultstr.equals("")){
if("".equals(resultstr)){
params.put("ExpectedResults", "");
}else{
params.put("ExpectedResults", SubComment(resultstr));
params.put("ExpectedResults", subComment(resultstr));
}
params.put("StepWait", time);
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+testcase.getFullExternalId()+" 步骤编号:"+ordersteps+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.CaseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本完成!","info",String.valueOf(ordersteps),"");
caselog.caseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本完成!","info",String.valueOf(ordersteps),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+testcase.getFullExternalId()+" 步骤编号:"+ordersteps+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.CaseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本出错!","error",String.valueOf(ordersteps),"");
caselog.caseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本出错!","error",String.valueOf(ordersteps),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
params.put("FunctionName","用例编号:"+testcase.getFullExternalId()+"|解析异常,用例步骤为空或是用例脚本错误!");
}finally{
return params;
return params;
}
return params;
}
public static String SubComment(String htmlStr) throws InterruptedException{
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
String regEx_space = "\t|\r|\n";//定义空格回车换行符
public static String subComment(String htmlStr) throws InterruptedException{
String regExScript = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regExStyle = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regExHtml = "<[^>]+>"; // 定义HTML标签的正则表达式
String regExSpace = "\t|\r|\n";//定义空格回车换行符
String scriptstr = null;
if (htmlStr!=null) {
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
Matcher mScript = pScript.matcher(htmlStr);
htmlStr = mScript.replaceAll(""); // 过滤script标签
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); // 过滤style标签
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
Matcher mStyle = pStyle.matcher(htmlStr);
htmlStr = mStyle.replaceAll(""); // 过滤style标签
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
Matcher mHtml = pHtml.matcher(htmlStr);
htmlStr = mHtml.replaceAll(""); // 过滤html标签
Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
Matcher mSpace = pSpace.matcher(htmlStr);
htmlStr = mSpace.replaceAll(""); // 过滤空格回车标签
}
if(htmlStr.indexOf("/*")>-1&&htmlStr.indexOf("*/")>-1){

View File

@ -11,8 +11,8 @@ import luckyclient.dblog.LogOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: TestBuildApi
* @Description: 二次封装关于测试版本部分的API
@ -34,10 +34,10 @@ public class TestBuildApi extends TestLinkBaseApi {
//能过项目名称以及计划名称获取计划ID
TestPlan testplanob = new TestPlan();
// testplanob = api.getTestPlanByName(TestPlanName(projectname), projectname);
if(TestControl.TASKID.indexOf("NULL")>-1||LogOperation.GetTestPlanName(TestControl.TASKID).indexOf("NULL")>-1){
testplanob = api.getTestPlanByName(TestPlanName(projectname), projectname);
if(TestControl.TASKID.indexOf("NULL")>-1||LogOperation.getTestPlanName(TestControl.TASKID).indexOf("NULL")>-1){
testplanob = api.getTestPlanByName(testPlanName(projectname), projectname);
}else{
testplanob = api.getTestPlanByName(LogOperation.GetTestPlanName(TestControl.TASKID), projectname);
testplanob = api.getTestPlanByName(LogOperation.getTestPlanName(TestControl.TASKID), projectname);
}
Integer planid = testplanob.getId();
@ -57,14 +57,14 @@ public class TestBuildApi extends TestLinkBaseApi {
/**
* 当没在测试计划中找到版本后自动创建一个版本
*/
public static void GetBuild(String projectname){
public static void getBuild(String projectname){
//能过项目名称以及计划名称获取计划ID
TestPlan testplanob = new TestPlan();
// testplanob = api.getTestPlanByName(TestPlanName(projectname), projectname);
if(TestControl.TASKID.indexOf("NULL")>-1||LogOperation.GetTestPlanName(TestControl.TASKID).indexOf("NULL")>-1){
testplanob = api.getTestPlanByName(TestPlanName(projectname), projectname);
if(TestControl.TASKID.indexOf("NULL")>-1||LogOperation.getTestPlanName(TestControl.TASKID).indexOf("NULL")>-1){
testplanob = api.getTestPlanByName(testPlanName(projectname), projectname);
}else{
testplanob = api.getTestPlanByName(LogOperation.GetTestPlanName(TestControl.TASKID), projectname);
testplanob = api.getTestPlanByName(LogOperation.getTestPlanName(TestControl.TASKID), projectname);
}
Integer planid = testplanob.getId();
try{

View File

@ -17,13 +17,13 @@ import br.eti.kinoshita.testlinkjavaapi.model.TestSuite;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.dblog.LogOperation;
import luckyclient.publicclass.remoterInterface.HttpRequest;
import luckyclient.publicclass.remoterinterface.HttpRequest;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: TestCaseApi
* @Description: 二次封装关于测试用例部分的API
@ -111,12 +111,12 @@ public class TestCaseApi extends TestLinkBaseApi {
//能过项目名称以及计划名称获取计划ID
TestPlan testplanob = new TestPlan();
//testplanob = api.getTestPlanByName(TestPlanName(projectname), projectname);
testplanob = api.getTestPlanByName(LogOperation.GetTestPlanName(TestControl.TASKID), projectname);
testplanob = api.getTestPlanByName(LogOperation.getTestPlanName(TestControl.TASKID), projectname);
Integer planid = testplanob.getId();
Map<String, Object> params = new HashMap<String, Object>();
params.put("devKey", TESTLINK_DEVKEY);
params.put("testprojectid", ProjectID(projectname));
params.put("testprojectid", projectID(projectname));
params.put("testplanid", planid);
params.put("testcaseexternalid", testCaseExternalID);
params.put("version", version);
@ -161,10 +161,10 @@ public class TestCaseApi extends TestLinkBaseApi {
if ("888888".equals(taskid)) {
tp = api.getTestPlanByName(testplan, projectname);
} else if (taskid.indexOf("NULL") > -1 || LogOperation.GetTestPlanName(taskid).indexOf("NULL") > -1) {
tp = api.getTestPlanByName(TestPlanName(projectname), projectname);
} else if (taskid.indexOf("NULL") > -1 || LogOperation.getTestPlanName(taskid).indexOf("NULL") > -1) {
tp = api.getTestPlanByName(testPlanName(projectname), projectname);
} else {
tp = api.getTestPlanByName(LogOperation.GetTestPlanName(taskid), projectname);
tp = api.getTestPlanByName(LogOperation.getTestPlanName(taskid), projectname);
}
planid = tp.getId();
//用例明细全部信息
@ -198,27 +198,27 @@ public class TestCaseApi extends TestLinkBaseApi {
}catch( TestLinkAPIException te) {
te.printStackTrace( System.err );
luckyclient.publicclass.LogUtil.ERROR.error("项目:"+projectname+" 测试计划:"+TestPlanName(projectname)+" 读取自动化用例对象异常!");
luckyclient.publicclass.LogUtil.ERROR.error("项目:"+projectname+" 测试计划:"+testPlanName(projectname)+" 读取自动化用例对象异常!");
System.exit(-1);
}
return testCases;
}
public static TestCase getTestCaseByExternalId(String TestCaseExternalId,int version){
return api.getTestCaseByExternalId(TestCaseExternalId, version);
public static TestCase getTestCaseByExternalId(String testCaseExternalId,int version){
return api.getTestCaseByExternalId(testCaseExternalId, version);
}
/**
* 更新testlink中用例指定步骤的预期结果
*/
public static String setTestLinkExpectedResults(String TestCaseExternalId, int version, int steps, String expectedResults) {
public static String setTestLinkExpectedResults(String testCaseExternalId, int version, int steps, String expectedResults) {
String results = "设置结果失败";
try {
TestCase tc = api.getTestCaseByExternalId(TestCaseExternalId, version);
TestCase tc = api.getTestCaseByExternalId(testCaseExternalId, version);
tc.getSteps().get(steps - 1).setExpectedResults(expectedResults);
api.createTestCaseSteps(tc.getId(), TestCaseExternalId, tc.getVersion(), TestCaseStepAction.UPDATE, tc.getSteps());
api.createTestCaseSteps(tc.getId(), testCaseExternalId, tc.getVersion(), TestCaseStepAction.UPDATE, tc.getSteps());
results = "设置结果成功";
} catch (TestLinkAPIException te) {
te.printStackTrace(System.err);
@ -232,14 +232,14 @@ public class TestCaseApi extends TestLinkBaseApi {
/**
* 更新系统中用例指定步骤的预期结果
*/
public static String setExpectedResults(String TestCaseSign, int steps, String expectedResults) {
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="caseno="+testCaseSign;
params+="&stepnum="+steps;
params+="&expectedresults="+expectedResults;
results=HttpRequest.sendPost("/projectCasesteps/cUpdateStepExpectedResults.do", params);
@ -256,9 +256,9 @@ public class TestCaseApi extends TestLinkBaseApi {
* 获取指定任务名称以及用例号报错日志中的执行测试结果
* casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogdetail_Runresult(String taskname,String caseno,int casestatus){
int taskid = LogOperation.gettaskexcute_taskid(taskname);
return LogOperation.getlogdetail_testresult(taskid, caseno,casestatus);
public static String getLogDetailRunresult(String taskname,String caseno,int casestatus){
int taskid = LogOperation.getTaskExcuteTaskid(taskname);
return LogOperation.getLogDetailTestResult(taskid, caseno,casestatus);
}
/**
@ -273,7 +273,7 @@ public class TestCaseApi extends TestLinkBaseApi {
TestCase suitecase=api.getTestCaseByExternalId(cases.getFullExternalId(), cases.getVersion());
List<Integer> suiteid=new ArrayList<Integer>();
suiteid.add(suitecase.getTestSuiteId());
TestSuite suite[]=api.getTestSuiteByID(suiteid);
TestSuite[] suite=api.getTestSuiteByID(suiteid);
String params="";
@ -290,7 +290,7 @@ public class TestCaseApi extends TestLinkBaseApi {
String stepsparams="";
String resultstr = null;
String stepsstr = step.getActions(); //获取actions字符串
String scriptstr = InterfaceAnalyticTestLinkCase.SubComment(stepsstr);
String scriptstr = InterfaceAnalyticTestLinkCase.subComment(stepsstr);
if(scriptstr.substring(scriptstr.length()-6, scriptstr.length()).indexOf("*Wait;")>-1){
String action="";
@ -304,13 +304,13 @@ public class TestCaseApi extends TestLinkBaseApi {
stepsparams="action="+action+"&";
scriptstr = scriptstr.substring(0, scriptstr.lastIndexOf("|")+1);
}
resultstr = InterfaceAnalyticTestLinkCase.SubComment(step.getExpectedResults()); //获取预期结果字符串
resultstr = InterfaceAnalyticTestLinkCase.subComment(step.getExpectedResults()); //获取预期结果字符串
stepsparams+="expectedresult="+resultstr.replace("%", "BBFFHH");
stepsparams+="&caseid="+caseid;
stepsparams+="&stepnum="+k;
stepsparams+="&projectid="+projectid;
stepsparams+="&steptype=0";
String temp[]=scriptstr.split("\\|",-1);
String[] temp=scriptstr.split("\\|",-1);
String param="";
for(int i=0;i<temp.length;i++){
if(i==0){
@ -318,7 +318,7 @@ public class TestCaseApi extends TestLinkBaseApi {
String functionname = temp[i].substring(temp[i].indexOf("#")+1, temp[i].indexOf(";"));
stepsparams+="&path="+packagenage.trim(); //set包名
stepsparams+="&operation="+functionname.trim(); //set方法名称
}else if(temp[i].equals("")){
}else if("".equals(temp[i])){
continue;
}else{
param+=temp[i]+"|";
@ -348,7 +348,7 @@ public class TestCaseApi extends TestLinkBaseApi {
TestCase suitecase=api.getTestCaseByExternalId(cases.getFullExternalId(), cases.getVersion());
List<Integer> suiteid=new ArrayList<Integer>();
suiteid.add(suitecase.getTestSuiteId());
TestSuite suite[]=api.getTestSuiteByID(suiteid);
TestSuite[] suite=api.getTestSuiteByID(suiteid);
String params="";
@ -365,7 +365,7 @@ public class TestCaseApi extends TestLinkBaseApi {
String stepsparams="";
String resultstr = null;
String stepsstr = step.getActions(); //获取actions字符串
String scriptstr = InterfaceAnalyticTestLinkCase.SubComment(stepsstr);
String scriptstr = InterfaceAnalyticTestLinkCase.subComment(stepsstr);
if(scriptstr.substring(scriptstr.length()-6, scriptstr.length()).indexOf("*Wait;")>-1){
String action="";
@ -379,13 +379,13 @@ public class TestCaseApi extends TestLinkBaseApi {
stepsparams="action="+action+"&";
scriptstr = scriptstr.substring(0, scriptstr.lastIndexOf("|")+1);
}
resultstr = InterfaceAnalyticTestLinkCase.SubComment(step.getExpectedResults()); //获取预期结果字符串
resultstr = InterfaceAnalyticTestLinkCase.subComment(step.getExpectedResults()); //获取预期结果字符串
stepsparams+="expectedresult="+resultstr.replace("%", "BBFFHH");
stepsparams+="&caseid="+caseid;
stepsparams+="&stepnum="+k;
stepsparams+="&projectid="+projectid;
stepsparams+="&steptype=1";
String temp[]=scriptstr.split("\\|",-1);
String[] temp=scriptstr.split("\\|",-1);
for(int i=0;i<temp.length;i++){
if(i==0&&temp[i].indexOf("=")>-1&&(temp.length>2||!"".equals(temp[1]))){
stepsparams+="&path="+temp[i].replace("=", "DHDHDH"); //set包名
@ -393,16 +393,16 @@ public class TestCaseApi extends TestLinkBaseApi {
continue;
}else{
String operation = null;
String operation_value = null;
String operationValue = null;
if(temp[i].indexOf("(")>-1&&temp[i].indexOf(")")>-1){
operation = temp[i].substring(0, temp[i].indexOf("("));
operation_value = temp[i].substring(temp[i].indexOf("(")+1, temp[i].lastIndexOf(")"));
operationValue = temp[i].substring(temp[i].indexOf("(")+1, temp[i].lastIndexOf(")"));
}else{
operation = temp[i];
}
stepsparams+="&operation="+operation.toLowerCase(); //set方法名称
if(null!=operation_value){
stepsparams+="&parameters="+operation_value.replace("%", "BBFFHH"); //set方法名称
if(null!=operationValue){
stepsparams+="&parameters="+operationValue.replace("%", "BBFFHH"); //set方法名称
}
}
}
@ -421,9 +421,9 @@ public class TestCaseApi extends TestLinkBaseApi {
* 获取指定任务名称以及用例号报错日志中的执行预期结果
* casestatus说明 pass:0 fail:1 lock:2 unexcute:4
*/
public static String getLogdetail_Expectresult(String taskname,String caseno,int casestatus){
int taskid = LogOperation.gettaskexcute_taskid(taskname);
return LogOperation.getlogdetail_expectresult(taskid, caseno,casestatus);
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){

View File

@ -9,8 +9,8 @@ import br.eti.kinoshita.testlinkjavaapi.TestLinkAPI;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: TestLinkBaseApi
* @Description: 初始化TESTLINK接口
@ -23,9 +23,9 @@ class TestLinkBaseApi{
/**
* @param args
*/
final static Properties properties = luckyclient.publicclass.SysConfig.getConfiguration();
private final static String TESTLINK_URL = "http://"+properties.getProperty("testlink.api.ip")+":80/testlink/lib/api/xmlrpc/v1/xmlrpc.php";
protected final static String TESTLINK_DEVKEY = properties.getProperty("testlink.api.devkey");
final static Properties PROPERTIES = luckyclient.publicclass.SysConfig.getConfiguration();
private final static String TESTLINK_URL = "http://"+PROPERTIES.getProperty("testlink.api.ip")+":80/testlink/lib/api/xmlrpc/v1/xmlrpc.php";
protected final static String TESTLINK_DEVKEY = PROPERTIES.getProperty("testlink.api.devkey");
protected final static Integer PLATFORMID = 0;
protected final static String PLATFORMNAME = null;
protected static TestLinkAPI api= iniTestlinkApi();
@ -41,13 +41,13 @@ class TestLinkBaseApi{
return new TestLinkAPI(testlinkURL, TESTLINK_DEVKEY);
}
protected static String TestPlanName(String projectname){
protected static String testPlanName(String projectname){
return api.getTestProjectByName(projectname).getNotes().substring(
api.getTestProjectByName(projectname).getNotes().indexOf("<p>")+3,
api.getTestProjectByName(projectname).getNotes().indexOf("</p>")).trim();
}
protected static Integer ProjectID(String projectname){
protected static Integer projectID(String projectname){
return api.getTestProjectByName(projectname).getId();
}

View File

@ -12,8 +12,8 @@ import luckyclient.dblog.LogOperation;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 此测试框架主要采用testlink做分层框架负责数据驱动以及用例管理部分有任何疑问欢迎联系作者讨论
* QQ:24163551 seagull1985
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
* @ClassName: AnalyticCase
* @Description: 解析单个用例中描述部分的脚本
@ -28,7 +28,7 @@ public class WebDriverAnalyticTestLinkCase {
* @param args
*/
@SuppressWarnings("finally")
public static Map<String,String> AnalyticCaseStep(TestCase testcase,Integer ordersteps,String tastid,LogOperation caselog){
public static Map<String,String> analyticCaseStep(TestCase testcase,Integer ordersteps,String tastid,LogOperation caselog){
String time = "0";
Map<String,String> params = new HashMap<String,String>();
@ -36,91 +36,91 @@ public class WebDriverAnalyticTestLinkCase {
try {
List<TestCaseStep> testcasesteps = (List<TestCaseStep>) testcase.getSteps();
String stepsstr = testcasesteps.get(ordersteps-1).getActions(); //获取actions字符串
String scriptstr = SubComment(stepsstr);
String scriptstr = subComment(stepsstr);
if(scriptstr.substring(scriptstr.length()-6, scriptstr.length()).toLowerCase().indexOf("*wait;")>-1){ //添加步骤之间等待时间
time = scriptstr.substring(scriptstr.lastIndexOf("|")+1,scriptstr.toLowerCase().lastIndexOf("*wait;"));
scriptstr = scriptstr.substring(0, scriptstr.lastIndexOf("|")+1);
}
resultstr = testcasesteps.get(ordersteps-1).getExpectedResults(); //获取预期结果字符串
String temp[]=scriptstr.split(splitFlag,-1);
String[] temp=scriptstr.split(splitFlag,-1);
for(int i=0;i<temp.length;i++){
if(i==0&&temp[i].indexOf("=")>-1&&(temp.length>2||!"".equals(temp[1]))){
String property = temp[i].substring(0, temp[i].indexOf("="));
String property_value = temp[i].substring(temp[i].indexOf("=")+1, temp[i].length());
String propertyValue = temp[i].substring(temp[i].indexOf("=")+1, temp[i].length());
params.put("property", property.trim().toLowerCase()); //set属性
params.put("property_value", property_value.trim()); //set属性值
luckyclient.publicclass.LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+property_value.trim());
params.put("property_value", propertyValue.trim()); //set属性值
luckyclient.publicclass.LogUtil.APP.info("对象属性解析结果property:"+property.trim()+"; property_value:"+propertyValue.trim());
}else if("".equals(temp[i])){
continue;
}else{
String operation = null;
String operation_value = null;
String operationValue = null;
if(temp[i].indexOf("(")>-1&&temp[i].indexOf(")")>-1){
operation = temp[i].substring(0, temp[i].indexOf("("));
operation_value = temp[i].substring(temp[i].indexOf("(")+1, temp[i].lastIndexOf(")"));
operationValue = temp[i].substring(temp[i].indexOf("(")+1, temp[i].lastIndexOf(")"));
}else{
operation = temp[i];
}
params.put("operation", operation.toLowerCase()); //set操作方法
params.put("operation_value", operation_value); //set操作值
luckyclient.publicclass.LogUtil.APP.info("对象操作解析结果operation:"+operation+"; operation_value:"+operation_value);
params.put("operation_value", operationValue); //set操作值
luckyclient.publicclass.LogUtil.APP.info("对象操作解析结果operation:"+operation+"; operation_value:"+operationValue);
}
}
//set预期结果
if(resultstr.equals("")){
params.put("ExpectedResults", "");
}else{
String ExpectedResults = SubComment(resultstr);
String expectedResults = subComment(resultstr);
//处理check字段
if(ExpectedResults.indexOf("check(")>-1){
params.put("checkproperty", ExpectedResults.substring(ExpectedResults.indexOf("check(")+6, ExpectedResults.indexOf("=")));
params.put("checkproperty_value", ExpectedResults.substring(ExpectedResults.indexOf("=")+1, ExpectedResults.indexOf(")")));
if(expectedResults.indexOf("check(")>-1){
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("=")));
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.indexOf(")")));
}
params.put("ExpectedResults", ExpectedResults);
luckyclient.publicclass.LogUtil.APP.info("预期结果解析ExpectedResults:"+ExpectedResults);
params.put("ExpectedResults", expectedResults);
luckyclient.publicclass.LogUtil.APP.info("预期结果解析ExpectedResults:"+expectedResults);
}
params.put("StepWait", time);
luckyclient.publicclass.LogUtil.APP.info("用例编号:"+testcase.getFullExternalId()+" 步骤编号:"+ordersteps+" 解析自动化用例步骤脚本完成!");
if(null!=caselog){
caselog.CaseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本完成!","info",String.valueOf(ordersteps),"");
caselog.caseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本完成!","info",String.valueOf(ordersteps),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+testcase.getFullExternalId()+" 步骤编号:"+ordersteps+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.CaseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本出错!","error",String.valueOf(ordersteps),"");
caselog.caseLogDetail(tastid, testcase.getFullExternalId(),"步骤编号:"+ordersteps+" 解析自动化用例步骤脚本出错!","error",String.valueOf(ordersteps),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
params.put("exception","用例编号:"+testcase.getFullExternalId()+"|解析异常,用例步骤为空或是用例脚本错误!");
}finally{
return params;
return params;
}
return params;
}
private static String SubComment(String htmlStr) throws InterruptedException{
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
String regEx_space = "\t|\r|\n";//定义空格回车换行符
private static String subComment(String htmlStr) throws InterruptedException{
String regExScript = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
String regExStyle = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
String regExHtml = "<[^>]+>"; // 定义HTML标签的正则表达式
String regExSpace = "\t|\r|\n";//定义空格回车换行符
String scriptstr = null;
if (htmlStr!=null) {
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
Matcher mScript = pScript.matcher(htmlStr);
htmlStr = mScript.replaceAll(""); // 过滤script标签
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); // 过滤style标签
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
Matcher mStyle = pStyle.matcher(htmlStr);
htmlStr = mStyle.replaceAll(""); // 过滤style标签
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
Matcher mHtml = pHtml.matcher(htmlStr);
htmlStr = mHtml.replaceAll(""); // 过滤html标签
Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
Matcher mSpace = pSpace.matcher(htmlStr);
htmlStr = mSpace.replaceAll(""); // 过滤空格回车标签
}
if(htmlStr.indexOf("/*")>-1&&htmlStr.indexOf("*/")>-1){

View File

@ -2,6 +2,17 @@ package rmi.model;
import java.io.Serializable;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
//注意对象必须继承Serializable
public class RunBatchCaseEntity implements Serializable {
/**

View File

@ -2,6 +2,17 @@ package rmi.model;
import java.io.Serializable;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
//注意对象必须继承Serializable
public class RunCaseEntity implements Serializable {
/**

View File

@ -2,6 +2,17 @@ package rmi.model;
import java.io.Serializable;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
//注意对象必须继承Serializable
public class RunTaskEntity implements Serializable {
/**

View File

@ -4,9 +4,19 @@ import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import rmi.service.RunService;
import rmi.serviceImpl.RunServiceImpl;
import rmi.serviceimpl.RunServiceImpl;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
public class Program{
public static void main(String[] args) {

View File

@ -7,6 +7,17 @@ import rmi.model.RunBatchCaseEntity;
import rmi.model.RunCaseEntity;
import rmi.model.RunTaskEntity;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
//此为远程对象调用的接口必须继承Remote类
public interface RunService extends Remote {
public String runtask(RunTaskEntity task,String loadpath) throws RemoteException;

View File

@ -1,4 +1,4 @@
package rmi.serviceImpl;
package rmi.serviceimpl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@ -19,7 +19,17 @@ import rmi.model.RunTaskEntity;
import rmi.service.RunService;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
* 为了尊重作者的劳动成果LuckyFrame关键版权信息严禁篡改
* 有任何疑问欢迎联系作者讨论 QQ:1573584944 seagull1985
* =================================================================
*
* @author seagull
* @date 2017年12月1日 上午9:29:40
*
*/
//此为远程对象的实现类须继承UnicastRemoteObject
public class RunServiceImpl extends UnicastRemoteObject implements RunService{
@ -143,6 +153,7 @@ public class RunServiceImpl extends UnicastRemoteObject implements RunService{
* @param realName
* @throws Exception
*/
@Override
public String getlogdetail(String storeName) throws RemoteException{
BufferedReader bos = null;
String ctxPath = System.getProperty("user.dir")+"\\log\\";
@ -187,6 +198,7 @@ public class RunServiceImpl extends UnicastRemoteObject implements RunService{
* @param realName
* @throws Exception
*/
@Override
public byte[] getlogimg(String imgName) throws RemoteException{
String ctxPath = System.getProperty("user.dir")+"\\log\\ScreenShot\\";
String downLoadPath = ctxPath+imgName;
@ -218,6 +230,7 @@ public class RunServiceImpl extends UnicastRemoteObject implements RunService{
* @param realName
* @throws Exception
*/
@Override
public String uploadjar(byte[] fileContent,String name,String loadpath) throws RemoteException{
String path = System.getProperty("user.dir")+loadpath;
if (!new File(path) .isDirectory())
@ -249,6 +262,7 @@ public class RunServiceImpl extends UnicastRemoteObject implements RunService{
return "上传"+name+"至客户端成功!";
}
@Override
public String getClientStatus() throws RemoteException{
return "success";
}