-1

I need to execute a http POST request then based on response I want to execute two different http requests. Which request to execute next, will be decided based on response objects from previous response. I need a Bean shell script which will do this job (or any alternative solution). Note: I have already extracted values from response using Regular Expression Extractor, but I am stuck how to write logic in bean shell which will decide which request to execute next.

Thanks in advance...

1 Answers1

0

You no need to use BeanShell, you can solve the issue using If Controller.

Keep your Test Plan as follows:

Test Plan
....Thread Group
........HTTP Request - 1
............Reg Ex Extractor // to retrieve value and store it in "myVar"
........If Contoller //write condition to match first Http Request (A)
............HTTP Request A
........If Controller //write condition to match second request (B) condition
............HTTP Request B

So, If controller child's (HTTP requests) only gets executed if the condition returns TRUE

Examples:

"${myVar}" == "\${myVar}"

Or

"${myVar}" != "\${myVar}"
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • Hi Naveen, Below is the use case, We need to make a http request providing valid arguments. Parse the response of the service. This will return JSON object which contains: enrollment_state i.e. (A, B, C, D) and enrollment_key. After parsing the response, we need to assert if enrollment_state: For A or B from the above request, then we need to do run the next request i.e ( fetchProvisionData) and pass the enrollment_key in the payload of the request For C & D, We need basically to do request again and note that enrollment_key will not be returned. – santosh Nov 23 '16 at 13:46
  • is the comment related to above question? If yes, can you please add the details of the test plan, json response in screenshots? If not, post a new question with above details. – Naveen Kumar R B Nov 23 '16 at 14:07
  • Yes, this is related to the same question. for request A below is the json – santosh Nov 23 '16 at 15:53
  • For request A below is the json { "carrierSubscriberNetworkId" : "${carrierSubscriberNetworkId}", "hardwareId" : "${hardwareId}" } , in response to this we will get value of enrollmentState and enrollmentKey. The JSON object which contains: enrollmentState i.e. (A, B, C, D) and enrollmentKey, I am aware that we can use 4 if controls i.e. for (A, B, C, D) For A or B from the above request, then we need to run the next request i.e ( fetchProvisionData) and pass the enrollmentKey in the payload of the request For C & D – santosh Nov 23 '16 at 16:01
  • can you edit the question with these details? It is hard to read. also add your test plan screenshot image – Naveen Kumar R B Nov 23 '16 at 16:03