Commit 0b638d56 by Li Yongyu

新增验收码等接口用例

parent b990f5fe
......@@ -6,7 +6,7 @@
<classes>
<class name="com.puhui.test.RenMai_APITest">
<methods>
<include name="f" invocation-numbers=""/>
<include name="f" invocation-numbers="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 "/>
</methods>
</class>
</classes>
......
......@@ -99,7 +99,7 @@ public class addAccount extends NWN implements API {
result = result && false;
failReason = failReason + "code is expected "
+ data.get("code").toString() + " but actually "
+ jp.getString("code") + ".";
+ jp.getString("retcode") + ".";
}
if ((data.get("msg") != null) && (msg != null) && (!msg.equals(data.get("msg").toString()))) {
......
......@@ -94,7 +94,7 @@ public class addChildTier extends NWN implements API {
+ data.get("statusCode").toString() + " but actually "
+ String.valueOf(re.getStatusCode()) + ". ";
}
if (json.length() != 0) {
String msg=jp.getString("message");
......@@ -106,7 +106,7 @@ public class addChildTier extends NWN implements API {
+ data.get("code").toString() + " but actually "
+ jp.getString("code") + ".";
}
if ((data.get("msg") != null) && (msg != null) && (!msg.equals(data.get("msg").toString()))) {
result = result && false;
failReason = failReason + "msg is expected "
......
......@@ -40,6 +40,8 @@ public class NWN extends BasicsGM{
public static List<String> n_admin_id_List = new ArrayList<String>();//n_admin的id
public static List<String> n_admin_phone_List = new ArrayList<String>();//n_admin的phone
public static List<String> n_admin_username_List = new ArrayList<String>();//n_admin的username
public static List<String> getcode_id_List = new ArrayList<String>();//getcode的id
public static List<String> n_getcode_id_List = new ArrayList<String>();//getcode的id
public static String level_id_List = "";//层级的id
public static List<String> user_id_List = new ArrayList<String>();//user_id
......@@ -127,6 +129,8 @@ public class NWN extends BasicsGM{
for(int i=0;i<n_package_idList.size();i++){
try {
deleteFromDB("n_package", "id", n_package_idList.get(i));
//deleteFromDB("n_packcode", "package_id", n_package_idList.get(i));
//deleteFromDB("n_packcode_record", "package_id", n_package_idList.get(i));
user_List.add(n_package_idList.get(i));
} catch (Exception e) {
e.printStackTrace();
......@@ -154,7 +158,23 @@ public class NWN extends BasicsGM{
user_id_List.removeAll(user_List);
// System.out.println(user_idList.toString());
}
//清除getcode_id_List
public void cleann_getcode_id_List_FromDB() {
List<String> user_List = new ArrayList<String>();
for(int i=0;i<getcode_id_List.size();i++){
try {
deleteFromDB("n_packcode", "package_id", getcode_id_List.get(i));
deleteFromDB("n_packcode_record", "package_id", getcode_id_List.get(i));
user_List.add(getcode_id_List.get(i));
} catch (Exception e) {
e.printStackTrace();
Log.logInfo("清除数据失败getcode_id_List");
}
}
getcode_id_List.removeAll(user_List);
// System.out.println(user_idList.toString());
}
//
//
......
package com.offcn.test;
import io.restassured.response.Response;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import com.offcn.TestData.offcn_api_testData;
import com.offcn.TestUnti.Log;
import com.offcn.TestUnti.Mail;
import com.offcn.TestUnti.MapUtil;
import com.offcn.TestUnti.OAuthTokenUnti;
import com.offcn.TestUnti.ReadProperties;
import com.offcn.TestUnti.Reflect_api;
import com.offcn.TestUnti.SheetUtils;
import com.offcn.TestUnti.StringUtils;
import com.offcn.TestUnti.XMLread;
import com.offcn.interfaces.API;
import com.offcn.listener.ProcessTestng;
import com.offcn.listener.ResultTestng;
import com.offcn.process.BasicsGM;
import com.offcn.process.NWN;
import com.offcn.process.TK;
import com.offcn.process.XYZB;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners({ ProcessTestng.class ,ResultTestng.class })
public class APITest_nwn extends NWN{
@Test(dataProvider = "renmai", dataProviderClass = offcn_api_testData.class)
public void f(HashMap<String, Object> data) {
Log.logInfo(data.get("TCNO").toString() + " Step " + data.get("Description").toString() + " is running......");
API obj = new Reflect_api().Reflections(data);
BasicsGM.map=new XMLread().getSystem();
obj.initialize(data);
data = obj.handleInput(data);
String parameter = MapUtil.getValue("parameter", data);
Long startTime=System.currentTimeMillis();
Response re = obj.SendRequest(data, data.get("serviceUrl").toString(), data.get("Request").toString());
Long endTime=System.currentTimeMillis();
String time=(endTime-startTime)+"毫秒";
String codeORerrcode="";
String msgORerrmsy="";
String result = "";
String body = "";
if(re!=null){
body=re.asString();
if(body.contains("<title>")){
int Alength="<title>".length();
int start=body.indexOf("<title>");
int end=body.indexOf("</title>")+1;
body="页面标题:"+body.substring(start+Alength, end-1);
result=body;
if(data.get("Description").toString().contains("流程")){
result = obj.handleOutput(re, data);
}
}else if(body.contains("<html>")){
body="返回html页面,状态码:"+re.getStatusCode();
if(data.get("Description").toString().contains("流程")){
result = obj.handleOutput(re, data);
}
}else{
result = obj.handleOutput(re, data);
}
codeORerrcode=getCode(re);
msgORerrmsy=getMsg(re);
}
Log.logInfo("返回结果="+StringUtils.decodeUnicode(body));
System.out.println();
//数据回写
//// HashMap<String, Object> ExpectResult=MapUtil.Expect(data);
// SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
// sheet.writeExcel(
// data.get("NO").toString(),
// data.get("TCNO").toString() + "_Step" + data.get("Step").toString(),
// data.get("Description").toString(),
// parameter,
//// JSONObject.fromObject(ExpectResult).toString(),
// re.getStatusCode()+"",
//// StringUtils.decodeUnicode(re==null?"":re.asString()),
// StringUtils.decodeUnicode(body),
// codeORerrcode,
// msgORerrmsy,
// result,
// time
// );
if(result.indexOf("Fail")!=-1){
String Expect1=data.get("code")==null?"":data.get("code").toString();
String Expect2=data.get("msg")==null?"":data.get("msg").toString();
String Expect3=data.get("custom")==null?"":data.get("custom").toString();
if(body.contains("HTML")){
body="异常页面信息";
}
Assert.assertEquals(StringUtils.decodeUnicode(body),Expect1+","+Expect2+","+Expect3);
}else{
Assert.assertTrue(true);
}
}
@AfterClass
public void afterClass() {
//测试结束删除测试所用的数据
if (!isClearMysql) {
this.cleann_n_admin_card_no_List_FromDB();
this.cleann_n_package_List_FromDB();
this.cleann_user_id_List_FromDB();
try {
if(stmt!=null){
stmt.close();
}
if (conn != null){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Log.logInfo("========测试结束========");
}
}
package com.offcn.test;
import io.restassured.response.Response;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import com.offcn.TestData.offcn_api_testData;
import com.offcn.TestUnti.Log;
import com.offcn.TestUnti.Mail;
import com.offcn.TestUnti.MapUtil;
import com.offcn.TestUnti.OAuthTokenUnti;
import com.offcn.TestUnti.ReadProperties;
import com.offcn.TestUnti.Reflect_api;
import com.offcn.TestUnti.SheetUtils;
import com.offcn.TestUnti.StringUtils;
import com.offcn.TestUnti.XMLread;
import com.offcn.interfaces.API;
import com.offcn.listener.ProcessTestng;
import com.offcn.listener.ResultTestng;
import com.offcn.process.BasicsGM;
import com.offcn.process.NWN;
import com.offcn.process.TK;
import com.offcn.process.XYZB;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners({ ProcessTestng.class ,ResultTestng.class })
public class APITest_nwn extends NWN{
@Test(dataProvider = "renmai", dataProviderClass = offcn_api_testData.class)
public void f(HashMap<String, Object> data) {
Log.logInfo(data.get("TCNO").toString() + " Step " + data.get("Description").toString() + " is running......");
API obj = new Reflect_api().Reflections(data);
BasicsGM.map=new XMLread().getSystem();
obj.initialize(data);
data = obj.handleInput(data);
String parameter = MapUtil.getValue("parameter", data);
Long startTime=System.currentTimeMillis();
Response re = obj.SendRequest(data, data.get("serviceUrl").toString(), data.get("Request").toString());
Long endTime=System.currentTimeMillis();
String time=(endTime-startTime)+"毫秒";
String codeORerrcode="";
String msgORerrmsy="";
String result = "";
String body = "";
if(re!=null){
body=re.asString();
if(body.contains("<title>")){
int Alength="<title>".length();
int start=body.indexOf("<title>");
int end=body.indexOf("</title>")+1;
body="页面标题:"+body.substring(start+Alength, end-1);
result=body;
if(data.get("Description").toString().contains("流程")){
result = obj.handleOutput(re, data);
}
}else if(body.contains("<html>")){
body="返回html页面,状态码:"+re.getStatusCode();
if(data.get("Description").toString().contains("流程")){
result = obj.handleOutput(re, data);
}
}else{
result = obj.handleOutput(re, data);
}
codeORerrcode=getCode(re);
msgORerrmsy=getMsg(re);
}
Log.logInfo("返回结果="+StringUtils.decodeUnicode(body));
System.out.println();
//数据回写
//// HashMap<String, Object> ExpectResult=MapUtil.Expect(data);
// SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
// sheet.writeExcel(
// data.get("NO").toString(),
// data.get("TCNO").toString() + "_Step" + data.get("Step").toString(),
// data.get("Description").toString(),
// parameter,
//// JSONObject.fromObject(ExpectResult).toString(),
// re.getStatusCode()+"",
//// StringUtils.decodeUnicode(re==null?"":re.asString()),
// StringUtils.decodeUnicode(body),
// codeORerrcode,
// msgORerrmsy,
// result,
// time
// );
if(result.indexOf("Fail")!=-1){
String Expect1=data.get("code")==null?"":data.get("code").toString();
String Expect2=data.get("msg")==null?"":data.get("msg").toString();
String Expect3=data.get("custom")==null?"":data.get("custom").toString();
if(body.contains("HTML")){
body="异常页面信息";
}
Assert.assertEquals(StringUtils.decodeUnicode(body),Expect1+","+Expect2+","+Expect3);
}else{
Assert.assertTrue(true);
}
}
@AfterClass
public void afterClass() {
//测试结束删除测试所用的数据
if (!isClearMysql) {
this.cleann_n_admin_card_no_List_FromDB();
this.cleann_n_package_List_FromDB();
this.cleann_user_id_List_FromDB();
this.cleann_getcode_id_List_FromDB();
try {
if(stmt!=null){
stmt.close();
}
if (conn != null){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Log.logInfo("========测试结束========");
}
}
......@@ -91,7 +91,7 @@ public class MakeTestCases {
//数据回写
SheetUtils sheet = new SheetUtils(wenjianming,Sheet);
sheet.writeExcel(
// s,
(i+1)+"",
leiming + "_" + (i+1),
(i+1)+"",
......
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