Commit 43e00c99 authored by xiongjunyi's avatar xiongjunyi

[modify:1.修改检查语句设置多个语句时只能判断第一条语句的bug

        2.修改参数拼接时如果对象类型字段值为空,拼接成""的bug
        3.添加闪送部分用例
        4.用例执行步骤抽象到工具类中,后续修改只需要修改工具类就行
        5.优化期望值比较的bug,只根据本次接口的调用结果来比较,减少时间且更加准确]
parent b8222ea9
......@@ -135,28 +135,19 @@ public class ExcelUtil {
*/
public static String postdata(XSSFWorkbook sheets , String sheet_name , int type , String... nums){
XSSFSheet sheet = sheets.getSheet(sheet_name);
//定义各种拼接方式
int count = ExcelUtil.getcount(sheet);
XSSFRow header_row = sheet.getRow(0);
if(count !=1){//如果只有一列说明引用数据为空,不需要补数据
//StringJoiner object = new StringJoiner("," , "{" , "}");//一个对象由{开始,以}结束
//只有内部的引用数据会有多行,length会大于1
StringJoiner key_value = new StringJoiner(",","{","}");//用来拼接key_value和key_value的
for(int i = 0 ; i < nums.length ; i++){
XSSFRow data_row = sheet.getRow(Integer.parseInt(nums[i]));
if(ExcelUtil.IsRowEmpty(data_row)){
log.error("引用的数据行为空!请检查!");
throw new RuntimeException("引用的数据行为空!请检查!");
}
else{
for(int j = 1 ; j < count ; j++){//不要序号一列
//StringJoiner special_type_args = new StringJoiner("","","");//用来拼接"a": 和 true / 1 / ["c"] 等
StringJoiner delimiter = new StringJoiner(":","","");//字段分隔符,每个字段都需要new一个新的出来,否则会叠加
......@@ -164,7 +155,6 @@ public class ExcelUtil {
String header = header_row.getCell(j).toString();//每个字段单元格的内容
if(header.contains("(Object)") || header.contains("(Array)") || header.contains("(Integer)") || header.contains("(bool)") ||
header.contains("(ArrayList)")){
args.add(header.substring(0, header.lastIndexOf("(") ));//拼接变量名
//delimiter.add(args.toString());//拼接分隔符,拼接完是"aaa":的形式
}
......@@ -183,10 +173,8 @@ public class ExcelUtil {
//Array类型需要多拼接一个[
if(header.contains("(Array)")){
StringJoiner json_array = new StringJoiner("" ,"[" , "]");//数组类型
String reference_data = postdata(sheets, refrence_sheet_name, DataRefTypeEnum.Type_List.getTypeId(),refrence_nums.split(","));
json_array.add(reference_data);//按数组格式拼接,拼接完成后是["aaa":"xxx"]的形式
delimiter.add(args.toString()).add(json_array.toString());//将key和value 用: 拼接起来
key_value.add(delimiter.toString());
}
......@@ -213,7 +201,11 @@ public class ExcelUtil {
delimiter.add(args.toString()).add(value);
key_value.add(delimiter.toString());
}
}
else if (header.contains("(Object)")){
StringJoiner values = new StringJoiner("", "{", "}");
delimiter.add(args.toString()).add(values.add("").toString());
key_value.add(delimiter.toString());
}
else{
//普通value值
......@@ -234,19 +226,22 @@ public class ExcelUtil {
StringJoiner values = new StringJoiner("", "","");
delimiter.add(args.toString()).add(values.add("null").toString());
key_value.add(delimiter.toString());
}else {
}
if(header.contains("(Object)")){
StringJoiner values = new StringJoiner("", "{", "}");
delimiter.add(args.toString()).add(values.add("").toString());
key_value.add(delimiter.toString());
}
else {
StringJoiner values = new StringJoiner("","\"","\"");//变量值,普通字符串变量
//values.add(null);
delimiter.add(args.toString()).add(values.toString());
key_value.add(delimiter.toString());
}
}
}
//object.add(key_value.toString());//至此一个对象拼接完成
}
}
//内层拼接完了,开始拼接最外层
if(sheet_name.contains("(Array)")){
......@@ -257,8 +252,6 @@ public class ExcelUtil {
}
//System.out.println(key_value);
return key_value.toString();
}else {
throw new RuntimeException("没有引用数据!");
}
......
......@@ -52,10 +52,10 @@ public class JsonTransfer {
}
return false;
}
public static boolean AnalysisJson(String response, Map<String,String> map ){
public static Map<String,String> AnalysisJson(String response, Map<String,String> map ){
if(response.indexOf(":") == -1){
//value中没有:表示该json不需要继续解析了
return true;
return map;
}
JSONObject fromObject = JSONObject.fromObject(response);
Iterator it = fromObject.keys();
......@@ -86,7 +86,7 @@ public class JsonTransfer {
}
}
return false;
return map;
}
/***
......
......@@ -221,9 +221,7 @@ public class ParamsBuilt {
public static void main(String[] args) {
String regex = " ";
String origin = null;
boolean flag = origin.matches(regex);
System.out.println(flag);
String a = "1.0";
Integer.parseInt(a);
}
}
......@@ -46,7 +46,7 @@ public class TestCaseUtil {
TestCase ts = new TestCase();
//按照用例约定格式,依次给Testcase对象各属性赋值
ts.setNo(Integer.valueOf(eachrow.getCell(0).getRawValue() == null ? "0" : eachrow.getCell(0).toString() ));//设置用例组号
ts.setNo(Integer.parseInt(eachrow.getCell(0).getRawValue() == null ? "0" : eachrow.getCell(0).toString() ));//设置用例组号
ts.setTest_point(eachrow.getCell(1, Row.RETURN_NULL_AND_BLANK) == null ? "" : eachrow.getCell(1).toString());//设置测试点
ts.setStep_desc(eachrow.getCell(2, Row.RETURN_NULL_AND_BLANK) == null ? "" : eachrow.getCell(2).toString());//设置步骤描述
ts.setInterface_name(eachrow.getCell(3, Row.RETURN_NULL_AND_BLANK).toString());//设置url
......@@ -327,6 +327,7 @@ public class TestCaseUtil {
* @return 返回比对结果 一致返回true 不一致返回false
*/
public static boolean do_check_sql(String check_sql , Map<String,String> string_var_map , Map<String, Integer> int_var_map, Map<String,String> res_map,String databasename) throws Exception {
boolean check_flag = true;
if(!"".equals(check_sql)){
String[] subs = check_sql.split(";");
for(String each: subs){
......@@ -353,10 +354,9 @@ public class TestCaseUtil {
logger.info("检查语句查询到的结果为:" + entry.getValue().toString());
if(var.equals((entry.getValue().toString()))){
logger.info("检查结果:"+ var + "与查询结果比对通过" );
return true;
}else {
logger.error("检查结果:" + var + "与查询结果比对失败!");
return false;
check_flag = false;
}
}
......@@ -365,7 +365,7 @@ public class TestCaseUtil {
}
}
//检查语句为空,不需要检查,返回true
return true;
return check_flag;
}
......
package com.miya.manning.framework.util;
import com.miya.manning.test.flow.order.Express;
import com.miya.manning.vo.conditions.Condition;
import com.miya.manning.vo.scripts.Script;
import com.miya.manning.vo.testcase.TestCase;
import org.apache.log4j.Logger;
import org.testng.Assert;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class TestUtil {
static Logger logger = Logger.getLogger(TestUtil.class);
public static void doTest(TestCase testCase , Map<String,String> string_var_map, Map<String,Integer> int_var_map,
Map<String,String> res_map , List<Script> Scripts, List<Condition> Conditions,
String url_start) throws Exception{
Map<String,String> one_res_map = new HashMap<>();//用来保存每个用例执行的变量结果集本地副本
//前置语句最先执行
String pre_sql = testCase.getPre_sql();
String databasename = testCase.getDatabasename();
//1.处理前置语句,赋值给变量或者直接执行
TestCaseUtil.deal_pre_sql(pre_sql, string_var_map, int_var_map, res_map , databasename);
//检查是否有控制器,判断是否执行该用例
String condition_name = testCase.getCondition_name();
if(!condition_name.isEmpty()){
List<Condition> execConditionList = Conditions.stream().filter(x -> x.getCondition_name().equals(testCase.getCondition_name())).collect(Collectors.toList());
boolean flag = ToolUtil.ExecuteCondition(execConditionList, Scripts ,testCase ,string_var_map, int_var_map, res_map);
if(flag){
//控制器返回结果为true时,说明已经执行过用例了或者无需执行用例,这里就不用再执行一次
logger.info("取消当前组用例执行,用例名称:" + testCase.getStep_desc() );
return;
}
}
String script_name = testCase.getScript_name();
if(!script_name.isEmpty()){
List<Script> execScriptList = Scripts.stream().filter(x -> x.getScript_name().equals(testCase.getScript_name())).collect(Collectors.toList());
ToolUtil.ExecuteScript(execScriptList);
}
//用例执行部分
//2.设置请求头
Map<String, String> httpheadermap = new HashMap<>();
if("C".equals(testCase.getPlatform())){
httpheadermap = HttpHeaderBuilt.httpHeadBuiltManningsC(string_var_map,int_var_map);
}
if("B".equals(testCase.getPlatform())){
httpheadermap = HttpHeaderBuilt.httpHeadBuiltManningsB(res_map);
}
logger.info("以下是请求头信息:");
for(Map.Entry<String,String> entry: httpheadermap.entrySet()){
logger.info(entry.getKey() + ":" + entry.getValue());
}
//4.调用前替换params中可能存在的变量
String params = testCase.getParams();
logger.info("替换前的参数为:" + params);
String new_params = ParamsBuilt.params_replace(params, int_var_map, string_var_map ,res_map);
logger.info("替换后的参数为:" + new_params);
//5.拼接url,调用并获取接口返回
StringBuffer url = new StringBuffer(url_start);
StringBuilder builder = new StringBuilder();
url.append(testCase.getInterface_name());//先拼接一部分
String new_url = ParamsBuilt.params_replace(url.toString(), int_var_map, string_var_map, res_map);//替换url中可能存在的变量
StringBuffer new_url_bf = new StringBuffer(new_url);
RequestUtil.doRequest(testCase, new_params, new_url_bf, httpheadermap, logger, builder);
//6.收集响应信息,并按规则添加至map中
one_res_map = JsonTransfer.AnalysisJson(builder.toString(),one_res_map);
//7.执行检查语句,根据本次返回的接口内容来校验,和期望值相同
String check_sql = testCase.getCheck_sql();
Assert.assertEquals(TestCaseUtil.do_check_sql(check_sql,string_var_map,int_var_map,one_res_map,databasename), true);
//8.校验期望值,校验本次接口返回的内容,用one_res_map来校验
String expect = testCase.getExpect();
Assert.assertEquals(TestCaseUtil.check(expect, int_var_map,string_var_map,one_res_map) , true);
//本次请求变量添加到总的变量集中
res_map.putAll(one_res_map);
}
}
package com.miya.manning.test.flow.order;
import com.miya.manning.framework.util.TestCaseUtil;
import com.miya.manning.framework.util.TestUtil;
import com.miya.manning.vo.conditions.Condition;
import com.miya.manning.vo.scripts.Script;
import com.miya.manning.vo.testcase.TestCase;
import org.apache.log4j.Logger;
import org.testng.annotations.*;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @ProjectName: manning_test
* @Package: com.miya.manning.test.flow.order.Delivery
* @ClassName: Mainprocess
* @Description: 万宁物流模块测试
* @Author: 熊军奕
* @CreateDate: 2022/5/23 下午22:38
* @UpdateUser: 熊军奕
* @UpdateDate: 2022/5/23 下午22:38
*/
public class Delivery_process {
static Logger logger = Logger.getLogger(Delivery_process.class);
private String url_start = "https://cs2-uat.mannings.com.cn/";
private String script_path = System.getProperty("user.dir") + File.separator + "target" + File.separator + "classes"
+ File.separator + "testcase" + File.separator + "Scripts" + File.separator + "Script.xls";
private String condition_path = System.getProperty("user.dir") + File.separator + "target" + File.separator + "classes"
+ File.separator + "testcase" + File.separator + "Conditions" + File.separator + "Condition.xls";
private String path = System.getProperty("user.dir") + File.separator + "target" + File.separator + "classes" +
File.separator + "testcase" + File.separator + "Delivery_process.xls";
//private String path = "D:\\autotest\\test_liucheng\\test_liucheng\\huihua_saas1.xls";
private Map<String,String> res_map = new TreeMap<>();
private static Map<String,Integer> int_var_map = new HashMap<>();
private static Map<String,String> string_var_map = new HashMap<>();
private static List<Script> Scripts = null;
private static List<Condition> Conditions = null;
@DataProvider(name = "ex")
public Object[][] Parameter(){
/*return new Object[][]{
{1,10, "200", "null", null},//查询券列表
{2,10, "200", "null", null},//查询券列表第二页
//{ "200", "null", null},//
};*/
Object[][] testcases = null;
try {
Scripts = TestCaseUtil.GetScripts(script_path);
Conditions = TestCaseUtil.GetConditions(condition_path);
testcases = TestCaseUtil.GetMain(path);
} catch (RuntimeException e) {
logger.error("error:" , e );
}
return testcases;
}
@BeforeClass
public void setUp() {
logger.info("闪送订单主流程测试开始!");
}
@AfterClass
public void tearDown() {
logger.info("闪送订单主流程测试结束!");
for (Map.Entry<String, String> entry : res_map.entrySet())
logger.info(entry.getKey() + ":" + entry.getValue());
}
@BeforeMethod
public void before(){
}
@Test(dataProvider = "ex")
public void Delivery( TestCase testCase) throws Exception {
TestUtil.doTest(testCase,string_var_map,int_var_map,res_map,Scripts,Conditions,url_start);
/*if (code == "200") {
Response response = new Response(final_res.getString("code"), final_res.getString("msg"), final_res.getJSONObject("data"));
JSONObject final_res_data = (JSONObject) response.getData();
Assert.assertEquals(response.getCode(), code);
Assert.assertEquals(response.getMsg(), msg);
String manufacturer_id =PropertiesHandle.readValue(StringUtil.httpHeader, "manufacturerId");
List<CouponConfigPO> couponGetPagelist = CouponSql.couponGetPage(manufacturer_id,pageNum,pageSize);
for (int i = 0; i< couponGetPagelist.size(); i++) {
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("manufacturerId"),couponGetPagelist.get(i).getManufacturerId());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("picUrl"),couponGetPagelist.get(i).getPicUrl());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("couponScene"),couponGetPagelist.get(i).getCouponScene());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("couponName"),couponGetPagelist.get(i).getCouponName());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("couponRights"),couponGetPagelist.get(i).getCouponRights());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("couponType"),couponGetPagelist.get(i).getCouponType());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("couponBatch"),couponGetPagelist.get(i).getCouponBatch());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("instructions"),couponGetPagelist.get(i).getInstructions());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getString("state"),couponGetPagelist.get(i).getState());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getInt("costScore"),couponGetPagelist.get(i).getCostScore());
Assert.assertEquals(final_res_data.getJSONArray("list").getJSONObject(i).getInt("userDailyGetLimit"),couponGetPagelist.get(i).getUserDailyGetLimit());
}
} else {
Response response = new Response(final_res.getString("code"), final_res.getString("msg"), final_res.getString("data"));
Assert.assertEquals(response.getCode(), code);
Assert.assertEquals(response.getMsg(), msg);
Assert.assertEquals(response.getData(), data);
}*/
}
}
......@@ -28,10 +28,6 @@ import java.util.stream.Collectors;
public class Express {
static Logger logger = Logger.getLogger(Express.class);
/*private String baseUrl = PropertiesHandle.readValue(StringUtil.brandurl);
private String apiprefixUrl = StringUtil.brand_apiprefix;*/
//private String testUrl = "web-front/coupon/get-page";
//private String url_start = baseUrl + apiprefixUrl ;
private String url_start = "https://cs2-uat.mannings.com.cn/";
private String script_path = System.getProperty("user.dir") + File.separator + "target" + File.separator + "classes"
+ File.separator + "testcase" + File.separator + "Scripts" + File.separator + "Script.xls";
......@@ -69,13 +65,13 @@ public class Express {
@BeforeClass
public void setUp() {
logger.info("分页查询券接口测试开始1!");
logger.info("物流订单相关测试点测试开始!");
}
@AfterClass
public void tearDown() {
logger.info("分页查询券接口测试结束!");
logger.info("物流订单相关测试点测试结束!");
for (Map.Entry<String, String> entry : res_map.entrySet())
logger.info(entry.getKey() + ":" + entry.getValue());
}
......@@ -87,62 +83,8 @@ public class Express {
@Test(dataProvider = "ex")
public void Express( TestCase testCase) throws Exception {
//前置语句最先执行
String pre_sql = testCase.getPre_sql();
String databasename = testCase.getDatabasename();
//1.处理前置语句,赋值给变量或者直接执行
TestCaseUtil.deal_pre_sql(pre_sql, string_var_map, int_var_map, res_map , databasename);
//检查是否有控制器,判断是否执行该用例
String condition_name = testCase.getCondition_name();
if(!condition_name.isEmpty()){
List<Condition> execConditionList = Conditions.stream().filter(x -> x.getCondition_name().equals(testCase.getCondition_name())).collect(Collectors.toList());
boolean flag = ToolUtil.ExecuteCondition(execConditionList, Scripts ,testCase ,string_var_map, int_var_map, res_map);
if(flag){
//控制器返回结果为true时,说明已经执行过用例了或者无需执行用例,这里就不用再执行一次
logger.info("取消当前组用例执行,用例名称:" + testCase.getStep_desc() );
return;
}
}
String script_name = testCase.getScript_name();
if(!script_name.isEmpty()){
List<Script> execScriptList = Scripts.stream().filter(x -> x.getScript_name().equals(testCase.getScript_name())).collect(Collectors.toList());
ToolUtil.ExecuteScript(execScriptList);
}
//用例执行部分
//2.设置请求头
Map<String, String> httpheadermap = new HashMap<>();
if("C".equals(testCase.getPlatform())){
httpheadermap = HttpHeaderBuilt.httpHeadBuiltManningsC(string_var_map,int_var_map);
}
if("B".equals(testCase.getPlatform())){
httpheadermap = HttpHeaderBuilt.httpHeadBuiltManningsB(res_map);
}
TestUtil.doTest(testCase,string_var_map,int_var_map,res_map,Scripts,Conditions,url_start);
logger.info("以下是请求头信息:");
for(Map.Entry<String,String> entry: httpheadermap.entrySet()){
logger.info(entry.getKey() + ":" + entry.getValue());
}
//4.调用前替换params中可能存在的变量
String params = testCase.getParams();
logger.info("替换前的参数为:" + params);
String new_params = ParamsBuilt.params_replace(params, int_var_map, string_var_map ,res_map);
logger.info("替换后的参数为:" + new_params);
//5.拼接url,调用并获取接口返回
StringBuffer url = new StringBuffer(url_start);
StringBuilder builder = new StringBuilder();
url.append(testCase.getInterface_name());//先拼接一部分
String new_url = ParamsBuilt.params_replace(url.toString(), int_var_map, string_var_map, res_map);//替换url中可能存在的变量
StringBuffer new_url_bf = new StringBuffer(new_url);
RequestUtil.doRequest(testCase, new_params, new_url_bf, httpheadermap, logger, builder);
//6.收集响应信息,并按规则添加至map中
JsonTransfer.AnalysisJson(builder.toString(),res_map);
//7.执行检查语句,和期望值相同
String check_sql = testCase.getCheck_sql();
Assert.assertEquals(TestCaseUtil.do_check_sql(check_sql,string_var_map,int_var_map,res_map,databasename), true);
//8.校验期望值
String expect = testCase.getExpect();
Assert.assertEquals(TestCaseUtil.check(expect, int_var_map,string_var_map,res_map), true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment