soapui - How to place the Groovy in centralized Groovy Library and access that class from any script -


i have below groovy script need place in centralized groovy library , access class mentioned in groovy script in ready api project path: d:\groovylib\com\linos\readyapi\util\property\propertyvalidation

//change name of properties test step below def step = context.testcase.teststeps['properties']  //parse xml have in script def parsedxml = new xmlslurper().parse(file)  //get error details response map def errordetails = parsedxml.'**'.findall { it.name() == 'integrationserviceerrorcode'}.inject([:]){map, entry ->    map[entry.errorcode.text()] = entry.description.text(); map    } log.info "error details response  : ${errordetails}"  def failuremessage = new stringbuffer()  //loop thru properties of property step , check against 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 not have error code ${key}")    } } if (failuremessage.tostring()) {   throw new error(failuremessage.tostring()) }  

i have created code in library below:

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 name of properties test step below def step = context.testcase.teststeps['properties']  //parse xml have in script def parsedxml = new xmlslurper().parse(file)  //get error details response map def errordetails = parsedxml.'**'.findall { it.name() == 'integrationserviceerrorcode'}.inject([:]){map, entry ->    map[entry.errorcode.text()] = entry.description.text(); map    } log.info "error details response  : ${errordetails}"  def failuremessage = new stringbuffer()  //loop thru properties of property step , check against 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 not have error code ${key}")    } } if (failuremessage.tostring()) {   throw new error(failuremessage.tostring()) }  

i not sure mention in def static method. new process , haven't done yet. can please guide me! i've read documentation on ready api! website. i'm not clear on that.

readyapi allows users create libraries , put them under script directory , reuse them needed.

please note that, readyapi not allow have groovy script in script directory, instead should groovy classes.

looks trying convert script, answered 1 of previous questions, class.

here there variables available in groovy script soapui. so, needs passed library class. instance, context, log common.

and there can more parameters related method well. in case, need pass file, property step name etc.

here groovy class isconverted script. , method can non-static or static. go non-static.

package com.linos.readyapi.util.property.propertyvalidation  class propertyvalidator {      def context     def log      def validate(string stepname, file file) {         //change name of properties test step below         def step = context.testcase.teststeps[stepname]          //parse xml have in script         def parsedxml = new xmlslurper().parse(file)          //get error details response map         def errordetails = parsedxml.'**'.findall { it.name() == 'integrationserviceerrorcode'}.inject([:]){map, entry ->    map[entry.errorcode.text()] = entry.description.text(); map    }         log.info "error details response  : ${errordetails}"          def failuremessage = new stringbuffer()          //loop thru properties of property step , check against 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 not have error code ${key}")             }         }         if (failuremessage.tostring()) {             throw new error(failuremessage.tostring())         }      } } 

hope aware copy above class. note has package name. copy in right directory. have suggestion here regarding package name long, can change com.linos.readyapi.util. of course, upto you.

now here how can use / call above class or methods groovy script test step of test case in different soapui projects:

groovy script step

import com.linos.readyapi.util.property.propertyvalidation.propertyvalidator  def properties = [context:context, log:log] propertyvalidator //you need have file object here properties.validate('properties', file) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -