部分PostMan的Tests代码块

部分Tests代码块

[TOC]


返回值为html,提取其中<p>标签的内容
//const cheerio = require('cheerio');
const $ = cheerio.load(responseBody);
result = $('div.text-center p').text();
console.log(result)

pm.test('test 001', function(){
    pm.expect(result).to.eql('新增配送方式成功');
});

官方实例

var html,
    titleText;
 
// load the response body as HTML using cheerio
// and using cheerio's jQuery like .find API, get the H1 tag
html = cheerio(responseBody);
titleText = html.find('h1').text();
 
// add a test that ensures that there is some H1 content
tests["page must have h1 heading"] = Boolean(titleText);

返回值为单个字符串
pm.test('test 001', function(){
    pm.expect(responseBody).to.eql('1')
})

返回值为JSON
pm.test("test 001", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.responseMessage.messageType).to.eql('success');
});
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容