Forum Discussion
- nmrao
Champion Level 2
Well can be done. Any specific that you have?
Here is documentation link if you just want to go thru it:
https://support.smartbear.com/readyapi/docs/servicev/configure/scripting.html- ricardo_mouraOccasional Contributor
i did the code right now:
i use above script to put on "script log" Pass or Fail information to each json field to be validate
the script works, but i have a problem:
my original switch case have a lot of cases and each request have a lot of validations,
if i do this on this way, the script will be to big and hard to maintain, Ideally I would have a validation file for each case, but i not know how.
my actual onRequest Script:
import com.eviware.soapui.support.XmlHolder import groovy.json.* //define request def request = mockRequest.getRequestContent() //define "json" which will be the name of my variable def json = new JsonSlurper().parseText(request) //define the request identificator for ConsultStatement requests def identificator = json.address.postalCode //define file directory def directory = "c:\\dump" def timestamp = System.currentTimeMillis() def requestFile = new File(directory, identificator + ".xml") switch (identificator){ case '063842134': requestFile.write("PostalCode: " + identificator) if (json.address.streetName == "test avenue"){ requestFile.append("\nPass - streetName: " + json.address.streetName) } else { requestFile.write("\nFail - streetName: " + json.address.streetName + ", expected: test avenue") } if (json.address.number == "123"){ requestFile.append("\nPass - number: " + json.address.number) } else { requestFile.append("\nFail - number: " + json.address.number + ", expected: 123") } // if-else will be repeat for all request fields // next case contain same validations... }
the output file should help testers to identify defects
- nmrao
Champion Level 2
Well. Below pointers on quick glance:
1. Not sure the reason behind appending pass / fail message for the request in Mock Service. IMO, it may not be useful.
2. Instead, catch error and send the reply accordingly and put assertions in the test case. That way, it would be easy to know if the application is behaving correct or not.
3. Keep less if / else conditions (if at all possible) to avoid confusion and that could also lead potential logic issues.
4. Modularize the code instead of putting lots of code, referring to "case", for example use a method / function and just call that