我们在进行接口请求测试时,会进行不同参数请求测试。当出现大批量参数时,如何能够进行一步到位的测试呢?各位看官且慢慢看来~~~
-
将参数格式化到cvs文件中
2.预置脚本
//获取page参数
var page= "1";
if(data.page){
page= data.page
}
pm.environment.set("page", page);
//获取page_size参数
var page_size= "7988";
if(data.page_size){
page_size = data.page_size
}
pm.environment.set("page_size", page_size);
//获取platform参数
var platform= "android";
if(data.platform){
platform= data.platform
}
pm.environment.set("platform", platform);
//获取Case用例名
var Case = "Debug";
if(data.Case){
Case = data.Case
}
pm.environment.set("Case", Case);
//获取Assertion断言内容
var Assertion = "0";
if(data.Assertion){
Assertion = data.Assertion
}
pm.environment.set("Assertion", Assertion);
//打印日志
console.log("执行用例: " + Case);
3.test模块脚本
//状态码
pm.test("断言: HTTP状态码 200", function () {
pm.response.to.have.status(200);
});
//响应时间
pm.test("断言: 响应时间 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
//自定义断言
var Assertion = pm.environment.get("Assertion");
var game_id = pm.environment.get("game_id");
var responseData = JSON.parse(responseBody);
//tests["断言: errcode " + Assertion] = ;
console.log(responseData);
if(Assertion == 200){
console.log(tv4.validate(responseData, schema));
//tests["断言: errcode " + Assertion] = true;
tests["断言: " + Assertion] = tv4.validate(responseData, schema); //验证json格式
}
else{
//console.log(responseData.code.value);
tests["断言: " + Assertion] = tv4.validate(responseData, schema1);
4.启动测试
如图:选择参数文件(支持cvs/text)
点击preview按钮可预览参数
点击蓝色runner按钮,即可进行批量测试