【原】postman常用设置全局变量的js片段
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                【原】postman常用设置全局变量的js片段
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                postman知識總結:
API自動化利器:http://www.bayescafe.com/tools/use-postman-to-test-api-automatically.html
?
1.獲取環境變量內容
var ostype = pm.environment.get("ostype");?
2.設置全局變量內容
postman.setEnvironmentVariable("ts",Math.floor(new Date().getTime()/1000));?
3.auth簽名
var auth = CryptoJS.SHA1(pm.environment.get("device_secret"),{asString: true}); postman.setEnvironmentVariable("auth", auth);?
4.隨機標識
const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; // 隨機整數 const getRandomValue = list => list[randomInt(0, list.length - 1)]; // 隨機選項 const chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g', 'k', 'l', 'm', 'n', 'o', '1']; let identifier = ''; for (let i = 0; i < 5; i++) {identifier += getRandomValue(chars); } pm.environment.set("identifier", identifier);?
5.schema校驗
let json; try {json = JSON.parse(responseBody); } catch(err) {tests['服務端沒返回合法的JSON格式,請檢查相關服務、網絡或反向代理設置(以下跳過其他斷言)'] = false;tests[`[INFO] 返回:${responseBody}`] = true;console.error(err); } if (json) {const result = tv4.validateResult(json, schema);console.log(result);tests['JSON Schema格式正確 ' + result.error ] = result.valid;} else {console.error(result.error);console.error(responseBody); }?
轉載于:https://www.cnblogs.com/HYanqing/p/11271848.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的【原】postman常用设置全局变量的js片段的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Windows 运行... 可执行的命令
- 下一篇: 动态添加模板列及保持页面状态
