本文主要是介绍jmeter 正则表达式提取器(表达式格式的问题),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:观察下面这两个是否是一致的:
"code":"00000000",
"code" : "00000000",
答案: 是不一致的,第二个相比第一个多了空格。要注意"code" : "(.*?)", 之间的间隔和格式,如果"code" : "(.*?)",间隔和服务器返回的code格式不一致,会导致无法正则表达式提取器无法取到值
PS:正则表达式没有找到匹配的结果,也没有缺省值的时候,使用变量的地方会直接显示${变量名}
1、 所以最好在该正则表达式提取器中设置enable debug,路径:点击该正则表达式提取器,然后点击最上方菜单栏 帮助->enable debug,然后运行该线程组,观察底部运行情况:
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Pattern = \$(\d+)\$
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: template = $1$
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Template item count: 1
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Integer '1'
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: RegexExtractor processing result
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Regex = "code" : "(.*?)",
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Input = {
"score" : 995,
"algorithmTime" : 0,
"code" : "00000000",
"timeConsumed" : 25
}
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: RegexExtractor: Match found!
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: RegexExtractor: Template piece 1 (Integer)
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Regex Extractor result = 00000000
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: template = $1$
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Template item count: 1
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Integer '1'
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: RegexExtractor processing result
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Regex = "code" : "(.*?)",
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Input = {
"score" : 995,
"algorithmTime" : 0,
"code" : "00000000",
"timeConsumed" : 25
}
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: RegexExtractor: Match found!
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: RegexExtractor: Template piece 1 (Integer)
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Regex Extractor result = 00000000
2、比如下面从debug中直接复制,然后进行修改,保证不能出错
2017/11/07 16:38:50 DEBUG - jmeter.extractor.RegexExtractor: Input = {
"score" : 995,
"algorithmTime" : 0,
"code" : "00000000",
"timeConsumed" : 25
}
"score" : 995,
"algorithmTime" : 0,
"code" : "00000000",
"timeConsumed" : 25
}
找到code一行,复制
"code" : "00000000",
修改为:
修改为:
"code" : "(.*?)",
参考:
http://www.cnblogs.com/wuyepiaoxue/p/5661194.html
http://www.51testing.com/html/33/n-860233.html
http://www.cnblogs.com/imyalost/p/6485754.html
http://www.51testing.com/html/33/n-860233.html
http://www.cnblogs.com/imyalost/p/6485754.html
http://blog.csdn.net/meami/article/details/50495148
这篇关于jmeter 正则表达式提取器(表达式格式的问题)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!