rao
hahahaha! well I don't know about 'easier' - but it certainly allows for tailoring your test cases to do exactly what you need - which the OTB functionality doesn't (as good as the OTB functionality actually is) and it's also a lot more fun when you solve a problem!
I have another question - based on your previous script to build the request (using groovy) and adding this script assertion into that script. I was going to create a new subject post - but honestly? this is so specific - I couldn't think of a decent title - and I'm unsure if anyone else would have this specific issue - so I just continued on this post. If you feel this needs a separate post, I will do so.
So - in summary I wanted to add in the script assertion you've given me, to the groovy script you've already provided to build the GET request. I've managed to update the script so it works, if I don't parameterize the asserted value in the script assertion - if I do parameterize it, the assertion now fails - see below for the updated script - the bit I'm concerned with is in red text
//script courtesy of Rao of https://community.smartbear.com
//import decs
import groovy.json.*
import wslite.rest.*
def serviceHost = context.expand ('${#Project#TestEndpoint}') //'https://whatevs.azurewebsites.net'
//Below to handle template parameter, additional $ required before
def getNamespaceDatasetPath = '''/api/1/${namespace}/${dataset}'''
//define all template param values as shown below
def binding = [namespace : context.expand( '${#TestCase#namespace}') , dataset : context.expand('${#TestCase#dataset}')]
//def binding = [namespace : 'certification-nomenclature', dataset : 'certification-nomenclature']
def template = new groovy.text.SimpleTemplateEngine().createTemplate(getNamespaceDatasetPath)
def queryParams = [:]
//Get the properties of Property Test step
context.testCase.testSteps["Properties"].properties.each {
queryParams[it.key] = it.value.value
}
def client = new RESTClient(serviceHost)
def response = client.get(path: template.make(binding) as String,
accept: ContentType.JSON,
query : queryParams
)
assert response.statusCode == 200
log.info groovy.json.JsonOutput.prettyPrint(response.text)
def object = new JsonSlurper().parseText(response.text)
assert object.header.success == true
//the next four lines are the original script assertion
assert response.text, 'Request parameter is correct'
//def json = new groovy.json.JsonSlurper().parseText(response.text) //this line isn't needed as I already pass the response to the object variable above
assert object.data.CertificateType_Code.every{'C'== it}
//I want to replace the line above with the next line so I parameterize the value being asserted on
//assert json.data.CertificateType_Code.every{context.expand('${REST Request#CertificateType_Code}') == it}
def count = 'count'
def step3 = context.testCase.testSteps['Properties2']
//step3.propertyNames?.each { step3.removeProperty(it) }
def prop3 = step3.hasProperty(count) ? step3.getProperty(count) : step3.addProperty (count)
prop3.value = object.meta.count
I think I understand why the script is failing - the script is NOT recognising the teststep name of 'REST Request' <-- this is the name of the groovy step that contains the above groovy - but I don't know why it's not recognising the test step name.
The script assertion works if I don't parameterize the assertion value - so I know this is the problem - can anyone advise?
I should highlight that I did a quick check to see what ReadyAPI! recognised the test step name as using the 'Get Data' function to point to the groovy step - but it created a line of code that indicated ReadyAPI! sees the step as 'REST Request', so I don't know why this parameterized assertion isnt working.
I've attached a screenshot so you can see the test case just to add a little clarity!
thanks to all!
richie