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

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

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.web

若是你想請求的http url地址每次都不同. 既請求的內容根據上次請求的返回內容而改變. 則咱們須要將上次請求的返回保存到某個變量裏,而後在下一次的請求中使用(引用).  這樣第二次的請求的值是動態變化的.  正則表達式

注意:若是正則表達式還不能知足您的需求, 請查閱jmeter bsf 處理器,能夠本身編寫腳本代碼。express

例如 : dom

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

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

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

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

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:

htm

regular expression_extractor

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

dynamic http_sampler

相關文章
相關標籤/搜索