Forum Discussion
Ive typed and deleted reaponse out 3 times, but im a bit confused!
So you have an endpoint you want to hit which will give you a perfectly valid response, but instead of the expected, valid response, you want to stub the response to be something different?
Can you just explain a bit more please? I must be missing something vital, cos im just thinking..."why?"
Cheers!
Rich
> So you have an endpoint you want to hit which will give you a perfectly valid response, but instead of the expected, valid response, you want to stub the response to be something different?
Correct!
There is some backend logic that gets triggered and invoked whenever the endpoint gets called. I need this logic to be triggered in order to proceed in a workflow I am testing. I don't need the actual response that is returned from the actual service though. I'll be using a mocked response (which is different from what the actual service returns, the response itself is a bunch of configuration data the UI consumes that drives certain UI behavior, I'm testing a different set of configuration than what the actual service usually returns).
- richie3 years agoCommunity HeroHey eric_the_tester,
Ok...wow!
Never actually tried stubbing out a whole response before!
If we're keeping everything contained within ReadyAPI only i think the way to do this would be to use the Event Handlers (think pre-processors and post-processors in jmeter or postman, etc.).
There is a replaceAll() method ive used before in events when ive wanted to change the content of the reaponse ive received before my assertions kick in (so post-processor), but ive never used it to replace a whole payload with a different one!
Start having a look at the events handlers functionality and i'll start thinking about the groovy script youll need. Now im thinking about it, i think i might know what to do with the groovyscript, BUT! the important bit is getting the groovy script right....which ChrisAdams or one of other real coders will be able to do, better, quicker and more efficiently than i. What i knock out may work, but it wont be pretty!
Cheers,
Rich- ChrisAdams3 years agoChampion Level 3
Hi,
I've never used event handlers.
But if I wanted to mock out a whole response for use later in the test, instead of the response from a given service, I would use a Groovy script step.
All the Groovy script would do is either, return a mocked response built in the Groovy script, or as I have done for comparing repsonses is have the Groovy script read the contents of a text file that contains the mocked response and return that.
The Groovy is not difficult for either as you're basically just returning a string.
What I have not tried is overwriting a response with a mocked one.
Have a think what's preferable and then maybe I'll be able to write something for you.
Related Content
Recent Discussions
- 5 days ago
- 10 days ago