使用JMeter的Rest API中的动态值

我有有效载荷POST呼叫:

{  

   "tenantName":"loki","owner":
 {
    "country": "india","firstName": "raj","lastName": "kumar","locale": "in","organization": "softwareag","phone": "9789155778","title": "mr","username": "raraj@softwareag.com","email": "raraj@softwareag.com","password":"V2VsY29tZUAxMjM0"
 },"products": [
    "cumulocity","b2b"
  ]
}

在该有效负载中,租户名称是唯一的,如何为每个帖子调用传递不同的值?

wcnm2132 回答:使用JMeter的Rest API中的动态值

您可以使用__RandomString来随机化名称,例如5个小写字母:

${__RandomString(5,abcdefghijklmnopqrstuvwxyz,)}
  

RandomString函数使用要使用的字符(chars)返回长度为随机的字符串

或从CSV Data set config加载名称值

,

您可以使用__groovy() function来调用RandomStringUtils.randomAlphabetic()方法,例如:

${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(4),)}

用您选择的数字替换4,以使随机字符串变短或变长

enter image description here

该函数可以直接内联到您的请求正文中

{
  "tenantName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(4),)}","owner": {
    "country": "india","firstName": "raj","lastName": "kumar","locale": "in","organization": "softwareag","phone": "9789155778","title": "mr","userName": "raraj@softwareag.com","email": "raraj@softwareag.com","password": "V2VsY29tZUAxMjM0"
  },"products": [
    "cumulocity","b2b"
  ]
}

更多信息:Apache Groovy - Why and How You Should Use It

本文链接:https://www.f2er.com/2901296.html

大家都在问