pm.test("The response has all properties",()=>{//parse the response JSON and test three propertiesconstresponseJson=pm.response.json();pm.expect(responseJson.type).to.eql('vip');pm.expect(responseJson.name).to.be.a('string');pm.expect(responseJson.id).to.have.lengthOf(1);}); 如果...
pm.test(testName:String, specFunction:Function):Function 接收两个参数: testName 用字符串输入一个测试名称,会显示在最终报告上;specFunction 接收一个回调函数,在该回调函数内部运行断言语句。 pm.expect():该函数对于处理来自响应 response 或变量 variables 的数据断言很有用。pm.expect 主要与 pm.test 联用。
pm.test("Body contains string",() => { pm.expect(pm.response.text()).to.include("customer_id"); }); 1. 2. 3. 这不会告诉您在哪里遇到字符串,因为它对整个响应正文执行测试。测试响应是否与字符串匹配(通常仅对短响应有效): pm.test("Body is string", function () { pm.response.to.have...
pm.test("Check if response body contains error message", function() { ... }); 这是Postman中定义测试的标准语法。它接受两个参数:一个字符串,用于描述测试的名称;一个函数,包含测试的具体实现 var jsonData = pm.response.json(); 这行代码使用Postman的pm.response.json()方法将API响应体解析为JSON对象。
expect(pm.response.status).to.equal("OK"); pm.expect(pm.response.status).to.contain("OK"); pm.expect(pm.response.status).to.contains("OK"); pm.expect(responseTime).to.greaterThan(10); pm.expect(pm.response.responseTime).to.greaterThan(10); //responseBody是一个字符串文本 pm.expect(...
Check if response body contains a string : 检查响应主体是否包含字符串 代码语言:javascript 复制 pm.test("Body matches string",function(){pm.expect(pm.response.text()).to.include("string_you_want_to_search");}); Check if response body is equal to a string :检查响应主体是否等于一个字符串...
Check if response body contains a string:检查响应主体是否包含字符串 pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search");}); 1. Check if response body is equal to a string:检查响应主体是否等于一个字符串 ...
pm.globals.unset("variable_key"); 9.获取一个变量(该函数在全局变量和活动环境中搜索变量) pm.variables.get("variable_key"); 10.检查响应主体是否包含字符串 pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search"); ...
pm.test("Contains a message property", function() { let jsonData = pm.response.json(); pm.expect(jsonData.message).to.eql("You have reached postman test demo web service"); }) Your Postman window should look like this: (Large preview) ...
3.检查响应中**string--Check if response body contains a string tests["Body matches string"] = responseBody.has("string_you_want_to_search"); 4.转化XML格式的响应成JSON对象---Convert XML body to a JSON object var jsonObject = xml2Json(responseBody); ...