Store request/response files in local directory with Groovy teststep in soapUI

前端 未结 5 778
挽巷
挽巷 2021-02-09 14:07

Through a groovy teststep in soapUI i want all request and response files to be stored in a local directory with system date.

The groovy teststep in soapUI:



        
5条回答
  •  有刺的猬
    2021-02-09 14:36

    More useful if we should save an error in Response:

    import com.eviware.soapui.support.XmlHolder
    import java.text.MessageFormat
    import org.apache.commons.lang.ObjectUtils
    
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def retrieve = groovyUtils.getXmlHolder("MyTestRequest#Response" )
    
    if (!ObjectUtils.equals(retrieve.getNodeValue("//*:xpath"), "string")){
     def currentTime = System.currentTimeMillis()
     def fullFilePath = context.expand('${projectDir}') + File.separator + "Fail-"+currentTime+".xml"
     def reportFile = new File(fullFilePath)
     if (!reportFile.exists())
     {
      reportFile.createNewFile()    
      reportFile.append((Object)retrieve.getPrettyXml(), 'UTF-8')
     }
    }
    

提交回复
热议问题