jmeter使用正则表达式匹配多个中的响应结果

一、背景:

同一个正则表达式匹配多个响应结果值,之前都是添加多个正则表达式,一个一个去获取需要的值,比较麻烦;今天尝试了一下用一个正则表达式获取响应中所有需要的值,使用这种方式也能够获取多个结果中指定的值,完美省事!

二、例如:

我要获取如下响应报文中首次出现的两个值(barnType 和 trainScheduleBarnId 的值)目标是:{"available":0,"barnNo":"01","barnType":"STX1","recommend":0,"spaceStatus":"FULL","trainScheduleBarnId":3271} 

三、接口响应的所有结果:

 

{"content":{"barns":[{"available":0,"barnNo":"01","barnType":"STX1","recommend":0,"spaceStatus":"FULL","trainScheduleBarnId":3271},{"available":1,"barnNo":"02","barnType":"STX2","recommend":1,"spaceStatus":"EMPTY","trainScheduleBarnId":3272},{"available":0,"barnNo":"03","barnType":"STX3","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3273},{"available":0,"barnNo":"04","barnType":"STX4","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3274},{"available":1,"barnNo":"05","barnType":"STX1","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3275},{"available":1,"barnNo":"06","barnType":"STX2","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3276},{"available":0,"barnNo":"07","barnType":"STX3","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3277},{"available":0,"barnNo":"08","barnType":"STX4","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3278}],"count":3,"endStationId":2101,"endStationName":"石家庄","endTime":1525491060000,"id":414,"startStationId":2401,"startStationName":"太原","startTime":1525059060000,"trainNo":"K707"},"errorCode":null,"errorMsg":null,"status":"OK"}

 四、正则表达式的写法:

五、调试的时候添加一个Debug PostProcessor 调试器

六、在Debug PostProcessor中可以查看到获取的参数结果

七、引用方式:${testValues_g1}   和   ${testValues_g2} 

八、这里还有个小技巧:

返回响应结果顺序都是不变的,想每次获取不同参数的值,怎么办?只需要小小的改动即可

 

九、匹配数字的含义:

* 0 表示随机

* -1 表示全部

* 1表示第一个

* 2表示第二个

* ......

感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
jmeter使用正则表达式匹配多个中的响应结果_第1张图片

 

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取 

你可能感兴趣的:(jmeter,mysql,测试工具,单元测试,测试用例,压力测试,功能测试)