10、postman中腳本的運用:chai.js

1、chai.js的API地址

postman之chaihttps://www.chaijs.com/api/

postman之cookiehttp://www.postmanlabs.com/postman-collection/CookieList.html#get

postman官方文檔https://learning.getpostman.com/docs/postman/environments-and-globals/manage-environments/

postman連接mysqlhttps://github.com/o1lab/xmysql#setup-and-usage

postman內置模塊列表https://learning.getpostman.com/docs/postman/scripts/postman-sandbox-api-reference/


2、chai.js有兩種風格:BDD、TDD

postman對BDD風格進行了重新封裝,在使用時,需要在方法之前加上pm,並且用戶在postman中使用腳本時,通常需要統計pass和fail的接口數量,所以在postman中使用斷言需要放在pm.test()方法中,不在pm.test()方法中使用的話,即便斷言失敗,也不會統計數量。

示例:

pm.test("Check if pattern is in target string",function () {
  pm.expect.fail('11');  
  });

3、在postman的腳本中依然可以使用原生的BDD和TDD

示例

var assert = require('chai').assert;   
var expect = require('chai').expect;

pm.test("Body is correct", function () {
    assert.isOk('1','');
});
pm.test("Check if pattern is in target string",function () {
  expect.fail('22');    
  });

截圖

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章