Commit 68fd7c6c by yangfangfang

物品

parent 2c494198
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="物品场景case"> <!-- 起一个好听且唯一的名字-->
<test name="物品设置模块测试" preserve-order="true" verbose="3"> <!-- 再起一个听且唯一的名字 -->
<packages>
<package name="com.xiaomai.cases.polar.goods.*"></package> <!-- 添加自己想要集成测试的case 范围自己定 -->
</packages>
</test>
<listeners>
<listener class-name="com.xiaomai.client.RetryListener" />
<listener class-name="com.xiaomai.client.TestListener" />
<listener class-name="com.xiaomai.client.ExtentTestNGIReporterListener"/>
</listeners>
</suite>
\ No newline at end of file
package com.xiaomai.cases.lunar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
public class GoodCTools extends XMBaseTest {
/**
* @param
* @description:C端获取物品列表
* @author: yff
**/
public JSONObject pageXcxHomeGoods_C(DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_pageXcxHomeGoods_C")
.setTerminal(Terminal.C);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("current", 0);
jsonObject.put("size", 20);
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
JSONArray jsonArray=new JSONArray();
jsonObject.put("ids",jsonArray);
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取C端的物品详情
* @param id:物品ID
* @author: yff
**/
public JSONObject getDetail_goods_C(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_getDetail_goods_C")
.setTerminal(Terminal.C);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
}
package com.xiaomai.cases.polar.finance.cashier;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.member.Tools;
import com.xiaomai.cases.polar.memberCard.CardTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.BigDecimal;
public class TestOfflinePay extends XMBaseTest {
String memberId;
String cardId;
String getDetailId;
Tools tools=new Tools();
OrderTools orderTools=new OrderTools();
CardTools cardTools=new CardTools();
@BeforeMethod
public void beforeTest(){
xmAppApi.setApiModule(ApiModule.Polar_Finance)
.setApiName("API_offlinePay")
.setLoginUser(LoginAccount.YFF_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "线下支付订单(实际是操作关联流水调用)")
public void testOfflinePay(){
//10020060066--固定流水,换场馆需要按照这个手机支付0.01元 "flowIds": ["1808757176611880962"]
String name = "创建订单潜在会员"+ RandomStringUtil.randomString(3);
String phone = RandomStringUtil.randomMobile("666");
//获取会员ID,没有则新建一个
int memberTotal = Integer.parseInt(tools.search("NORMAL","NORMAL").getJSONObject("result").getString("total"));
if (memberTotal == 0) {
memberId = tools.create(name,phone).getString("result");
}
memberId=tools.search("NORMAL","NORMAL").getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("id");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取会员卡信息
//获取会员卡列表,没有则新建一个
int cardTotal = Integer.parseInt(orderTools.fetchPageOfMemberCard("次卡","MEMBER_CARD").getJSONObject("result").getString("total"));
if (cardTotal == 0) {
cardId = cardTools.memberCardCreate("次卡-创建订单会员卡"+ TimeUtils.getCurrentTime()).getString("result");
}
JSONObject memberCard=orderTools.fetchPageOfMemberCard("次卡","MEMBER_CARD");
cardId=memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("id");
BigDecimal quantity= new BigDecimal(memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("balance"));
float price= Float.parseFloat(memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("price"));
int validPeriod= Integer.parseInt(memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("validPeriod"));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取签单要用的卡快照id
String latestSnapshotId=orderTools.fetchDetailById(cardId,xmAppApi.getLoginInfo().getBrandId(),xmAppApi.getLoginInfo().getStudioId(),xmAppApi.getLoginInfo().getAdminId()).getJSONObject("result").getString("latestSnapshotId");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//检查会员对该卡是否超出购买上限
boolean limitResult=orderTools.checkAllowPurchase("MEMBER_CARD",cardId,memberId,"1",xmAppApi.getLoginInfo().getBrandId(),xmAppApi.getLoginInfo().getStudioId(),xmAppApi.getLoginInfo().getAdminId()).getBoolean("success");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if(limitResult == true) {
//创建待支付订单
JSONObject orderResult = orderTools.signOrder(cardId, latestSnapshotId, quantity, price, validPeriod, latestSnapshotId, price / 2, "PURCHASE",
"MEMBER_CARD", memberId, price - price / 2, 0, "6");
getDetailId = orderResult.getString("result");//订单ID
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//关联流水
JSONObject jsonObject=new JSONObject();
JSONArray flowIds=new JSONArray();
flowIds.add("1808757176611880962");
jsonObject.put("flowIds",flowIds);
jsonObject.put("voucherId",getDetailId);
jsonObject.put("brandId",xmAppApi.getLoginInfo().getBrandId());
jsonObject.put("studioId",xmAppApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON,params,jsonObject.toJSONString(),headers).assetsSuccess(true);
String result=xmAppApi.getBodyInJSON().getString("result");
Assert.assertEquals(result,"true","关联流水失败");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验关联流水之后,订单状态变成已完成
//获取订单详情
//校验获取订单详情
JSONObject getDetailResult=orderTools.getDetail(getDetailId);
String state=getDetailResult.getJSONObject("result").getString("state");
Assert.assertEquals(state,"PAID","关联流水成功,但订单状态未是已完成");
//关联之后一定要把签单订单作废!!否则下次流水就不能关联了
//校验是否可以作废签单订单
boolean checkDiscardSignVoucherResult = orderTools.checkDiscardVoucher(getDetailId).getBoolean("success");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (checkDiscardSignVoucherResult == true) {
JSONObject discardResult = orderTools.discard(getDetailId, "重复录入", "已作废签单订单" + RandomStringUtil.randomString(10));
Assert.assertEquals(discardResult.getString("success"), "true", "签单订单作废失败");
}
}
}
}
package com.xiaomai.cases.polar.goods.Tools;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.XMBaseTest;
public class GoodTools extends XMBaseTest {
/**
* @param
* @description:新建物品
* @param multiSpec:是否是多规格;true:多规格;false:单规格
* @author: yff
**/
public JSONObject testCreateGoods(boolean multiSpec,DataUserInfo...userInfos) {
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
String color1 = "黑色";
String color2 = "白色";
String size1 = "大的";
String size2 = "小的";
String skin1 = "貂蝉";
String skin2 = "王昭君";
JSONObject jsonObject = new JSONObject();
//多规格
if (multiSpec==true) {
//商品介绍不为空,纯文本的写法
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的多规格三个规格,每个规格都有两个规格值");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1869984687228407810");
jsonObject.put("multiSpec", true);
jsonObject.put("name", "自动化创建三个规格" + RandomStringUtil.randomString(2));
jsonObject.put("xcxSaleState", "YES");
JSONObject multiSpecInfo = new JSONObject();
//设置三个规格和每个都有两个规格值
JSONArray specList = new JSONArray();
JSONObject specList1 = new JSONObject();
specList1.put("name", "颜色");
JSONArray specList1SpecValues = new JSONArray();
JSONObject specList1SpecValues1 = new JSONObject();
specList1SpecValues1.put("name", color1);
JSONObject specList1SpecValues2 = new JSONObject();
specList1SpecValues2.put("name", color2);
specList1SpecValues.add(specList1SpecValues1);
specList1SpecValues.add(specList1SpecValues2);
specList1.put("specValues", specList1SpecValues);
JSONObject specList2 = new JSONObject();
specList2.put("name", "尺码");
JSONArray specList2SpecValues = new JSONArray();
JSONObject specList2SpecValues1 = new JSONObject();
specList2SpecValues1.put("name", size1);
JSONObject specList2SpecValues2 = new JSONObject();
specList2SpecValues2.put("name", size2);
specList2SpecValues.add(specList2SpecValues1);
specList2SpecValues.add(specList2SpecValues2);
specList2.put("specValues", specList2SpecValues);
JSONObject specList3 = new JSONObject();
specList3.put("name", "限定皮肤");
JSONArray specList3SpecValues = new JSONArray();
JSONObject specList3SpecValues1 = new JSONObject();
specList3SpecValues1.put("name", skin1);
JSONObject specList3SpecValues2 = new JSONObject();
specList3SpecValues2.put("name", skin2);
specList3SpecValues.add(specList3SpecValues1);
specList3SpecValues.add(specList3SpecValues2);
specList3.put("specValues", specList3SpecValues);
specList.add(specList1);
specList.add(specList2);
specList.add(specList3);
multiSpecInfo.put("specList", specList);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//排列出来的组合2*2*2
JSONArray specCombinationList = new JSONArray();
JSONObject specCombinationList1 = new JSONObject();
JSONArray specCombinationList1Specs = new JSONArray();
specCombinationList1Specs.add(color1);
specCombinationList1Specs.add(size1);
specCombinationList1Specs.add(skin1);
specCombinationList1.put("specs", specCombinationList1Specs);
specCombinationList1.put("price", "0.01");
specCombinationList1.put("inventory", 10);
specCombinationList.add(specCombinationList1);
JSONObject specCombinationList2 = new JSONObject();
JSONArray specCombinationList2Specs = new JSONArray();
specCombinationList2Specs.add(color1);
specCombinationList2Specs.add(size1);
specCombinationList2Specs.add(skin2);
specCombinationList2.put("specs", specCombinationList2Specs);
specCombinationList2.put("price", "0.01");
specCombinationList2.put("inventory", 10);
specCombinationList.add(specCombinationList2);
JSONObject specCombinationList3 = new JSONObject();
JSONArray specCombinationList3Specs = new JSONArray();
specCombinationList3Specs.add(color1);
specCombinationList3Specs.add(size2);
specCombinationList3Specs.add(skin1);
specCombinationList3.put("specs", specCombinationList3Specs);
specCombinationList3.put("price", "0.01");
specCombinationList3.put("inventory", 10);
specCombinationList.add(specCombinationList3);
JSONObject specCombinationList4 = new JSONObject();
JSONArray specCombinationList4Specs = new JSONArray();
specCombinationList4Specs.add(color1);
specCombinationList4Specs.add(size2);
specCombinationList4Specs.add(skin2);
specCombinationList4.put("specs", specCombinationList4Specs);
specCombinationList4.put("price", "0.01");
specCombinationList4.put("inventory", 10);
specCombinationList.add(specCombinationList4);
JSONObject specCombinationList5 = new JSONObject();
JSONArray specCombinationList5Specs = new JSONArray();
specCombinationList5Specs.add(color2);
specCombinationList5Specs.add(size1);
specCombinationList5Specs.add(skin1);
specCombinationList5.put("specs", specCombinationList5Specs);
specCombinationList5.put("price", "0.01");
specCombinationList5.put("inventory", 10);
specCombinationList.add(specCombinationList5);
JSONObject specCombinationList6 = new JSONObject();
JSONArray specCombinationList6Specs = new JSONArray();
specCombinationList6Specs.add(color2);
specCombinationList6Specs.add(size1);
specCombinationList6Specs.add(skin2);
specCombinationList6.put("specs", specCombinationList6Specs);
specCombinationList6.put("price", "0.01");
specCombinationList6.put("inventory", 10);
specCombinationList.add(specCombinationList6);
JSONObject specCombinationList7 = new JSONObject();
JSONArray specCombinationList7Specs = new JSONArray();
specCombinationList7Specs.add(color2);
specCombinationList7Specs.add(size2);
specCombinationList7Specs.add(skin1);
specCombinationList7.put("specs", specCombinationList7Specs);
specCombinationList7.put("price", "0.01");
specCombinationList7.put("inventory", 10);
specCombinationList.add(specCombinationList7);
JSONObject specCombinationList8 = new JSONObject();
JSONArray specCombinationList8Specs = new JSONArray();
specCombinationList8Specs.add(color2);
specCombinationList8Specs.add(size2);
specCombinationList8Specs.add(skin2);
specCombinationList8.put("specs", specCombinationList8Specs);
specCombinationList8.put("price", "0.01");
specCombinationList8.put("inventory", 10);
specCombinationList.add(specCombinationList8);
multiSpecInfo.put("specCombinationList", specCombinationList);
jsonObject.put("multiSpecInfo", multiSpecInfo);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
}
//单规格
else if (multiSpec==false){
//商品介绍不为空,纯文本的写法
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1869984687228407810");
jsonObject.put("multiSpec", false);
jsonObject.put("name", "自动化创建单规格" + RandomStringUtil.randomString(2));
jsonObject.put("xcxSaleState", "YES");
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("inventory", "10");
jsonObject2.put("price", "0.01");
jsonObject.put("singleSpecInfo", jsonObject2);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
}
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取物品列表
* @author: yff
**/
public JSONObject studioGoods( DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_pageStudioGoods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("current", 0);
jsonObject.put("size", 20);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:删除物品
* @author: yff
**/
public JSONObject deleteGoods(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_delete")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建物品的重名校验
* @param name:物品名称
* @author: yff
**/
public JSONObject checkRepeatNameForStudio(String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_checkRepeatNameForStudio")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
jsonObject.put("id","");
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取B端的物品详情
* @param id:物品ID
* @author: yff
**/
public JSONObject getDetail_goods(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_getDetail_goods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取多规格物品的库存详情;注意仅多规格,单规格没有这个接口
* @param id:物品ID
* @author: yff
**/
public JSONObject listMultiSpecInventorRecords(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listMultiSpecInventorRecords")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建分組
* @param name:分組名称
* @author: yff
**/
public JSONObject createGoodsGroup(String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",name);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取分组列表
* @author: yff
**/
public JSONObject listPageGoodsGroup( DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listPageGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:分组重名校验
* @author: yff
**/
public JSONObject checkNameRepeatGoodsGroup(String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_checkNameRepeatGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",name);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:删除分组
* @param id:分组ID
* @author: yff
**/
public JSONObject deleteGoodsGroup(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_deleteGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:删除分组前是否存在物品的校验
* @param id:分组ID
* @author: yff
**/
public JSONObject checkAllowDelete(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_checkAllowDelete")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:编辑分组
* @param id:分组ID
* @param name:修改后的分组名称
* @author: yff
**/
public JSONObject modifyGoodsGroup(String id,String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_modifyGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("name",name);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建物品时拉取物品分组
* @author: yff
**/
public JSONObject listGoodsGroup(DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:批量修改物品的分组
* @param groupId:分组ID
* @param id:物品ID
* @author: yff
**/
public JSONObject batchModifyGoodsBelongGroup(String groupId,String id,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_batchModifyGoodsBelongGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("groupId",groupId);
JSONArray ids=new JSONArray();
ids.add(id);
jsonObject.put("ids",ids);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.lunar.goods.GoodCTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class createGoods extends XMBaseTest {
GoodTools goodTools=new GoodTools();
GoodCTools goodCTools=new GoodCTools();
String studioResult1;
String studioResult2;
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoods")
.setLoginUser(LoginAccount.YFF_RC)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "创建物品-多规格")
public void testCreateGoods() {
//分组是存量的,因为只能创建10个,超了的话还是要用存量的
//获取物品列表
JSONObject beforeTotalStudioGoods= goodTools.studioGoods();
int beforeTotal=Integer.parseInt(beforeTotalStudioGoods.getJSONObject("result").getString("total"));
//
// //切换端位
// DataUserInfo info = new DataUserInfo();
// info.setTerminal(Terminal.C);
// info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// JSONObject beforePageXcxHomeGoods_C = goodCTools.pageXcxHomeGoods_C(info);
// int beforeTotal_C = Integer.parseInt(beforePageXcxHomeGoods_C.getJSONObject("result").getString("total"));
String name="自动化创建三个规格" + RandomStringUtil.randomString(2);
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio=Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name).getString("result"));
if(checkRepeatNameForStudio==false) {
String color1 = "黑色";
String color2 = "白色";
String size1 = "大的";
String size2 = "小的";
String skin1 = "貂蝉";
String skin2 = "王昭君";
JSONObject jsonObject = new JSONObject();
//商品介绍为空
// JSONObject description=new JSONObject();
// jsonObject.put("description",description.toString());
//商品介绍不为空,纯文本
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的多规格三个规格,每个规格都有两个规格值");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1869984687228407810");
jsonObject.put("multiSpec", true);
jsonObject.put("name", name);
jsonObject.put("xcxSaleState", "YES");
JSONObject multiSpecInfo = new JSONObject();
//设置三个规格和每个都有两个规格值
JSONArray specList = new JSONArray();
JSONObject specList1 = new JSONObject();
specList1.put("name", "颜色");
JSONArray specList1SpecValues = new JSONArray();
JSONObject specList1SpecValues1 = new JSONObject();
specList1SpecValues1.put("name", color1);
JSONObject specList1SpecValues2 = new JSONObject();
specList1SpecValues2.put("name", color2);
specList1SpecValues.add(specList1SpecValues1);
specList1SpecValues.add(specList1SpecValues2);
specList1.put("specValues", specList1SpecValues);
JSONObject specList2 = new JSONObject();
specList2.put("name", "尺码");
JSONArray specList2SpecValues = new JSONArray();
JSONObject specList2SpecValues1 = new JSONObject();
specList2SpecValues1.put("name", size1);
JSONObject specList2SpecValues2 = new JSONObject();
specList2SpecValues2.put("name", size2);
specList2SpecValues.add(specList2SpecValues1);
specList2SpecValues.add(specList2SpecValues2);
specList2.put("specValues", specList2SpecValues);
JSONObject specList3 = new JSONObject();
specList3.put("name", "限定皮肤");
JSONArray specList3SpecValues = new JSONArray();
JSONObject specList3SpecValues1 = new JSONObject();
specList3SpecValues1.put("name", skin1);
JSONObject specList3SpecValues2 = new JSONObject();
specList3SpecValues2.put("name", skin2);
specList3SpecValues.add(specList3SpecValues1);
specList3SpecValues.add(specList3SpecValues2);
specList3.put("specValues", specList3SpecValues);
specList.add(specList1);
specList.add(specList2);
specList.add(specList3);
multiSpecInfo.put("specList", specList);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//排列出来的组合2*2*2
JSONArray specCombinationList = new JSONArray();
JSONObject specCombinationList1 = new JSONObject();
JSONArray specCombinationList1Specs = new JSONArray();
specCombinationList1Specs.add(color1);
specCombinationList1Specs.add(size1);
specCombinationList1Specs.add(skin1);
specCombinationList1.put("specs", specCombinationList1Specs);
specCombinationList1.put("price", "0.01");
specCombinationList1.put("inventory", 10);
specCombinationList.add(specCombinationList1);
JSONObject specCombinationList2 = new JSONObject();
JSONArray specCombinationList2Specs = new JSONArray();
specCombinationList2Specs.add(color1);
specCombinationList2Specs.add(size1);
specCombinationList2Specs.add(skin2);
specCombinationList2.put("specs", specCombinationList2Specs);
specCombinationList2.put("price", "0.01");
specCombinationList2.put("inventory", 10);
specCombinationList.add(specCombinationList2);
JSONObject specCombinationList3 = new JSONObject();
JSONArray specCombinationList3Specs = new JSONArray();
specCombinationList3Specs.add(color1);
specCombinationList3Specs.add(size2);
specCombinationList3Specs.add(skin1);
specCombinationList3.put("specs", specCombinationList3Specs);
specCombinationList3.put("price", "0.01");
specCombinationList3.put("inventory", 10);
specCombinationList.add(specCombinationList3);
JSONObject specCombinationList4 = new JSONObject();
JSONArray specCombinationList4Specs = new JSONArray();
specCombinationList4Specs.add(color1);
specCombinationList4Specs.add(size2);
specCombinationList4Specs.add(skin2);
specCombinationList4.put("specs", specCombinationList4Specs);
specCombinationList4.put("price", "0.01");
specCombinationList4.put("inventory", 10);
specCombinationList.add(specCombinationList4);
JSONObject specCombinationList5 = new JSONObject();
JSONArray specCombinationList5Specs = new JSONArray();
specCombinationList5Specs.add(color2);
specCombinationList5Specs.add(size1);
specCombinationList5Specs.add(skin1);
specCombinationList5.put("specs", specCombinationList5Specs);
specCombinationList5.put("price", "0.01");
specCombinationList5.put("inventory", 10);
specCombinationList.add(specCombinationList5);
JSONObject specCombinationList6 = new JSONObject();
JSONArray specCombinationList6Specs = new JSONArray();
specCombinationList6Specs.add(color2);
specCombinationList6Specs.add(size1);
specCombinationList6Specs.add(skin2);
specCombinationList6.put("specs", specCombinationList6Specs);
specCombinationList6.put("price", "0.01");
specCombinationList6.put("inventory", 10);
specCombinationList.add(specCombinationList6);
JSONObject specCombinationList7 = new JSONObject();
JSONArray specCombinationList7Specs = new JSONArray();
specCombinationList7Specs.add(color2);
specCombinationList7Specs.add(size2);
specCombinationList7Specs.add(skin1);
specCombinationList7.put("specs", specCombinationList7Specs);
specCombinationList7.put("price", "0.01");
specCombinationList7.put("inventory", 10);
specCombinationList.add(specCombinationList7);
JSONObject specCombinationList8 = new JSONObject();
JSONArray specCombinationList8Specs = new JSONArray();
specCombinationList8Specs.add(color2);
specCombinationList8Specs.add(size2);
specCombinationList8Specs.add(skin2);
specCombinationList8.put("specs", specCombinationList8Specs);
specCombinationList8.put("price", "0.01");
specCombinationList8.put("inventory", 10);
specCombinationList.add(specCombinationList8);
multiSpecInfo.put("specCombinationList", specCombinationList);
jsonObject.put("multiSpecInfo", multiSpecInfo);
jsonObject.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
JSONObject response = xmAppApi.getBodyInJSON();
studioResult1 = response.getString("result");
//校验:
//校验1:获取B端物品列表
//①统计值增加1
//②有对应的商品id
JSONObject afterStudioGoods = goodTools.studioGoods();
int afterTotal = Integer.parseInt(afterStudioGoods.getJSONObject("result").getString("total"));
JSONArray records = afterStudioGoods.getJSONObject("result").getJSONArray("records");
boolean success=false;
for (int i = 0; i < records.size(); i++) {
if (records.getJSONObject(i).getString("id").equals(studioResult1)) {
success=true;
}
Assert.assertEquals(success, true, "新建三个规格的物品成功,但物品列表未找到对应增加的物品ID");
}
Assert.assertEquals(afterTotal, beforeTotal + 1, "新建三个规格的物品成功,但物品列表的统计值未增加");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// //校验:
// //校验2:获取C端物品列表
// //①统计值增加1
// //②有对应的商品id
// JSONObject afterPageXcxHomeGoods_C = goodCTools.pageXcxHomeGoods_C(info);
// int afterTotal_C = Integer.parseInt(afterPageXcxHomeGoods_C.getJSONObject("result").getString("total"));
// JSONArray records_C = afterPageXcxHomeGoods_C.getJSONObject("result").getJSONArray("records");
//
// boolean success_C=false;
// for (int i = 0; i < records_C.size(); i++) {
// if (records_C.getJSONObject(i).getString("id").equals(studioResult1)) {
// success_C=true;
// }
// Assert.assertEquals(success_C, true, "新建三个规格的物品成功,但C端的物品列表未找到对应增加的物品ID");
// }
// Assert.assertEquals(afterTotal_C, beforeTotal_C + 1, "新建三个规格的物品成功,但C端物品列表的统计值未增加");
//校验3:获取B端物品详情,状态是开启,小程序售卖也是开启
JSONObject getDetail_goods=goodTools.getDetail_goods(studioResult1);
String state=getDetail_goods.getJSONObject("result").getString("state");
String xcxSaleState=getDetail_goods.getJSONObject("result").getString("xcxSaleState");
//规格1ID
String getDetailSpecListId1=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specList").getJSONObject(0).getString("id");
//规格2ID
String getDetailSpecListId2=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specList").getJSONObject(1).getString("id");
//规格3ID
String getDetailSpecListId3=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specList").getJSONObject(2).getString("id");
Assert.assertEquals(state,"YES","新建物品是启用,但物品详情展示非启用");
Assert.assertEquals(xcxSaleState,"YES","新建物品是开启小程序售卖,但物品详情展示非开启小程序售卖");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//
// //校验4:获取C端物品详情,状态是开启,小程序售卖也是开启
// JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(studioResult1,info);
// String state_C=getDetail_goods_C.getJSONObject("result").getString("state");
// String xcxSaleState_C=getDetail_goods_C.getJSONObject("result").getString("xcxSaleState");
// Assert.assertEquals(state_C,"YES","新建物品是启用,但C端物品详情展示非启用");
// Assert.assertEquals(xcxSaleState_C,"YES","新建物品是开启小程序售卖,但C端物品详情展示非开启小程序售卖");
//校验5:获取B端查看多规格的库存详情,和物品详情的规格id都一致
JSONObject listMultiSpecInventorRecords=goodTools.listMultiSpecInventorRecords(studioResult1);
//规格1ID
String listMultiSpecInventorRecordsSpecListId1=listMultiSpecInventorRecords.getJSONObject("result").getJSONArray("specList").getJSONObject(0).getString("id");
//规格2ID
String listMultiSpecInventorRecordsSpecListId2=listMultiSpecInventorRecords.getJSONObject("result").getJSONArray("specList").getJSONObject(1).getString("id");
//规格3ID
String listMultiSpecInventorRecordsSpecListId3=listMultiSpecInventorRecords.getJSONObject("result").getJSONArray("specList").getJSONObject(2).getString("id");
Assert.assertTrue(listMultiSpecInventorRecordsSpecListId1.equals(getDetailSpecListId1),"新建物品的库存详情的规格1的规格ID和物品详情的规格1的规格ID不一致");
Assert.assertTrue(listMultiSpecInventorRecordsSpecListId2.equals(getDetailSpecListId2),"新建物品的库存详情的规格2的规格ID和物品详情的规格2的规格ID不一致");
Assert.assertTrue(listMultiSpecInventorRecordsSpecListId3.equals(getDetailSpecListId3),"新建物品的库存详情的规格3的规格ID和物品详情的规格3的规格ID不一致");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
@Test(description = "创建物品-单规格")
public void testCreateGoods_1() {
//获取物品列表
JSONObject beforeTotalStudioGoods= goodTools.studioGoods();
int beforeTotal=Integer.parseInt(beforeTotalStudioGoods.getJSONObject("result").getString("total"));
// //切换端位
// DataUserInfo info = new DataUserInfo();
// info.setTerminal(Terminal.C);
// info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// JSONObject beforePageXcxHomeGoods_C = goodCTools.pageXcxHomeGoods_C(info);
// int beforeTotal_C = Integer.parseInt(beforePageXcxHomeGoods_C.getJSONObject("result").getString("total"));
String name = "自动化创建单规格" + RandomStringUtil.randomString(2);
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio = Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name).getString("result"));
if (checkRepeatNameForStudio == false) {
//单规格
JSONObject jsonObject = new JSONObject();
//商品介绍不为空,纯文本
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1869984687228407810");
jsonObject.put("multiSpec", false);
jsonObject.put("name", "自动化创建单规格" + RandomStringUtil.randomString(2));
jsonObject.put("xcxSaleState", "YES");
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("inventory", "10");
jsonObject2.put("price", "0.01");
jsonObject.put("singleSpecInfo", jsonObject2);
jsonObject.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
JSONObject response = xmAppApi.getBodyInJSON();
studioResult2=response.getString("result");
//校验:
//校验1:获取B端物品列表
//①统计值增加1
//②有对应的商品id
JSONObject afterStudioGoods = goodTools.studioGoods();
int afterTotal = Integer.parseInt(afterStudioGoods.getJSONObject("result").getString("total"));
JSONArray records = afterStudioGoods.getJSONObject("result").getJSONArray("records");
boolean success=false;
for (int i = 0; i < records.size(); i++) {
if (records.getJSONObject(i).getString("id").equals(studioResult2)) {
success=true;
}
Assert.assertEquals(success, true, "新建三个规格的物品成功,但物品列表未找到对应增加的物品ID");
}
Assert.assertEquals(afterTotal, beforeTotal + 1, "新建三个规格的物品成功,但物品列表的统计值未增加");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// //校验:
// //校验2:获取C端物品列表
// //①统计值增加1
// //②有对应的商品id
// JSONObject afterPageXcxHomeGoods_C = goodCTools.pageXcxHomeGoods_C(info);
// int afterTotal_C = Integer.parseInt(afterPageXcxHomeGoods_C.getJSONObject("result").getString("total"));
// JSONArray records_C = afterPageXcxHomeGoods_C.getJSONObject("result").getJSONArray("records");
//
// boolean success_C=false;
// for (int i = 0; i < records_C.size(); i++) {
// if (records_C.getJSONObject(i).getString("id").equals(studioResult2)) {
// success_C=true;
// }
// Assert.assertEquals(success_C, true, "新建三个规格的物品成功,但C端的物品列表未找到对应增加的物品ID");
// }
// Assert.assertEquals(afterTotal_C, beforeTotal_C + 1, "新建三个规格的物品成功,但C端物品列表的统计值未增加");
//校验3:获取B端物品详情,状态是开启,小程序售卖也是开启
JSONObject getDetail_goods=goodTools.getDetail_goods(studioResult2);
String state=getDetail_goods.getJSONObject("result").getString("state");
String xcxSaleState=getDetail_goods.getJSONObject("result").getString("xcxSaleState");
Assert.assertEquals(state,"YES","新建物品是启用,但物品详情展示非启用");
Assert.assertEquals(xcxSaleState,"YES","新建物品是开启小程序售卖,但物品详情展示非开启小程序售卖");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//
// //校验4:获取C端物品详情,状态是开启,小程序售卖也是开启
// JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(studioResult2,info);
// String state_C=getDetail_goods_C.getJSONObject("result").getString("state");
// String xcxSaleState_C=getDetail_goods_C.getJSONObject("result").getString("xcxSaleState");
// Assert.assertEquals(state_C,"YES","新建物品是启用,但C端物品详情展示非启用");
// Assert.assertEquals(xcxSaleState_C,"YES","新建物品是开启小程序售卖,但C端物品详情展示非开启小程序售卖");
}
}
@Test(description = "数据清理",priority = 1)
public void deleteGood()throws InterruptedException{
goodTools.deleteGoods(studioResult1);//删除新建的多规格物品
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
goodTools.deleteGoods(studioResult2);//删除新建的单规格物品
}
// @Test(description ="循环")
// public void xun(){
// for (int i = 0; i < 20; i++) {
// testCreateGoods();
// }
// }
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class createGoodsGroup extends XMBaseTest {
GoodTools goodTools=new GoodTools();
String name1="自动化创建分组";
String name2="自动化编辑分组";
String createId;
String groupId;
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoodsGroup")
.setLoginUser(LoginAccount.YFF_RC)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "创建分组")
public void testCreateGoodsGroup() {
name1="自动化创建分组";
//创建之前先看下列表的分组是不是10个,大于等于10就不走新建分组这个case了
JSONObject listPageGoodsGroup=goodTools.listPageGoodsGroup();
JSONArray listPageGoodsGroup_result=listPageGoodsGroup.getJSONArray("result");
if(listPageGoodsGroup_result.size()<10){
//创建之前先校验重名不重名
Boolean checkNameRepeatGoodsGroup=Boolean.parseBoolean(goodTools.checkNameRepeatGoodsGroup(name1).getString("result"));
if (checkNameRepeatGoodsGroup==false){
//创建分组
JSONObject createGoodsGroup=goodTools.createGoodsGroup(name1);
groupId=createGoodsGroup.getString("result");
//校验分组是否创建成功
//校验1:B端分组列表中是否有这个分组
JSONObject afterListPageGoodsGroup=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result=afterListPageGoodsGroup.getJSONArray("result");
boolean success=false;
for(int i=0; i < afterListPageGoodsGroup_result.size(); i++){
if(afterListPageGoodsGroup_result.getJSONObject(i).getString("id").equals(groupId)){
success=true;
}
Assert.assertEquals(success,true,"新建分组成功,但是分组中未找到对应的分组ID");
}
//校验2:新建物品拉取分组名称的时候也有此条数据
JSONObject listGoodsGroup=goodTools.listGoodsGroup();
JSONArray listGoodsGroupResult=listGoodsGroup.getJSONArray("result");
boolean success_listGoodsGroup=false;
for(int i=0;i < listGoodsGroupResult.size();i++){
if(listGoodsGroupResult.getJSONObject(i).getString("id").equals(groupId)){
success_listGoodsGroup=true;
}
Assert.assertEquals(success_listGoodsGroup,true,"新建分组成功,但分组中未找到对应的分组ID");
}
//新建一个物品
JSONObject create=goodTools.testCreateGoods(true);
createId=create.getString("result");
//新建分组成功后,批量移动物品至其分组
JSONObject jsonObject=goodTools.batchModifyGoodsBelongGroup(groupId,createId);
//移动至其分组校验
//校验1:该分组物品数量为1
JSONObject afterListPageGoodsGroup_count=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result_count=afterListPageGoodsGroup_count.getJSONArray("result");
for(int i=0; i < afterListPageGoodsGroup_result_count.size(); i++){
if(afterListPageGoodsGroup_result_count.getJSONObject(i).getString("id").equals(groupId)){
String goodsCount=afterListPageGoodsGroup_result_count.getJSONObject(0).getString("goodsCount");
Assert.assertEquals(goodsCount,"1","批量移动1个数据至该分组之后,该分组下物品数不为1");
}
}
Boolean checkNameRepeatGoodsGroup_modify=Boolean.parseBoolean(goodTools.checkNameRepeatGoodsGroup(name2).getString("result"));
if (checkNameRepeatGoodsGroup_modify==false) {
//编辑分组
JSONObject modifyGoodsGroup=goodTools.modifyGoodsGroup(groupId,name2);
//编辑之后校验编辑是否成功
//校验1:分组列表中有这个修改后的分组名称
JSONObject afterListPageGoodsGroup_modify=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result_modify=afterListPageGoodsGroup_modify.getJSONArray("result");
boolean success_modify=false;
for(int i=0; i < afterListPageGoodsGroup_result_modify.size(); i++){
if(afterListPageGoodsGroup_result_modify.getJSONObject(i).getString("name").equals(name2)){
success_modify=true;
}
Assert.assertEquals(success_modify,true,"编辑分组成功,但列表中没有编辑成功后的分组");
}
//校验2:新建物品拉取分组名称的时候也有此条编辑后的数据
JSONObject listGoodsGroup_modify=goodTools.listGoodsGroup();
JSONArray listGoodsGroupResult_modify=listGoodsGroup_modify.getJSONArray("result");
boolean success_listGoodsGroup_modify=false;
for(int i=0;i < listGoodsGroupResult_modify.size();i++){
if(listGoodsGroupResult_modify.getJSONObject(i).getString("id").equals(groupId)){
success_listGoodsGroup_modify=true;
}
Assert.assertEquals(success_listGoodsGroup_modify,true,"编辑分组成功,但在新建物品时拉取分组未找到对应的分组ID");
}
}
else {
System.out.println("场馆已存在相同名称分组");
}
}
else {
System.out.println("场馆已存在相同名称分组");
}
}
else{
System.out.println("分组列表已经超过10个");
}
}
@Test(description = "删除数据:物品和分组",priority = 1)
public void testDeleteGoodsGroup() {
//先删除物品
JSONObject deleteGoods=goodTools.deleteGoods(createId);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//再删除分组
//先校验分组下有没有物品,没有物品才可以删除
Boolean checkAllowDeleteSuccess=Boolean.parseBoolean(goodTools.checkAllowDelete(groupId).getJSONObject("result").getString("success"));
if(checkAllowDeleteSuccess==true) {
JSONObject deleteGoodsGroup = goodTools.deleteGoodsGroup(groupId);
//删除分组校验
//校验1:分组列表中没有这个物品
JSONObject afterListPageGoodsGroup=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result=afterListPageGoodsGroup.getJSONArray("result");
boolean success=false;
for(int i=0; i < afterListPageGoodsGroup_result.size(); i++){
if( ! afterListPageGoodsGroup_result.getJSONObject(i).getString("id").equals(groupId)){
success=true;
}
Assert.assertEquals(success,true,"删除分组成功,但列表中还有此条数据");
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验2:新建物品拉取分组名称的时候没有此条编辑后的数据
JSONObject listGoodsGroup=goodTools.listGoodsGroup();
JSONArray listGoodsGroupResult=listGoodsGroup.getJSONArray("result");
boolean success_listGoodsGroup=false;
for(int i=0;i < listGoodsGroupResult.size();i++){
if( ! listGoodsGroupResult.getJSONObject(i).getString("id").equals(groupId)){
success_listGoodsGroup=true;
}
Assert.assertEquals(success_listGoodsGroup,true,"删除分组成功,但在新建物品时拉取分组还有此条数据");
}
}
else {
System.out.println("该分组下有物品,不可删除");
}
}
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class deleteGood extends XMBaseTest {
GoodTools goodTools=new GoodTools();
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_delete")
.setLoginUser(LoginAccount.YFF_RC)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "删除物品")
public void testCreateGoods() {
// JSONObject jsonObject=goodTools.testCreateGoods(true);
//获取物品列表
JSONObject studioGoods= goodTools.studioGoods();
String id=studioGoods.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("id");
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
@Test
public void xun(){
for(int i=0;i<46;i++){
testCreateGoods();
}
}
}
\ No newline at end of file
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