zoukankan      html  css  js  c++  java
  • postman的正则提取和内置动态参数,cookie提取

    1. 正则匹配:新建一个规则,把左边界和有边界的值放进去,中间要提取的内容用(.+?)表示
    var data=responseBody.match(new RegExp('"height":(.+?)},'))
    console.log(data[1])
    2.内置动态参数
     时间戳 {{timestamp}}
     0-1000的随机整数数   {{randomint}}
       生成一个guid字符串    {{guid}}
    3.cookie提取
        var cookie=postman.getResponseCookie("aliyungf_tc").value
          console.log(cookie)
    4. 获取一个1000-2000之间的随机数
      1.获取一个随机数( constant 是定义一个函数)
        const randomInt = (min,max) =>Math.random()   //范围在0-0.9999999之间  
        console.log(randomInt(1000,2000))
        const randomInt = (min,max) =>Math.random()*100  //0-100之间取随机数
        2.获取一个1000到2000之间的随机数
      const randomInt = (min,max) =>Math.floor(Math.random()*(max-min+1))+min
           console.log(randomInt(1000,2000))
      Math.floor是取整的意思  
    5.如果多个接口都要用动态参数
      可以设置一个全局变量,值等于动态参数 var  randomInt = (min,max) =>Math.floor(Math.random()*(max-min+1))+min
      那么多个接口都可以取这个值,但是取到的时候字符串,需要用  eval函数把这个转换成一个函数
     
    6. postman的MD5加密(有时候传参需要穿加密过的参数,需要进行把参数在pre--request Script里进行预处理,处理过后设置一个全局变量,传参时直接引用)
      var username=CryptoJS.MD5('admin').toString().toUpperCase()  //toUpperCase()是加密后把小写字母转换为大写字母
           console.log(username)
     
     
     
    人生因有期待而美好; 谁不是一边热爱生活,又一边不想活。 学最好的别人,做最好的自己。
  • 相关阅读:
    LeetCode Find Duplicate File in System
    LeetCode 681. Next Closest Time
    LeetCode 678. Valid Parenthesis String
    LeetCode 616. Add Bold Tag in String
    LeetCode 639. Decode Ways II
    LeetCode 536. Construct Binary Tree from String
    LeetCode 539. Minimum Time Difference
    LeetCode 635. Design Log Storage System
    LeetCode Split Concatenated Strings
    LeetCode 696. Count Binary Substrings
  • 原文地址:https://www.cnblogs.com/peoty/p/15110300.html
Copyright © 2011-2022 走看看