Commit cf62b81b authored by xiongjunyi's avatar xiongjunyi

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

        2.修改参数拼接时如果对象类型字段值为空,拼接成""的bug
        3.添加闪送部分用例
        4.用例执行步骤抽象到工具类中,后续修改只需要修改工具类就行
        5.优化期望值比较的bug,只根据本次接口的调用结果来比较,减少时间且更加准确]
parent 5c3cc116
......@@ -64,6 +64,11 @@
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
......
......@@ -3,6 +3,7 @@ package com.miya.manning.framework.request;
import com.google.gson.JsonObject;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
......@@ -10,12 +11,16 @@ import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.testng.collections.CollectionUtils;
import java.io.*;
......@@ -36,6 +41,7 @@ import java.util.Map.Entry;
* @UpdateDate: 2019/1/21 下午5:39
*/
public class HTTPPost {
private static final Logger log = Logger.getLogger(HTTPPost.class);
public static String httpPost(String url, JSONObject jsonParam) throws ClientProtocolException, IOException {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
......@@ -277,6 +283,7 @@ public class HTTPPost {
Entry<String, String> elem = (Entry<String, String>) headerIterator.next();
httppost.addHeader(elem.getKey(), elem.getValue());
}
httppost.addHeader("ContentType" , "application/json");
StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");
entity.setContentEncoding("UTF-8");
......@@ -291,7 +298,55 @@ public class HTTPPost {
//System.out.print(result);
return result;
}
public static String httpuploadfile(String url, String file_path ,Map<String, String> httpHeaderMap) throws ClientProtocolException, IOException {
String result = null;
try{
File file = new File(file_path);
String filename = file.getName();
FileInputStream in = null;
InputStream is = null;
if(null != file){
try{
in = new FileInputStream(file);
}catch (FileNotFoundException e){
log.error(e);
}
is = in;
}
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
HttpPost httppost = new HttpPost(url);
//添加HTTPHeader
Iterator headerIterator = httpHeaderMap.entrySet().iterator(); //循环增加header
while (headerIterator.hasNext()) {
Entry<String, String> elem = (Entry<String, String>) headerIterator.next();
httppost.addHeader(elem.getKey(), elem.getValue());
}
httppost.addHeader("Content-Disposition","form_data; name=\"file\"; filename=\"" + filename + "\"");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", is , ContentType.MULTIPART_FORM_DATA , filename);
HttpEntity entity = builder.build();
httppost.setEntity(entity);
HttpResponse httpResponse;
httpResponse = closeableHttpClient.execute(httppost);
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity, "UTF-8");
closeableHttpClient.close();
//System.out.print(result);
if(null != is){
is.close();
}
if(null != in){
in.close();
}
if(null != closeableHttpClient){
closeableHttpClient.close();
}
}catch (Exception e){
log.error(e);
}
return result;
}
public static String httpPost(String url, JSONArray jsonParam, Map<String, String> httpHeaderMap) throws ClientProtocolException, IOException {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
......
......@@ -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("没有引用数据!");
}
......
......@@ -56,7 +56,7 @@ public class HttpHeaderBuilt {
public static Map<String,String> httpHeadBuiltManningsB(Map<String,String> res_map){
Map<String,String> httpheadermap = new HashMap<>();
httpheadermap.put("content-type","application/json");
//httpheadermap.put("content-type","application/json");
httpheadermap.put("authorization", res_map.containsKey("varg_data_0_token")? res_map.get("varg_data_0_token") : "");
httpheadermap.put("type", "unioncenter");
return httpheadermap;
......
......@@ -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);
}
}
......@@ -33,21 +33,30 @@ public class RequestUtil {
builder.append(result);
logger.info("收到的应答为:" + result);
}else if("post".equals(testCase.getMethod_type())){
logger.info(url.toString());
if(new_params.startsWith("[")){
JSONArray Req = JsonTransfer.ToJsonArray(new_params);
System.out.println(Req);
String result = HTTPPost.httpPost(url.toString(),Req,httpheadermap);
builder.append(result);
logger.info(result);
}
else if (new_params.startsWith("{")){
JSONObject Req = JsonTransfer.ToJsonObject(new_params);
System.out.println(Req);
String result = HTTPPost.httpPost(url.toString(),Req,httpheadermap);
if(testCase.isIs_uploadfile()){
//文件流
String result = HTTPPost.httpuploadfile(url.toString(), testCase.getPath(),httpheadermap);
builder.append(result);
logger.info(result);
}else {
//正常传参
logger.info(url.toString());
if(new_params.startsWith("[")){
JSONArray Req = JsonTransfer.ToJsonArray(new_params);
System.out.println(Req);
String result = HTTPPost.httpPost(url.toString(),Req,httpheadermap);
builder.append(result);
logger.info(result);
}
else if (new_params.startsWith("{")){
JSONObject Req = JsonTransfer.ToJsonObject(new_params);
System.out.println(Req);
String result = HTTPPost.httpPost(url.toString(),Req,httpheadermap);
builder.append(result);
logger.info(result);
}
}
}
else if("put".equals(testCase.getMethod_type())){
if(new_params != null ){
......
......@@ -46,12 +46,23 @@ 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
ts.setMethod_type(eachrow.getCell(4, Row.RETURN_NULL_AND_BLANK).toString());//设置方法类型
ts.setPath(eachrow.getCell(5, Row.RETURN_NULL_AND_BLANK).toString());//设置引用数据路径
XSSFCell cell = eachrow.getCell(5,Row.RETURN_NULL_AND_BLANK);
if(cell.getHyperlink() != null ){//如果是超链接
ts.setIs_uploadfile(true);
//获取文件名即可
String path_name = cell.getHyperlink().getAddress();
String file_name = path.substring(0,path.lastIndexOf("\\") + 1) + path_name;
ts.setPath(file_name);
}else{
ts.setIs_uploadfile(false);
ts.setPath(eachrow.getCell(5, Row.RETURN_NULL_AND_BLANK).toString());//设置引用数据路径
}
ts.setExpect(eachrow.getCell(6, Row.RETURN_NULL_AND_BLANK) == null ? "" : eachrow.getCell(6).toString());//设置期望结果
ts.setCheck_sql(eachrow.getCell(7, Row.RETURN_NULL_AND_BLANK) == null ? "" : eachrow.getCell(7).toString());//设置检查语句
ts.setPre_sql(eachrow.getCell(8, Row.RETURN_NULL_AND_BLANK) == null ? "" : eachrow.getCell(8).toString());//设置前置语句
......@@ -135,11 +146,11 @@ public class TestCaseUtil {
List<TestCase> excute_testCases = testCases.stream().filter(x->"Y".equals(x.getIs_excute())).collect(Collectors.toList());
List<Object[]> tss = new ArrayList<>();
for(TestCase testCase:excute_testCases){
if(!testCase.getPath().isEmpty()){
if(!testCase.getPath().isEmpty() && !testCase.isIs_uploadfile()){
String data_path = path.substring(0,path.lastIndexOf("\\")+1) + testCase.getPath().substring(0, testCase.getPath().lastIndexOf("|"));
String nums = testCase.getPath().substring(testCase.getPath().lastIndexOf("|")+1 );
XSSFWorkbook sheets = ExcelUtil.ExcelData(data_path);
if("get".equals(testCase.getMethod_type().toLowerCase())){
if("get".equalsIgnoreCase(testCase.getMethod_type())){
if(nums.split(",").length >1 ){
logger.error("get方法不能对应多组参数");
continue;
......@@ -147,7 +158,7 @@ public class TestCaseUtil {
String data = ExcelUtil.getdata(sheets);
testCase.setParams(data);
}
else if("post".equals(testCase.getMethod_type().toLowerCase())){
else if("post".equalsIgnoreCase(testCase.getMethod_type())){
String data = ExcelUtil.postdata(sheets, sheets.getSheetName(0), DataRefTypeEnum.Type_normal.getTypeId(), nums.split(","));
//System.out.println(data);
testCase.setParams(data);
......@@ -316,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){
......@@ -342,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;
}
}
......@@ -354,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,16 +28,13 @@ 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";
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 + "Express.xls";
private String path = System.getProperty("user.dir") + File.separator + "target" + File.separator + "classes" +
File.separator + "testcase" + File.separator + "Express.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<>();
......@@ -68,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());
}
......@@ -86,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);
......
......@@ -2,7 +2,7 @@ package com.miya.manning.vo.testcase;
public class TestCase {
//public static int Length = 5; //最多支持5组用例一起执行
private int no;//用例组号
private String test_point;//测试点
private String step_desc;//步骤描述
......@@ -18,6 +18,7 @@ public class TestCase {
private String databasename;//执行数据库名称,默认为空字符串
private String script_name;//脚本名称
private String condition_name;//控制器名称
private boolean is_uploadfile;//是否是用来上传文件的用例
public String getIs_excute() {
......@@ -142,6 +143,14 @@ public class TestCase {
this.condition_name = condition_name;
}
public boolean isIs_uploadfile() {
return is_uploadfile;
}
public void setIs_uploadfile(boolean is_uploadfile) {
this.is_uploadfile = is_uploadfile;
}
@Override
public String toString() {
return "TestCase{" +
......
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