Forum Discussion
yes.. this is the documentation which i read.. not clear in that.. doesn't have detailed information i felt
Edited my post..
Thanks for the reformatting I think I understand now...
Your code was missing a couple of closing brackets, this might of just been a cut and paste error. Also you will need to pass in the context and log Ready API variables and your file variable to your static method. Assuming your code is now:
package com.Linos.readyapi.util.property.propertyvalidation import com.eviware.soapui.support.GroovyUtils import groovy.lang.GroovyObject import groovy.sql.Sql class PropertyValidation { def static propertystepvalidation(File file, context, log) { //Change the name of the Properties test step below def step = context.testCase.testSteps['Properties'] //Parse the xml like you have in your script def parsedXml = new XmlSlurper().parse(file) //Get the all the error details from the response as map def errorDetails = parsedXml.'**'.findAll { it.name() == 'IntegrationServiceErrorCode' }.inject([:]) { map, entry -> map[entry.ErrorCode.text()] = entry.Description.text(); map } log.info "Error details from response : ${errorDetails}" def failureMessage = new StringBuffer() //Loop thru properties of Property step and check against the response step.properties.keySet().each { key -> if (errorDetails.containsKey(key)) { step.properties[key]?.value == errorDetails[key] ?: failureMessage.append("Response error code discription mismatch. expected [${step.properties[key]?.value}] vs actual [${errorDetails[key]}]") } else { failureMessage.append("Response does not have error code ${key}") } } if (failureMessage.toString()) { throw new Error(failureMessage.toString()) } } }
Save this in a file called "PropertyValidation.groovy"
From your message I think you may have the directory wrong. Just set the script library to “D:\GroovyLib”
Now because your class has specified it's package to be com.Linos.readyapi.util.property.propertyvalidation place your file "PropertyValidation.groovy" in the directory:
D:\GroovyLib\com\Linos\readyapi\util\property\propertyvalidation
Think of the package as the sub-directory within the script library directory.
You should now be able to call your static method from any ReadyAPI groovy script window as such (note the import statement, this is just needed once at the top of each script that calls your static function):
import com.Linos.readyapi.util.property.propertyvalidation.PropertyValidation import java.io.File def file // Obtain your file object however you need to PropertyValidation.propertystepvalidation(file, context, log)
EDIT: To add the passing in of parameters into static method, see posts below.
Related Content
- 7 years ago
- 9 months ago
Recent Discussions
- 5 days ago
- 9 days ago