Forum Discussion

vinodtiwari10's avatar
vinodtiwari10
New Member
9 years ago

How to save response data in Excel/CSV format in SOAP UI 5.2.1?

Hi,

 

I am getting response when hitting request in XML format. I want to store that XML or save that XML in CSV or Excel format.

 

Regards,

Vinod

  • Layansan's avatar
    Layansan
    New Contributor

    You need to use an Excel API to communicate or manipulate data in the Excel files.

    Download Java Excel API and place the JXL.jar file in the “lib” folder of your SoupUI installation directory. 

     

    Assume the response is like: 

    <Response xmlns="http://localhost/something">
       <content>some content</content>
       <id>100</id>
    </Response>

    Add a Groovy test step

    import jxl.*
    import jxl.write.*
    
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder("RequestStep#ResponseAsXml") // Change RequestStep name
    
    log.info holder.getXml()  // will display /Log the response in Xml
    
    WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/output.xls"))
    WritableSheet sheet = workbook.createSheet("Worksheet 1", 0)
    
    log.info(sheet.isHidden())
    
    xPath1 = "//*:id/text()"     // use xPath to access the value from response
    xPath2 = "//*:content/text()"
    
    log.info holder.getNodeValue(xPath1)
    log.info holder.getNodeValue(xPath2)
    
    Label label = new Label(0, 1, holder.getNodeValue(xPath1)); //column=0,row=1
    sheet.addCell(label);
    Label label1 = new Label(2, 2, holder.getNodeValue(xPath2)); //column=2,row=2
    sheet.addCell(label1); 
    
    workbook.write();
    workbook.close();
    • ddineesh's avatar
      ddineesh
      New Contributor

      its working just fine for me. Thanks a lot for this article.

    • LearnAutomation's avatar
      LearnAutomation
      New Member

      I am able to extract the text from a tag and save it in excel using your code. But it will format the entire excel...I am trying to save the extracted response value in a particular cell in my test case. But when i run the code, all the other values in that particular excel sheet is removed and only the extracted soap response is saved.. can you help please!!