当前位置:网站首页>Jmeter- (IV) regular expression for interface testing

Jmeter- (IV) regular expression for interface testing

2022-06-25 21:18:00 Hello, test

Preface :

         stay jmeter View a list in , Generally, we will get a corresponding... According to a field ID, For subsequent use cases , When matching , Regular expressions are used , The writing method varies according to the data structure of the return value of the list , Here are a few common formats , Then there are other formats , It can be supplemented .


These operators are used below , Please refer to the screenshot below :

Refer to the website :JsonPath Use _LZJWXJ Koalas -CSDN Blog

1. according to name obtain moid

"result":

[{

"network": 7,

"moid": "datacenter-57",

"datastore": 2,

"name": "DC1"

}]

}

JSONPath Expression: $.result[?(@.name =='${NAME}')][0].moid

2.  according to host_name obtain host_moid

"result": 

   [ {

  "cluster_name": "test FT", 

  "cluster_type": true, 

  "cluster_moid": "domain-c1960", 

   "child": 

   [  {

  "host_moid": "host-2179", 

 "host_name": "10.10.132.111"

  } ]

 }]

JSONPath Expression:  $.result[0].child[?(@.host_name=='${HOST_NAME}')][0].host_moid

3.  Direct access to cpu and memory_KB

"result": 

 {

 "data_store": 

  [ {

"moid": "datastore-2181", 

 "name": "datastore1", 

 "ssd": "false", 

 "type": "VMFS", 

"thin_support": true

   }],

     "cpu":32, 

     "memory_KB": 67108276

      }

JSONPath Expression:  obtain cpu:  $.result.cpu

                                      obtain memory_KB:  $.result.memory_KB

4.  according to name obtain moid

"result": 

 {

 "data_store": 

  [ {

"moid": "datastore-2181", 

 "name": "datastore1", 

 "type": "VMFS", 

"thin_support": true

   }],

     "cpu":32, 

     "memory_KB": 67108276

      }

JSONPath Expression:   $.result.data_store[?(@.name=='${DATASTORE_NAME}')][0].moid 

5. Based on acquisition state

"result":

{

"childSnapshotList":

[

{

"currentSnapshot": false,

"quiesced": false,

"state": "suspended",

"childSnapshotList":

[

{

"currentSnapshot": true,

"quiesced": false,

"state": "poweredOff",

"childSnapshotList":

[

],

"name"

"SNAPSHOT1_2",

"id": 56

}

],

"name"

"SNAPSHOT_2",

"id": 55

}

]

}

JSONPath Expression:  $.result.childSnapshotList[0].childSnapshotList[?(@.name =='${SNAPSHOT1}')][0].state

Hello Test, The above examples are all used by me Jmeter During interface testing , Some of the common API The structure of the response data , Write regular expressions according to different structures , You can refer to the same type of structure , Leave a message in the comment area , finger heart ~

原网站

版权声明
本文为[Hello, test]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202181331152260.html