0

I am looking for a example where i have to verify results in previous response and if condition true have to send one set of values in next request.

Ex

If(formtype==1) {

send 1 value in next request for 1 of the body value }

if(formtype==2)

{ send 2 value in next request for 1 of the body value }

Please advise

Sinu Reddy
  • 49
  • 6

2 Answers2

0

You can add conditional handlers using JMeter Post or Pre-Processors. For example, I use JSON Extractor to get response data stored in FORM_DATA and combined with JSR223 PostProcessor Javascript.

...
var formData = JSON.parse(vars.get("FORM_DATA"));
var formtype = formData.formtype;

if(formtype == 1) {
    log.info("data_next_req" + data_next_req);

    // SET vars
    vars.put("DATA_NEXT_REQ", data_next_req);

} else if (formtype == 2){
    log.info("data_next_req_1" + data_next_req_1);
    log.info("data_next_req_2" + data_next_req_2);

    // SET vars
    vars.put("DATA_NEXT_REQ_1", data_next_req_1);
    vars.put("DATA_NEXT_REQ_2", data_next_req_2);
}

Then, on the next request, you can get the value by ${vars-name}.

mtSiniChi
  • 81
  • 2
  • 6
  • Hi,Thanks for response,i tried and extracted data,but when i am sending(${vars-name}) still data not passing into next request – Sinu Reddy Apr 09 '20 at 06:13
  • ```var formData = JSON.parse(vars.get("${form}")); var formtype = formData.form_type; if(formtype == 3) { vars.put("rooms", [ { "idx": 1, "paxes": [ { "title": "Mr", "first_name": "Do", "last_name": "Anh", "age": 30, "type": "adult", "nationality": "VN" }]);``` – Sinu Reddy Apr 09 '20 at 06:19
  • and used ${rooms} in my next request.```{ "prebook_id": "${requestid}", "source_id": "${sourceid}", "adults_count": 1, "child_count": 0, "child_ages": [], "rooms_count": 1, "rooms": ${rooms}``` – Sinu Reddy Apr 09 '20 at 06:21
  • In post / pre processor you can print logs to make sure the result is correct before putting in variables of Jmeter. With the syntax: `vars.put ("varName", value);`. Get the value: `vars.get ("varName") `or `$ {"varName"}`. Note when using `vars.get` and `$`, see more at https://stackoverflow.com/q/46418275/9488752 – mtSiniChi Apr 10 '20 at 03:30
0

Just extract the formtype value using a suitable JMeter's Post-Processor (for HTML response types the most appropriate one would be CSS Selector Extractor) and store it into a JMeter Variable

As the result you will have i.e. ${formtype} JMeter Variable with the value of 1, 2 or whatever is the value of this attribute, the variable can be used directly in the next (and further) requests

The whole process is known as correlation and there is a lot of information about it over the web.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133