Commit 356203fc authored by Su-Yi's avatar Su-Yi

增加自动创建、删除功能

parent 9b33ae7c
......@@ -25,6 +25,7 @@ public class Article {
public void setUp() {
}
//文章内容页
@Test(description="代理人_种草爆文列表页",priority = 1)
public void 代理人_种草爆文列表页() throws IOException {
......
......@@ -39,10 +39,10 @@ public class CircleFriends {
@Test(description="获取tab列表",priority = 2)
public void 获取tab列表() throws IOException {
Response response = network.getResponse(FRIENDS_GETMATERIALTAGS);
int tabCount = response.jsonPath().getInt("data.size()");
boolean hasList = response.jsonPath().getInt("data.size()") > 0;
int id = response.jsonPath().getInt("data.find {it.name == '保险'}.id"); //标签tab
firstTagId = response.jsonPath().getInt("data[0].id");//第一个标签的ID
Assert.assertEquals(tabCount,6,network.message(FRIENDS_GETMATERIALTAGS,"获取tab数量有误",response.body().asString()));
Assert.assertTrue(hasList,network.message(FRIENDS_GETMATERIALTAGS,"获取tab数量有误",response.body().asString()));
Assert.assertEquals(id,595,network.message(FRIENDS_GETMATERIALTAGS,"获取tab中不包含保险",response.body().asString()));
}
......
package com.kjj.qa.cases;
import com.kjj.qa.utils.BaseUtils;
import com.kjj.qa.utils.NetworkUtils;
import io.restassured.response.Response;
import org.testng.Assert;
......@@ -119,5 +120,8 @@ public class GreetingCard {
@AfterClass
public static void tearDown(){
apiCount += 8;
// 删除账号
BaseUtils.disableUser();
}
}
......@@ -3,7 +3,7 @@ package com.kjj.qa.cases;
import static com.kjj.qa.config.BasicConfig.*;
import static io.restassured.RestAssured.given;
import com.kjj.qa.utils.ManagerUtils;
import com.kjj.qa.utils.BaseUtils;
import com.kjj.qa.utils.NetworkUtils;
import io.restassured.response.Response;
import org.testng.Assert;
......@@ -22,10 +22,12 @@ public class Pay {
@BeforeClass
public static void setUp() {
// 创建用户 并传到network里
AGENT_TKU = BaseUtils.createTku();
network.agentCookies.put("tku",AGENT_TKU);
}
@Test (description = "默认付费_付费页",priority = 1) //priorty 方法执行优先级
@Test (description = "默认付费_付费页",priority = 1) //priority 方法执行优先级
public void 默认付费_付费页() throws IOException {
//付款中间页判断
Response response = network.getResponse(PAY_GETMIDDLEDETAIL);
......@@ -35,7 +37,7 @@ public class Pay {
//会销资格判断
response = network.getResponse(PAY_HASSITESALEVALID);
boolean siteSaleValid = response.jsonPath().getBoolean("data");
Assert.assertEquals(siteSaleValid,false,network.message(PAY_HASSITESALEVALID,"会销资格判断:判断错误,有会销资格",response.body().asString()));
Assert.assertFalse(siteSaleValid,network.message(PAY_HASSITESALEVALID,"会销资格判断:判断错误,有会销资格",response.body().asString()));
//会员类型版本判断
Map<String, Object> params = new HashMap<String, Object>();
......@@ -48,7 +50,7 @@ public class Pay {
//获取当前用户可用优惠码
response = network.getResponse(params,PAY_GETPROMOCODE);
String promoCode = response.jsonPath().getString("data");
Assert.assertEquals(promoCode,null, network.message(params,PAY_GETPROMOCODE,"是否优惠判断:判断错误,当前有优惠",response.body().asString()));
Assert.assertNull(promoCode, network.message(params,PAY_GETPROMOCODE,"是否优惠判断:判断错误,当前有优惠",response.body().asString()));
//获取付费价格
// Response actualPayMoneyResponse = network.getResponse(PAY_COMBOLIST);
......@@ -118,7 +120,7 @@ public class Pay {
public void 默认付费_微信支付后回调() throws IOException {
//创建支付
Map<String, Object> payParams = new HashMap<String, Object>();
payParams.put("userVersion",1);
payParams.put("userVersion",2); // 1 通用版 2 保险版
payParams.put("comboId","Kj21MTU");
payParams.put("oaId","1");
payParams.put("paySource","2");
......@@ -151,9 +153,6 @@ public class Pay {
public static void tearDown() throws IOException, InterruptedException {
apiCount += 7;
// 切换为保险版vip
ManagerUtils.switchvip();
//延迟2秒
Thread.sleep(2000);
}
......
......@@ -17,7 +17,7 @@ public class Upload {
@BeforeClass
public void setUp() {
System.out.println();
}
@Test(description="会员判断",priority = 1)
......
......@@ -3,23 +3,26 @@ package com.kjj.qa.config;
public class BasicConfig {
public static int apiCount; //接口数量统计
// *************** 配置信息,每次重新配置以下信息就ok ***************
// 是否推送
// 是否开启钉钉机器人推送
public static final boolean isPushReport = true; //true
// 用户微信昵称
public static final String WECHAT_NAME = "小疙瘩人寿"; //true
// 用户tku
public static final String AGENT_TKU = "T3gM31f18jAWCsXW1UG8R8APmD6DCd3FZdTj6LC27JQpLqwSBR6Jso7ceK5azRdKHRuWjmtxrDAUopQXRp";
// 小疙瘩的openid
public static final String OPEN_ID = "osi5w5ucTy5jRR0zw7hLNJm1S3xY";
// *************** 钉钉机器人 ***************
// 线上-告警群
public static final String DINGTALKPATH = "https://oapi.dingtalk.com/robot/send?access_token=f63c9cb36e89dd68e9af82d926933b3afc6544e57b23a3a55ed5b3b772d5e8d2";
// 测试
// public static final String DINGTALKPATH = "https://oapi.dingtalk.com/robot/send?access_token=e4b7d997fb9f90b17672dcdb9c9922d52c59f741b82081a368f4d3c305c1afcd";
// 代理人 TKU
public static String AGENT_TKU = null;
// 访客 TKU
public static final String VISITOR_TKU = "T3gM31f18jAW2hicRDxbwHFSuwA4MMVLLeHZ5G4yvb3kN2xUC7kBMVyjghwaMUaBkXBb34TrZkSBtySoUs";
// 代理人微信昵称
public static final String WECHAT_NAME = "客集集-梦晨"; //true
// 代理人的openid(固定)
public static final String OPEN_ID = "osi5w5l1lGC9T8f-sLNNurqvfS4A";
// 客集云公众号的oaSourceId(固定)
public static final String OASOURCE_ID = "gh_3b9884c7b0ee";
// 钉钉机器人 线上-告警群
public static final String DINGTALKPATH = "https://oapi.dingtalk.com/robot/send?access_token=f63c9cb36e89dd68e9af82d926933b3afc6544e57b23a3a55ed5b3b772d5e8d2";
// *************** 客集集域名 ***************
public static final String HOST = "https://kjj.m.duibatest.com.cn";
......@@ -31,10 +34,6 @@ public class BasicConfig {
public static final String MANAGER_HOST = "https://kjj-mng.duibatest.com.cn";
// *************** TKU ***************
public static final String VISITOR_TKU = "T3gM31f18jAW2hicRDxbwHFSuwA4MMVLLeHZ5G4yvb3kN2xUC7kBMVyjghwaMUaBkXBb34TrZkSBtySoUs";
// *************** 素材ID ***************
public static final String ARTICLE_CONTENTID = "Kj21NjM4NDc";
......@@ -48,6 +47,9 @@ public class BasicConfig {
// *************** 公共 ***************
public static final String CREATE_USER = HOST + "/kjy/mp/autotest/create/user";
public static final String AUTOTEST_UNSUBSCRIBE = HOST + "/kjy/mp/autotest/unsubscribe";
public static final String AUTOTEST_TKU = HOST + "/kjy/mp/autotest/tku";
public static final String VERSION_INFO = HOST + "/kjy/mp/version/info";
......@@ -195,12 +197,15 @@ public class BasicConfig {
public static final String FRIENDS_GETCURRENTINFO = HOST + "/kjy/mp/timelineContent/getCurrentInfo";
// ************** 首页 ****************
public static final String HOME_GETHOMETIMELINECONTENT = HOST + "/kjy/mp/home/getHomeTimeLineContent";
// ************** 设置中心 ***************
public static final String SELLERCONFIG_EDITCONFIG = HOST + "/kjy/mp/sellerConfig/editConfig";
// ************** BOSS看板 ***************
public static final String BOSS_VERSIONINFO = HOST + "/kjy/mp/version/info";
......@@ -244,10 +249,14 @@ public class BasicConfig {
public static final String GREETING_SAVEDEFAULT = ACTIVITY_HOST + "/kjy/mp/greeting/conf/saveDefault";
// *************** 管理后台 ***************
public static final int PROMOTION_CODE = 398; // 优惠码ID
public static final String SSO_DOLOGIN = SSO_HOST + "/doLogin";
public static final String MANAGER_DISABLEUSER = MANAGER_HOST + "/kjy/manager/testUser/disableUser";
public static final String MANAGER_CHANGECOMPANY = MANAGER_HOST + "/kjy/manager/seller/changeCompany";
public static final String MANAGER_UPDATETYPEORDATE = MANAGER_HOST + "/kjy/manager/seller/updateTypeOrDate";
......
package com.kjj.qa.utils;
import io.restassured.response.Response;
import java.util.HashMap;
import java.util.Map;
import static com.kjj.qa.config.BasicConfig.*;
public class AccountUtils {
private static final NetworkUtils network = NetworkUtils.getInstance();
public static void changeTku(){
Map<String, Object> params = new HashMap<String, Object>();
params.put("openId","osi5w5ucTy5jRR0zw7hLNJm1S3xY");
params.put("password","gh_3b9884c7b0ee");
Response response = network.getResponse(params,CREATE_USER);
response.body().prettyPrint();
}
public static void main(String[] args) {
changeTku();
}
}
package com.kjj.qa.utils;
import io.restassured.response.Response;
import org.testng.Assert;
import static com.kjj.qa.config.BasicConfig.*;
......@@ -8,13 +9,13 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ManagerUtils {
public class BaseUtils {
private static final NetworkUtils network = NetworkUtils.getInstance();
private static int PROMOTION_CODE = 398;
// 登录管理后台
/**
* 登录管理后台
*/
public static void ssoLogin(){
// 请求下后台的管理员信息接口
Response response = network.getResponse(MANAGER_ADMININFO);
String actualType = "application/json;charset=UTF-8";
......@@ -45,14 +46,31 @@ public class ManagerUtils {
network.agentHeaders.put("X-Csrf-Token",ssoCookies.get("csrf_token"));
}
// 拿到sellerId
/**
* 获取 sellerId
* @return sellerId
*/
public static String getSellerId (){
Response response = network.getResponse(USER_INFO);
return response.jsonPath().getString("data.sellerId");
}
// 切换vip
public static void switchvip() {
/**
* 获取 userId
* @return userId
*/
public static String getUserId (){
Response response = network.getResponse(USER_INFO);
return response.jsonPath().getString("data.userId");
}
/**
* 切换vip
* @param userVersion 1是通用版 2是保险版
* @param vipType 1是普通用户 2是vip用户
*/
public static void switchVip(int userVersion, int vipType) {
String sellerId = getSellerId();
// 登录下,检验是否失效
......@@ -69,8 +87,8 @@ public class ManagerUtils {
Map<String, Object> switchVipParams = new HashMap<String, Object>();
switchVipParams.put("reason","1");
switchVipParams.put("sellerId",sellerId);
switchVipParams.put("userVersion",2);
switchVipParams.put("vipType",2);
switchVipParams.put("userVersion",userVersion);
switchVipParams.put("vipType",vipType);
switchVipParams.put("vipStartDate",System.currentTimeMillis());
switchVipParams.put("vipEndDate",System.currentTimeMillis() + 1000*3600*24*365L);
response = network.postResponse(switchVipParams,MANAGER_UPDATETYPEORDATE);
......@@ -79,15 +97,20 @@ public class ManagerUtils {
changeParams.remove("companyId",6); //去掉公司
response = network.getResponse(changeParams,MANAGER_CHANGECOMPANY);
// 删除管理后台tku
network.agentHeaders.remove("X-Csrf-Token");
network.agentCookies.remove("sso_ticket");
network.agentCookies.remove("device_no");
network.agentCookies.remove("csrf_token");
}
// 切换为内部人员 isInternalSeller 传1代表内部人员 传0代表非内部人员
/**
* 标记为内部人员
* @param isInternalSeller 1:内部人员 0:非内部人员
*/
public static void switchInsider(int isInternalSeller){
String sellerId = getSellerId();
// 登录下,检验是否失效
ssoLogin();
......@@ -97,47 +120,54 @@ public class ManagerUtils {
Response response = network.getResponse(params,MANAGER_SETINTERALSELLER);
response.body().prettyPrint();
// 删除管理后台tku
network.agentHeaders.remove("X-Csrf-Token");
network.agentCookies.remove("sso_ticket");
network.agentCookies.remove("device_no");
network.agentCookies.remove("csrf_token");
}
// 拿优惠码
public static void getPromotionCode() {
/**
* 获取优惠码
* @return 未使用的优惠码
*/
public static String getPromotionCode() {
// 登录下,检验是否失效
ssoLogin();
// 获取优惠码详情
// 获取优惠码详情
Map<String, Object> params = new HashMap<String, Object>();
params.put("id",PROMOTION_CODE);
Response response = network.getResponse(params,MANAGER_PROMOTIONCODEBATCHDETAIL);
long deadline = response.jsonPath().getLong("data.deadline");
deadline = (deadline - System.currentTimeMillis()) / (1000*60*60*24); //到期时间
// 检测日期是否快到期,若到期修改截止日期
if (deadline < 5)
{
if (deadline < 5) {
modifyPromotionCode(0);
}
// 获取未使用的code列表
// 获取该优惠码下未使用的列表
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("batchId",PROMOTION_CODE);
listParams.put("promotionCodeStatus",0); //0 未使用
listParams.put("pageIndex",1);
listParams.put("pageSize",20);
response = network.getResponse(listParams,MANAGER_PROMOTIONCODELIST);
int unUseCount = response.jsonPath().getInt("data.list.size()");
// 未使用数量 < 5
if (unUseCount < 5)
{
// 优惠码未使用数量 不足5个
if (unUseCount < 5) {
modifyPromotionCode(100);
}
// 取未使用列表的第一个优惠码
response =network.getResponse(listParams,MANAGER_PROMOTIONCODELIST);
return response.jsonPath().getString("data.list[0].promotionCode");
}
/**
* 修改优惠码
* @param addNum 追加的优惠码数量
*/
public static void modifyPromotionCode(int addNum){
Map<String, Object> params = new HashMap<String, Object>();
params.put("addNum", Math.max(addNum, 0)); // 如果addNum > 0,则返回大的那个值
......@@ -155,12 +185,92 @@ public class ManagerUtils {
Response response = network.postResponse(params,MANAGER_PROMOTIONBATCHMODIFY);
response.body().prettyPrint();
}
/**
* 创建用户和tku
*/
public static String createTku(){
// 创建userId
Map<String, Object> params = new HashMap<String, Object>();
params.put("openId",OPEN_ID);
params.put("oaSourceId",OASOURCE_ID);
Response response = network.getResponse(params,CREATE_USER);
long userId = response.jsonPath().getLong("data");
response.body().prettyPrint();
// 创建tku
Map<String, Object> tkuParams = new HashMap<String, Object>();
tkuParams.put("userId",userId);
response = network.getResponse(tkuParams,AUTOTEST_TKU);
response.body().prettyPrint();
String tku = "";
try {
// 判断tku 是否有效
tku = response.jsonPath().getString("data");
Assert.assertNotNull(tku);
} catch (AssertionError e) {
System.out.println("获取tku失败");
DingTalkUtils.sendError("测试停止-获取tku失败! \n"+
"path: " + AUTOTEST_TKU + "\n" +
"params: " + params + "\n" +
"response: "+response.body().asString());
throw new RuntimeException();
}
// tku赋值
return tku;
}
/**
* 获取tku
* @param userId 用户id
* @return 用户tku
*/
public static String getTku(int userId){
Map<String, Object> tkuParams = new HashMap<String, Object>();
tkuParams.put("userId",userId);
Response response = network.getResponse(tkuParams,AUTOTEST_TKU);
response.body().prettyPrint();
return response.jsonPath().getString("data");
}
/**
* 账号禁用
*/
public static void disableUser() {
// 获取sellerId、userId
String sellerId = getSellerId();
String userId = getUserId();
// 取关公众号
Map<String, Object> unsubscribeParams = new HashMap<String, Object>();
unsubscribeParams.put("userId",userId);
unsubscribeParams.put("oaId",1);
Response response = network.getResponse(unsubscribeParams,AUTOTEST_UNSUBSCRIBE);
System.out.println(response.statusCode());
// 登录下,检验是否失效
ssoLogin();
// 公司改为客集集
Map<String, Object> changeParams = new HashMap<String, Object>();
changeParams.put("id",sellerId);
changeParams.put("companyId",6);
response = network.getResponse(changeParams,MANAGER_CHANGECOMPANY);
// 删除账号
Map<String, Object> params = new HashMap<String, Object>();
params.put("userId",userId);
response = network.postResponse(params,MANAGER_DISABLEUSER);
response.body().prettyPrint();
}
public static void main(String[] args) throws IOException {
getPromotionCode();
}
}
package com.kjj.qa.utils;
import io.restassured.response.Response;
import static com.kjj.qa.config.BasicConfig.*;
import java.util.HashMap;
import java.util.Map;
public class DingTalkUtils {
//通过钉钉机器人发送消息到钉钉群中
private static final NetworkUtils network = NetworkUtils.getInstance();
// 通过钉钉机器人发送消息到钉钉群中
public static void sendVal(String context)throws Exception{
//测试结果
context = "【测试结果】\n"
......@@ -26,22 +31,30 @@ public class DingTalkUtils {
//发起dingding机器人通知
if (isPushReport){
NetworkUtils network = NetworkUtils.getInstance();
network.dingTalkRobot(params);
}
}
// 流程走不通,发送错误信息到钉钉
public static void sendError(String errorMessage){
Map<String, Object> contentParams = new HashMap<String, Object>();
contentParams.put("content","【测试结果】\n" + errorMessage);
public static void main(String[] args) {
//获取当前系统时间
// long currentTime = System.currentTimeMillis();
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
// Date date = new Date(currentTime);
// System.out.println(formatter.format(date));
//钉钉机器人消息体
Map<String, Object> params = new HashMap<String, Object>();
params.put("msgtype","text");
params.put("text",contentParams);
System.out.println(params);
//发起dingding机器人通知
if (isPushReport){
Response response = network.dingTalkRobot(params);
response.body().prettyPrint();
}
}
// Reporter.log(formatter.format(date) + splitTimeAndMsg + msg, true);
public static void main(String[] args) {
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
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