Forum Discussion
nmrao
9 years agoCommunity Hero
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
Here is documentation link if you just want to go thru it:
https://support.smartbear.com/readyapi/docs/servicev/configure/scripting.html
ricardo_moura
9 years agoOccasional 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