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

前端 未结 5 779
挽巷
挽巷 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:26

    There are several ways of doing this. One would be creating a Groovy test step with the following script:

    def myOutFile = "C:/Temp/MyOutDir/response.xml"
    def response = context.expand( '${MyTestRequest#Response}' )
    def f = new File(myOutFile)
    f.write(response, "UTF-8")
    
    0 讨论(0)
  • 2021-02-09 14:27

    Try to use SoapUI's tools to select the value of whatever you want. Right click on the groovy editing area, choose Get Data --> your test suite --> your test case --> your test step --> response. This will get you the entire response. You can also dive deeper into the response with this method.

    0 讨论(0)
  • 2021-02-09 14:27

    Check out the answer by McDonald. Best way to save and shoot request.

    http://www.loadui.org/forum/viewtopic.php?f=5&t=16354#p38935

    0 讨论(0)
  • 2021-02-09 14:31

    There is a shorter syntax. Logic is similar what @robert Shared

    def response=context.expand('${TestRequest#RawRequest}')
    new File("c:/testpath/input.xml").write(response)
    

    if you want to reduce it to just one line

     new File("c:/testpath/input.xml").write(context.expand('${TestRequest#RawRequest}')
    

    You can replace RawRequest with whatever you want to save

    Request or Response

    RawRequest is used when you want data replacing the variables used in request

    0 讨论(0)
  • 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')
     }
    }
    
    0 讨论(0)
提交回复
热议问题