Jmeter數據關聯(如何將返回的內容提取保存到變量)


該章節主要介紹的是jmeter 正則表達式提取器。 

If you need to add HTTP Request sampler with dynamic URL that can be different each time from testing to testing you must use one of the Post-Processors offered by JMeter. I usually use Regular Expression Extractor for this purposes.

如果你想請求的http url地址每次都不一樣. 既請求的內容根據上次請求的返回內容而改變. 則我們需要將上次請求的返回保存到某個變量里,然后在下一次的請求中使用(引用).  這樣第二次的請求的值是動態變化的.  

注意:如果正則表達式還不能滿足您的需求, 請查閱jmeter bsf 處理器,可以自己編寫腳本代碼。

例如 : 

1.  請求  http://www.whoistester.com/a/

2.  返回含有  href="http://blog.whoistester.com"的內容, 通過正則表達式提取器 href="/([^"]+)"

模式寫$1$ , 變量名寫url,  則提取器會將http://blog.whoistester.com的字符串保存到變量名為url的變量里.

4.  下次請求則請求$url 地址. 具體的例子見下圖. 

So, let's imaging that you have "Popular News" web page which contains the links to "News Story" web pages that contains the full texts of news and you want to write a test which will include both "News" page and random "News Story" page.

For this you must include "News" page HTTP Request sampler inside Simple Controller with a Regular Expression Extractor to store random "News Story" page URL to a variable:

regular expression_extractor

Then use the variable with the stored random "News Story" page URL in "News Story" HTTP sampler:

dynamic http_sampler


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM