Commit ad225d14 authored by Su-Yi's avatar Su-Yi

增加上传case,增加Network框架请求文件类型

parent 11102261
......@@ -26,8 +26,8 @@ public class Upload {
Assert.assertTrue(true, "会员判断错误");
}
@Test(description = "上传文章链接",priority = 2)
public void 上传文章链接() throws IOException {
@Test(description = "上传_文章链接",priority = 2)
public void 上传_文章链接() throws IOException {
//待上传的文章链接
String articleLink = "https://mp.weixin.qq.com/s/j4qnDM98d2ZPW35ozFra8w";
......@@ -47,13 +47,13 @@ public class Upload {
String contentId = response.jsonPath().getString("data.contentId");//内容ID
String contentImageUrl = response.jsonPath().getString("data.contentImageUrl");
String contentType = response.jsonPath().getString("data.contentType");
Assert.assertEquals(contentType,"network_link","上传其他链接-查询调用失败");
Assert.assertEquals(contentType,"article","上传文章链接-查询调用失败");
}
@Test(description="上传视频链接",priority = 3)
public void 上传视频链接() throws IOException{
@Test(description="上传_视频链接",priority = 3)
public void 上传_视频链接() throws IOException{
//待上传的视频链接
String videoLink = "https://mp.weixin.qq.com/s/j4qnDM98d2ZPW35ozFra8w";
String videoLink = "https://v.douyin.com/oEahcd/ 复制此链接,打开【抖音短视频】,直接观看视频!";
//开始上传
Map<String, Object> params = new HashMap<String, Object>();
......@@ -70,12 +70,12 @@ public class Upload {
int taskStatus = response.jsonPath().getInt("data.taskStatus");//上传状态: 1是执行中,2是上传成功
String contentId = response.jsonPath().getString("data.contentId");//内容ID
String contentImageUrl = response.jsonPath().getString("data.contentImageUrl");
String contentType = response.jsonPath().getString("data.contentType");
Assert.assertEquals(contentType,"network_link","上传其他链接-查询调用失败");
String responseTaskId = response.jsonPath().getString("data.taskId");
Assert.assertEquals(responseTaskId,taskId,"上传视频链接-查询调用失败");
}
@Test(description = "上传其他链接",priority = 4)
public void 上传其他链接() throws IOException {
@Test(description = "上传_其他链接",priority = 4)
public void 上传_其他链接() throws IOException {
//待上传的其他链接
String network_link = "https://tieba.baidu.com/p/6688007444";
......@@ -116,9 +116,10 @@ public class Upload {
@Test(description = "上传_本地视频",priority = 5)
public void 上传_本地视频() throws IOException {
//1.上传视频到oss
Response response = network.postResponse("/kjy/mp/upload/video");
String videoUrl = response.jsonPath().getString("videoUrl");
String firstFrameUrl = response.jsonPath().getString("firstFrameUrl");
Response response = network.postFileResponse("src/test/java/com/kjj/qa/resource/uploadCase.mp4","/kjy/mp/upload/video");
String videoUrl = response.jsonPath().getString("data.videoUrl");
String firstFrameUrl = response.jsonPath().getString("data.firstFrameUrl");
System.out.println(videoUrl+"\n"+firstFrameUrl);
Assert.assertNotNull(videoUrl,"上传本地视频-上传oss失败");
//2.开始上传视频
......@@ -128,7 +129,7 @@ public class Upload {
params.put("contentTitle","=自动化测试=");
response = network.postResponse(params,"/kjy/mp/seller/upload/video");
String contentId = response.jsonPath().getString("data.contentId");
Assert.assertNotNull(videoUrl,"上传本地视频-上传第步失败");
Assert.assertNotNull(videoUrl,"上传本地视频-上传第2步失败");
}
@Test(description="大家都在转_榜单列表",priority = 6)
......@@ -169,7 +170,7 @@ public class Upload {
response = network.getResponse(params,"/kjy/mp/seller/import/list");
length = response.jsonPath().getInt("data.size()");
contentType = response.jsonPath().getString("data[0].contentType");
Assert.assertEquals(length, 1, "获取我的上传-视频列表内容有误");
Assert.assertEquals(length, 2, "获取我的上传-视频列表内容有误");//因为有一篇抖音,一篇本地,所以数量是2
Assert.assertEquals(contentType, "video", "获取我的上传-视频列表数量有误");
//获取其他的列表
......@@ -195,14 +196,14 @@ public class Upload {
Assert.assertEquals(length, 0, "获取我的上传-其他列表数量有误");
}
@Test(description="上传视频失败重试")
public void 上传视频失败重试() throws IOException{
Map<String, Object> params = new HashMap<String, Object>();
params.put("taskId","Kj21NDE3Mjc");
Response response = network.getResponse("/kjy/mp/seller/import/tryupload");
String upload = response.jsonPath().get("success");
Assert.assertEquals(upload, true,"上传失败");
}
// @Test(description="上传视频失败重试")
// public void 上传视频失败重试() throws IOException{
// Map<String, Object> params = new HashMap<String, Object>();
// params.put("taskId","Kj21NDE3Mjc");
// Response response = network.getResponse("/kjy/mp/seller/import/tryupload");
// String upload = response.jsonPath().get("success");
// Assert.assertEquals(upload, true,"上传失败");
// }
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import javax.print.DocFlavor;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
......@@ -26,6 +27,10 @@ public class NetworkUtil {
public Map<String, Object> getAgentHeaders() { return agentHeaders; }
public void setAgentHeaders(Map<String, Object> agentHeaders) { this.agentHeaders = agentHeaders; }
public Map<String, Object> fileHeaders = new HashMap<String, Object>();
public Map<String, Object> getFileHeaders() { return agentHeaders; }
public void setFileHeadersHeaders(Map<String, Object> fileHeaders) { this.fileHeaders = fileHeaders; }
// 钉钉的 headers
public Map<String, Object> dingTalkHeaders = new HashMap<String, Object>();
public Map<String, Object> getDingTalkHeaders() { return dingTalkHeaders; }
......@@ -37,17 +42,23 @@ public class NetworkUtil {
//技术告警群
private static String dingtalkPath = "https://oapi.dingtalk.com/robot/send?access_token=f63c9cb36e89dd68e9af82d926933b3afc6544e57b23a3a55ed5b3b772d5e8d2";
// private static String dingtalkPath = "https://oapi.dingtalk.com/robot/send?access_token=f63c9cb36e89dd68e9af82d926933b3afc6544e57b23a3a55ed5b3b772d5e8d2";
//测试
// private static String dingtalkPath = "https://oapi.dingtalk.com/robot/send?access_token=e4b7d997fb9f90b17672dcdb9c9922d52c59f741b82081a368f4d3c305c1afcd";
private static String dingtalkPath = "https://oapi.dingtalk.com/robot/send?access_token=e4b7d997fb9f90b17672dcdb9c9922d52c59f741b82081a368f4d3c305c1afcd";
private volatile static NetworkUtil network;
// 构造函数 初始化tku、content-type
private NetworkUtil (){
//cookies中的tku
agentCookies.put("tku","T3gM31f18jAWdUCruXfs5ctTjrD7HUxiwWFhgGdsgYUHEcnsw5hkVNdMgsNhrH61CLETLLNt2N4q2wBCyN");
//json类型的headers
agentHeaders.put("Content-Type","application/json");
//二进制文件的headers
fileHeaders.put("Content-Type","multipart/form-data");
//钉钉的headers
dingTalkHeaders.put("Content-Type","application/json;charset=utf-8");
}
//单例模式
......@@ -81,7 +92,7 @@ public class NetworkUtil {
.cookies(agentCookies)
.headers(agentHeaders)
.params(params)
.get(host+path);
.get(host + path);
}
// post 不帶参请求
......@@ -89,7 +100,7 @@ public class NetworkUtil {
return given()
.cookies(agentCookies)
.headers(agentHeaders)
.post(host+path);
.post(host + path);
}
// post 带参请求
......@@ -99,14 +110,22 @@ public class NetworkUtil {
.cookies(agentCookies)
.headers(agentHeaders)
.body(jsonStr)
.post(host+path);
.post(host + path);
}
// post 文件上传
public Response postFileResponse(String filePath, String path){
return given()
.cookies(agentCookies)
.headers(fileHeaders)
.multiPart("file",new File(filePath))
.post(host + path);
}
// post 带参请求
public Response dingTalkRobot(Map<String, Object> params) {
String jsonStr = JSONObject.toJSONString(params);
dingTalkHeaders.put("Content-Type","application/json;charset=utf-8");
return given()
.headers(dingTalkHeaders)
......@@ -114,16 +133,9 @@ public class NetworkUtil {
.post(dingtalkPath);
}
public static void main(String[] args) {
// NetworkUtil network = new NetworkUtil();
//
// Map<String,Object> json=new HashMap();
// Map<String,Object> text=new HashMap();
// json.put("msgtype","text");
//
// text.put("content","报告 :");
// json.put("text",text);
// Response res = network.dingTalkRobot(json);
}
}
......@@ -16,11 +16,11 @@
<class name="com.kjj.qa.cases.SellerCard"/>
</classes>
</test>
<!-- <test preserve-order="true" name="上传" >-->
<!-- <classes>-->
<!-- <class name="com.kjj.qa.cases.Upload"/>-->
<!-- </classes>-->
<!-- </test>-->
<test preserve-order="true" name="上传" >
<classes>
<class name="com.kjj.qa.cases.Upload"/>
</classes>
</test>
<!-- <test preserve-order="true" name="新手任务" >-->
<!-- <classes>-->
<!-- <class name="com.kjj.qa.cases.NewTask"/>-->
......
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