Domanda

Is there a way to parse all the available rows in an Excel datasource of SoapUI Pro and feed it to a repeatable schema complex type of SOAP request other than programmatically reading it and inserting values into a SOAP request xml document with a Groovy script? i.e.:

       Col1  Col2  Col3
Row1   C11   C12   C13     
Row2   C21   C22   C23
Row3   C31   C32   C33

Into:

<soapenv:Envelope xmlns:soapenv="http://my.ns.com">
   <soapenv:Header/>
   <soapenv:Body>
     <Rows>
       <Row>
         <Col1>C11</Col1>
         <Col2>C12</Col2>
         <Col3>C13</Col3>             
       </Row>
       <Row>
         <Col1>C21</Col1>
         <Col2>C22</Col2>
         <Col3>C23</Col3>             
       </Row>
       <Row>
         <Col1>C31</Col1>
         <Col2>C32</Col2>
         <Col3>C33</Col3>             
       </Row>
     </Rows>    
   </soapenv:Body>
</soapenv:Envelope>
È stato utile?

Soluzione 2

I was managed to write a script to do just that with the help of JExcel (unpack and place jxl.jar in soapui-installation-path/bin/ext) -- this assumes that your Soap request document contains everything except the Row elements:

import jxl.*;

def workbook = Workbook.getWorkbook(new File("C:\\Path\\To\\YourExcel.xls"))
def sheet = workbook.getSheet(0)

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "requestStep#Request" )
def rowsNode = holder.getDomNode("//Rows") // return a Rows Node
def updateRequestDoc = rowsNode.getOwnerDocument() // return a Document

// Clean up previous inserts
while (rowsNode.hasChildNodes()) {
   rowsNode.removeChild(rowsNode.getFirstChild())
}

// Skip the header
for (int i = 1; i < sheet.getRows(); i++) {
    Cell[] cells = sheet.getRow(i)
    if (cells.length > 0) {
        // Append Row node to the Rows Node
        def rowElement = updateRequestDoc.createElement("Row")
        rowsNode.appendChild(rowElement)

        // Populate the Row node with all the "available" cells for that row (blank elements are skipped)
        for (int j = 0; j < cells.length; j++) {
            String cellContent = cells[j].getContents()

            // Select the tag name based on the index in which it is parsed from the Excel document
            if (!cellContent.isEmpty()) {
                String tagName = null               
                switch(cells[j].getColumn()) {
                    case 0:
                        tagName = 'Col1'                    
                        break

                    case 1:
                        tagName = 'Col2'                        
                        break

                    case 2:
                        tagName = 'Col3'                        
                        break


                    default:
                        break

                }

                if (tagName != null && !tagName.isEmpty()) {

                    def currentElement = updateRequestDoc.createElementNS(tagName)
                    def currentTextElement = updateRequestDoc.createTextNode(cellContent)
                    currentElement.appendChild(currentTextElement)

                    // Get the last Row node and add the field element to it
                    def rowNode = rowsNode.getLastChild()
                    rowNode.appendChild(currentElement)
                }
            }
        }           
    }
}

holder.updateProperty(true)
workbook.close()

Altri suggerimenti

A datasource test step is intended to be read one line at a time, and used one line at a time. It can be done, but it would be difficult. You are essentially trying to fit a square peg into a round hole.

You would have to do something like:

  1. DataSource
  2. Groovy step that takes the current line from the DataSource and appends it to the Request (step 4). Google XmlSlurper() for idea how to do it.
  3. Data Loop back to step 1.
  4. Soap Request
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top