harry21
8 years agoOccasional Contributor
How to place the Groovy in centralized Groovy Library and access that class from any script
I have the below Groovy script which i need to place it in centralized Groovy Library and then access the class mentioned in the Groovy from any script in my Ready API Project.
//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()) }
Path: D:\GroovyLib\com\Linos\readyapi\util\property\propertyvalidation
File Name: PropertyValidation
I have just tried the code in Groovy Library.. Please correct this if wrong
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() { //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()) }
I am not sure what to mention in the def static method. I am new to this process and haven't done that yet. Can someone please guide me! I've read the documentation on Ready API! website. But I'm not clear on that.
- Believe that it is sorted out in the thread:
http://stackoverflow.com/questions/43254590/how-to-place-the-groovy-in-centralized-groovy-library-and-access-that-class-from/43269724#43269724