我需要一些使用正则表达式提取器获取值的帮助.我没有任何价值 [英] I need some help in getting a value using regular expression extractor. I am getting no value out

查看:151
本文介绍了我需要一些使用正则表达式提取器获取值的帮助.我没有任何价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JMeter的新手,正在学习使用正则表达式提取器进行练习.

I am new to JMeter and learning, practicing using the Regular expression extractor.

我已经使用记录仪创建了一个测试计划.我已经添加了一个正则表达式提取器,因为我想将网页中的您的帐户"文本转换为变量.

I have created a test plan using the recorder. I have added a regular expression extractor as i want to get the text "Your Account" from my webpage into a variable.

我使用调试采样器检查我的变量中是否有"Your Account"值. 运行测试时,我在变量中看到默认值"your_account_NONE".

I use the debug sampler to check if my variable has got the value "Your Account" in there. I am seeing the default value "your_account_NONE" in the variable when i run the test.

我认为我的正则表达式是错误的.请指教,帮助.谢谢.

I think my regular expression is wrong. Please advise, help. Thanks.

我知道测试运行时我在正确的页面上,因为我已经插入了一个响应声明,要测试的模式设置为您的帐户" 断言通过.如果我将模式更改为您的帐户tttttttttt" 断言失败.所以我在正确的页面上. 我想将您的帐户"值放入一个变量中.

I know I am on the correct page when the test runs because i have inserted a Response Assertion, pattern to test is set to "Your Account" The assertion passes. If i change to pattern to "Your Accounttttttttttt" The assertion fails. So I am on the correct page. I would like to get the value "Your Account" into a variable.

我的正则表达式具有以下配置:

My regular expression has the following config:

Reference Name: YourAccount
Regular Expression: <h1>"Your "   <span>Account</span> </h1>
Template: $1$
Match: 1
Default Value: your_account_NONE

我的测试计划如下:

Test Plan
   Thread Group
   Http Request defaults (Server Name: a URL to go to homepage)
   Recording Controller
      Http Cache Manager
      Http Cookie Manager
      Http request (sign in)
      http request (Homepage)
         Regular Expression Extractor
         Response Assertion

推荐答案

此问题的解决方案是使用正则表达式字符分组.然后在正则表达式提取器的模板"部分中引用它们.

The solution to this issue is to use Regular Expression Character Groupings. These are then referenced in the "Template" portion of the regular expression extractor.

只需将所需的匹配部分用()括起来.

Simply encase the part of the match you want in ().

例如:

 Regular Expression: <h1>"(Your )"   <span>(Account)</span> </h1>

上面的行在您的"和帐户"周围放置了一个字符分组. 然后,要将其构建到一个参考变量中,您希望您的模板"是这样的:

The line above places a character grouping around "Your " and "Account". Then, to build that into one reference variable you want your "Template" to be this:

$1$$2$

这会将两个字符分组连接到变量"YourAccount"中.

That will concatenate the two character groupings into the variable "YourAccount".

这篇关于我需要一些使用正则表达式提取器获取值的帮助.我没有任何价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆