0
votes

I want to manipulate the request body of HTTP thread based on the data extracted (using 'Regular Expression Extractor') from the previous HTTP response. Here is the scenario:- I have extracted the statusFlag and statusId from 'HTTP request 1' as: Ref name: status Reg. Exp: "statusFlag":"(\w+)","statusId":"(\w+)"

So, first I want to check that the value of statusFlag is 'New' or not. If it is New then I have to proceed and feed statusId in next HTTP request or else display statusFlag mismatch.

Need help. Got stuck badly.

2

2 Answers

1
votes

That's how your Jmeter project should look like. Regular Expression Extractor stores extracted value in ct variable that can be accessed in If Controller as "${ct}" == "yourvalue" and, if true, can be also sent as a part of Request 2 body using the same ${ct} reference.

Jmeter project structure

1
votes

I believe Response Assertion is what you're looking for. Add it after the Regular Expression Extractor and configure it as follows:

  • Apply to: JMeter Variable -> statusFlag (or your reference name)
  • Pattern Matching Rules: Equals
  • Add New as a "Pattern to Test"

    Response assertion

The assertion will check whether "statusFlag" is "New" and if not - it will fail the sampler and report the expected and the actual value.

Optionally you can add If Controller after the Response Assertion, use ${JMeterThread.last_sample_ok} as a condition and place 2nd request as a child of the If Controller - it will be executed only if "statusFlag" is new.

See How to Use JMeter Assertions in Three Easy Steps guide for more information on conditionally setting pass or fail criteria to requests in your JMeter test.