部分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');
});