官术网_书友最值得收藏!

  • JMeter Cookbook
  • Bayo Erinle
  • 324字
  • 2021-08-05 17:36:29

Using Regular Expression Tester

When trying to extract parts of a server response through a regular matching expression, Regular Expression Tester is your best friend. This component allows you to test your regular expression patterns directly on the sampler response data. Without such a component, it will be daunting to nail down the exact regular expression to fulfill your matching needs. This component comes bundled as part of the View Results Tree listener.

How to do it…

In this recipe, we cover the use of Regular Expression Tester:

  1. Launch JMeter.
  2. Open the ch2_regex_tester.jmx test script located in the scripts/ch2 directory.
  3. Run the test plan.
  4. Click on the View Results Tree listener.
  5. In the bottom-left corner of the View Results Tree listener, select the RegEx Tester option.
  6. In the Regular expression textbox, enter a regular expression to extract information from the server response. We can proceed in the following way:
    • Let's say we wanted to extract the xsrf token; we will use the regular expression 'xsrf':'(\w+)'
    • To extract the search ID, we could use searchId =\s+\"(\d+)\"
    • To extract the user region, we could use region":\s+"(\w+), and so on
  7. Once we have the right regular expression, we could then apply it to the HTTP sampler to correctly execute our test plan. This is shown in the following screenshot:

How it works…

Regular Expression Tester executes directly on the sampler response data since it is bundled as part of the results listener. As a result, we are able to refine our regular expression to our content without needing to re-execute our test script. This is a huge time saver and makes what could otherwise be a daunting task simple, in a sense.

There's more…

Regular expressions are extremely expressive and powerful. It is beyond the scope of this book to cover all the different syntax that could be used. For more information on regular expressions, some good starting resources are:

主站蜘蛛池模板: 吉木乃县| 玛纳斯县| 临湘市| 奉化市| 永康市| 新竹县| 襄城县| 保亭| 梧州市| 鞍山市| 惠来县| 三门县| 基隆市| 永泰县| 闽侯县| 壤塘县| 安吉县| 永川市| 唐海县| 舟曲县| 滨州市| 基隆市| 普陀区| 修水县| 咸丰县| 乃东县| 尼勒克县| 平利县| 五原县| 酒泉市| 德格县| 浏阳市| 姜堰市| 霞浦县| 五寨县| 兴海县| 兴业县| 仙游县| 容城县| 米林县| 青州市|