Get Knowledge from Video instead of Content:

Saturday, 1 October 2016

RegEx in JMeter

How to use Reg-Ex in JMeter?
You can add Reg-Ex component under those request samplers whose response contain a dynamic value.

1. Right Click on request
2. Add->Post-Processors->Regular Expression Extractor
Apache JMeter Regular Expression


3. Provide Reference Name, Regular Expression Statement (along with unique left and right boundaries), template, Match No. and Default Value.
Apache JMeter Regular Expression

4. Choose where this Reg-Ex is applicable. 
  • Main sample only: Search in the main sample only
  • Sub-samples only: Search in the sub-samples only
  • Main sample and sub-samples: Search in both sample and sub-samples
  • JMeter Variable: Assertion is to be applied to the contents of the named variable

5. You need to specify "Field to check" where dynamic value can be found.
  • Body: In the body of the response
  • Body (unescaped): In the body of the response, with all HTML escape codes replaced. Note that this option highly impacts performances, so use it only when absolutely necessary and be aware of its impacts
  • Body as a Document - the extracted text from various type of documents via Apache Tika. Note that this option highly impacts performances, so use it only when absolutely necessary and be aware of its impacts
  • Request Headers: In request header
  • Response Headers: In response header
  • URL: In request URL
  • Response Code: HTTP status code
  • Response Message: In response body as a message
          6. Match No.: Reg-Ex matching is applied to all qualifying samples. For example, if there are the main sample and 2 sub-samples, each of which contains a single match for the regex, (i.e. 3 matches in total). For match number = 2, Sub-samples only, the extractor will match the 2nd sub-sample. For match number = 2, Main sample and sub-samples, the extractor will match the 2nd sub-sample (1st match is the main sample). For match number = 0 or negative, all qualifying samples will be processed. For match number > 0, matching will stop as soon as enough matches have been found.

          7. Default Value: If the regular expression does not match, then the default value will be set to a reference variable.

          Tip: You can use debug sampler to check captured reg-ex value.

          Related Topic:


          No comments :

          Post a Comment