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

posted @ 2018-08-09 17:18  张飞博客  阅读(4440)  评论(0编辑  收藏  举报