- 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:
- Launch JMeter.
- Open the
ch2_regex_tester.jmx
test script located in thescripts/ch2
directory. - Run the test plan.
- Click on the View Results Tree listener.
- In the bottom-left corner of the View Results Tree listener, select the RegEx Tester option.
- 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
- Let's say we wanted to extract the
- 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:
- 大數據技術基礎
- Creating Mobile Apps with Sencha Touch 2
- Neural Network Programming with TensorFlow
- 大數據時代下的智能轉型進程精選(套裝共10冊)
- 數據驅動:從方法到實踐
- Spark大數據分析實戰
- LabVIEW 完全自學手冊
- 視覺大數據智能分析算法實戰
- Power BI智能數據分析與可視化從入門到精通
- 數據庫應用系統開發實例
- 數據庫技術及應用
- 大數據數學基礎(Python語言描述)
- 算力芯片:高性能CPU/GPU/NPU微架構分析
- 從零進階!數據分析的統計基礎(第2版)
- Hands-On Java Deep Learning for Computer Vision