how to make jmeter to select unique values from re

2020-02-07 12:31发布

问题:

I have the following response from JMeter:

{"tot_cnt":{"tc":"41651","rpp":"100","pdid":"1594"},"mg":[{"id":"683","rsd":"6-May-13 \/ 6-May-13","col":"black","cc":"c_197","pn":"old_NEXUS MARKETING CAMPAIGNS-PERMANENT","loc":"PTD - 07 \/ 18 \/ BX","isf":"1","isl":"0","tq":"180","pi":"0","st":"2","dsid":"527","cid":"1917","iq":"0","wid":"WI\/txq8xa56","inv":null,"rbp":"0","pdid":"106","di":"0","pl":"0","spl":null},{"id":"17670","rsd":"6-Jun-13 \/ 6-Jun-13","col":"black","cc":"c_197","pn":"old_NEXUS MARKETING CAMPAIGNS-PERMANENT","loc":"PTD - 07 \/ 18 \/ BX","isf":"1","isl":"0","tq":"180","pi":"0","st":"2","dsid":"527","cid":"1917","iq":"0","wid":"WI\/ckwu5qe8","inv":null,"rbp":"0","pdid":"106","di":"0","pl":"0","spl":null},{"id":"22","rsd":"22-Jul-13 \/ 22-Jul-13","col":"black","cc":"c_1884","pn":"old_THE ORTHODONTIC CLINC","loc":"15 - 34 \/ 0N \/ RS","isf":"1","isl":"1","tq":"1","pi":"0","st":"2","dsid":"15","cid":"1992","iq":"0","wid":"WI\/tldj53ky","inv":null,"rbp":"0","pdid":"1582","di":"0","pl":"0","spl":null},{"id":"686","rsd":"29-Jul-13 \/ 29-Jul-13","col":"black","cc":"c_197","pn":"old_NEXUS MARKETING CAMPAIGNS-PERMANENT","loc":"PTD - 07 \/ 18 \/ BX","isf":"1","isl":"0","tq":"180","pi":"0","st":"2","dsid":"527","cid":"1917","iq":"0","wid":"WI\/n4olde1g","inv":null,"rbp":"0","pdid":"107","di":"0","pl":"0","spl":null},{"id":"73","rsd":"5-Aug-13 \/ 5-Aug-13","col":"black","cc":"c_2357","pn":"old_KCA DEATAG","loc":"338 - 34 \/ 0N \/ RS","isf":"1","isl":"1","tq":"1","pi":"0","st":"2","dsid":"338","cid":"1914","iq":"0","wid":"WI\/zdqbx1zx","inv":null,"rbp":"0","pdid":"1578","di":"0","pl":"0","spl":null},{"id":"137","rsd":"5-Aug-13 \/ 5-Aug-13","col":"black","cc":"c_1219","pn":"old_TYPHOO - J01-TYPHOO- JULY 2013","loc":"56 - 24 \/ 81 \/ L3","isf":"1","isl":"0","tq":"2","pi":"0","st":"2","dsid":"56","cid":"2090","iq":"0","wid":"WI\/azdtc77c","inv":null,"rbp":"0","pdid":"1086","di":"0","pl":"0","spl":null},{"id":"70","rsd":"12-Aug-13 \/ 12-Aug-13","col":"black","cc":"c_2394","pn":"old_SKF UK LTD","loc":"338 - 34 \/ 0N \/ RS","isf":"1","isl":"1","tq":"1","pi":"0","st":"2","dsid":"338","cid":"1914","iq":"0","wid":"WI\/45uzkvp3","inv":null,"rbp":"0","pdid":"1556","di":"0","pl":"0","spl":null},{"id":"1253","rsd":"12-Aug-13 \/ 12-Aug-13","col":"black","cc":"c_2349","pn":"old_JUST TILES","loc":"PTD - 34 \/ 0M \/ MR","isf":"1","isl":"0","tq":"1","pi":"0","st":"2","dsid":"528","cid":"1955","iq":"0","wid":"WI\/ofunwm5s","inv":null,"rbp":"0","pdid":"1559","di":"0","pl":"0","spl":null},{"id":"1320","rsd":"12-Aug-13 \/ 12-Aug-13","col":"black","cc":"c_2073","pn":"old_NEW COLLEGE SWINDON SUMMER CAMPAIGN","loc":"PTD - 34 \/ 0N \/ RS","isf":"1","isl":"0","tq":"1","pi":"0","st":"2","dsid":"528","cid":"1955","iq":"0","wid":"WI\/gpp1dejn","inv":null,"rbp":"0","pdid":null,"di":"0","pl":"0","spl":null},{"id":"27","rsd":"19-Aug-13 \/ 19-Aug-13","col":"black","cc":"c_2138","pn":"old_WIRED STUDIO PEAK MEGA REAR","loc":"15 - 34 \/ 0N \/ RS","isf":"1","isl":"1","tq":"1","pi":"0","st":"2","dsid":"15","cid":"1992","iq":"0","wid":"WI\/b5m0iyuc","inv":null,"rbp":"0","pdid":"1597","di":"0","pl":"0","spl":null},{"id":"561","rsd":"19-Aug-13 \/ 19-Aug-13","col":"black","cc":"c_3737","pn":"old_LONDON ROAD BRIDGE SCHEME DERBY CITY COUNCIL","loc":"PTD - 83 \/ 4I \/ WB","isf":"1","isl":"0","tq":"1","pi":"0","st":"2","dsid":"527","cid":"1917","iq":"0","wid":"WI\/1s1xaqxw","inv":null,"rbp":"0","pdid":"2574","di":"0","pl":"0","spl":null}

I used (?=(?:(?!isf).)*?isf":"1)(?=(?:(?!isl).)*?isl":"0)(?=(?:(?!st).)*?st":"2)"id":"(\d+) regular expression to select the required id.

When I run the test using 5 users, during few tests same id is selected for different iterations causing error.

I need to make jmeter extract some unique values from response for each iteration. How can I do that? Thanks in advance.

回答1:

Interim solution:

In your "Regular Expression Extractor", keep the setting "Match No." as "0"

Even tough the ID's will not be unique but it will randomly select different values rather than selecting same value again & again.

Complete solution:

write all the valid "ID" to CSV file in "1st Thread group" using Bean Shell Sampler & then
In the "2nd Thread Group" run the test using created CSV with unique values for each request.

While analyzing the results you can ignore 1st thread group.

Hope this will help.



标签: jmeter