postman中常用的一些脚本

提取参数

  1. 正则表达式

    access=pm.response.text().match(new RegExp('"access":"(.+?)",'))[1]
    
  2. json提取器

    老方法:

    res = JSON.parse(responseBody)
    pm.environment.set("token", res.data['access']);
    

    新方法:

    res=pm.response.json()
    pm.environment.set("token", res.data['access']);
    

参数加密

  1. sha256

    pm.environment.set("pwd",CryptoJS.SHA256('admin88888').toString());
    
  2. md5

    CryptoJS.MD5('待加密字符串').toString()
    
  3. base64

    CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse('待加密字符串'))
    
  4. AES

    CryptoJS.AES.encrypt('待加密字符串', '秘钥').toString()
    

你可能感兴趣的:(#,postman,postman,测试工具)