1、json提取器提取变量

  1. var jsonData =JSON.parse(responseBody);
  2. pm.globals.set("s_id", jsonData.data[0].id);

2、常用断言方式

  1. pm.test("Status code is 200", function () {
  2. pm.response.to.have.status(200);
  3. });
  1. pm.test("Body matches string", function () {
  2. pm.expect(pm.response.text()).to.include("string_you_want_to_search");
  3. });
  1. pm.test("Your test name", function () {
  2. var jsonData = pm.response.json();
  3. pm.expect(jsonData.value).to.eql(100);
  4. });
  1. pm.test("Body is correct", function () {
  2. pm.response.to.have.body("response_body_string");
  3. });
  1. pm.test("Content-Type is present", function () {
  2. pm.response.to.have.header("Content-Type");
  3. });
  1. pm.test("Response time is less than 200ms", function () {
  2. pm.expect(pm.response.responseTime).to.be.below(200);
  3. });
  1. pm.test("Successful POST request", function () {
  2. pm.expect(pm.response.code).to.be.oneOf([201, 202]);
  3. });
  1. pm.test("Status code name has string", function () {
  2. pm.response.to.have.status("Created");
  3. });