[TechCorner Challenge #2] A Dispatching script to get responses based on the values in Request Body
Hi Community!
You are already adding so much value to the ReadyAPI Community and all fellow ReadyAPI users are grateful for this! Here’s your chance to contribute more to our TechCorner tag - a collection of helpful ReadyAPI scripts, code samples, tips and other useful content.
Today, I’d like us to focus on ServiceV which is part of ReadyAPI that allows creating virtual services and mock to test things in a sandbox.
Quite often, QA testers need to be able to get certain responses based on parameters in the body. To parse data of an incoming request, you can use a dispatching script. Your task today is to create such a script.
Difficulty:
The steps to follow to complete the task:
-
Create a REST virtual service from the Petstore Swagger specification (https://petstore.swagger.io/v2/swagger.json)
-
Add two responses - ‘OK’ and ‘Bad Request’ for the "POST /v2/pet" operation (VirtAction).
-
Add a dispatching script for the "POST /v2/pet" operation (VirtAction).
The dispatching conditions:
-
If "name" property contains more than 3 characters and the "status" value is one of {available, pending or sold}
return the "OK" response (HTTP status code is 200, body is "{"result": "OK"}" or "<result>OK</result>" depending on the media type of the request)
-
Otherwise, return the "Bad Request" response (HTTP status code is 400, body is "{"error": "Invalid Request"}" or "<error>Invalid Request</error>" depending on the media type of the request).
A sample request:
JSON |
XML |
---|---|
{ |
<Pet> |
Good luck!
Support team answered me that there is no junit impor funcionality in server version, but only in cloud version.
i implemented by myself parsing the xml and using server api to create-update test results.