Forum Discussion

SR1's avatar
SR1
Occasional Contributor
5 years ago

Add the responses to a list in Mockservice's OnRequestScript and refer it in the Project's testsuite

I have a mockservice that listens on port 80 and receive the JSON callback from a API server. Rightnow im using the below code in OnrRequest script to get the response and assign it to a project's property like below.

mockRunner.mockService.project.setPropertyValue("ResponseBody",requestBody)

In the testsuite, i poll for the "ResponseBody" and when it gets some value then I read the responsebody value and process it in the testsuite. After processing i will move to the next hit. The polling/waiting is consuming time and instead of waiting for the callback response i want to complete all the hits and finally process the callback responses collected in the mockservice. Is there anyway to collect all responses in the mockservice and refer the list in the testsuite?

i tried below but Im not sure whether its correct or not.
In the Mockservice's "Start Script" i put the below code
def mockList=[]
context.setProperty("MockResponseList",mockList)

In the Mockservice's "OnRequest Script" i put the below code
def requestBody = mockRequest.getRequestContent()

def jsonResponseList=context.getProperty("MockResponseList")
jsonResponseList.add(requestBody)

1)but i dont know how to refer the above jsonResponseList in the project's testsuites
2)jsonResponseList will stay the same for each OnrequestScript call? or it will be unique?
3)Is there anyway to collect all responses in the mockservice and refer the list in the testsuite?
4)What is the best way to collect all responses and process in one go?

No RepliesBe the first to reply