Xml 在SoapUI中将整个Excel数据源解析为SOAP请求的提要

Xml 在SoapUI中将整个Excel数据源解析为SOAP请求的提要,xml,excel,soap,groovy,soapui,Xml,Excel,Soap,Groovy,Soapui,除了用Groovy脚本以编程方式读取并将值插入SOAP请求xml文档之外,是否有其他方法可以解析SoapUI Pro的Excel数据源中的所有可用行,并将其提供给可重复的模式复杂类型的SOAP请求?i、 e: Col1 Col2 Col3 Row1 C11 C12 C13 Row2 C21 C22 C23 Row3 C31 C32 C33 进入: 我在解包的帮助下编写了一个脚本,并将jxl.jar放在soapui安装路径/bin/

除了用Groovy脚本以编程方式读取并将值插入SOAP请求xml文档之外,是否有其他方法可以解析SoapUI Pro的Excel数据源中的所有可用行,并将其提供给可重复的模式复杂类型的SOAP请求?i、 e:

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


我在解包的帮助下编写了一个脚本,并将jxl.jar放在soapui安装路径/bin/ext中——这假设您的Soap请求文档包含除行元素以外的所有内容:

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()

数据源测试步骤旨在一次读取一行,一次使用一行。这是可以做到的,但很难做到。你基本上是想把一个方形的钉子装进一个圆孔里

您必须执行以下操作:

数据来源 Groovy步骤,从数据源获取当前行并将其附加到请求步骤4。谷歌XmlSlurper的想法如何做到这一点。 数据循环返回到步骤1。 Soap请求
这实际上是一种更干净的方法。我上面的代码,应该表明我不是一个测试人员,一次完成了所有这些,但我更喜欢你的。谢谢。您也可以使用XmlHolder;我在这里写了一些东西:但就我个人而言,在这种情况下,我会使用XmlSlurper。如果你喜欢这个答案,我可以接受:Thanx。
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()