How to dynamically insert xml nodes based on parameters from excel sheet in SoapUi using groovy
Below is the code which I used to get a data from excel sheet and using it in my Request.
import jxl.*
def TestCase = context.testCase
def FilePath = "D:\\DataSheet_Services_create.xls"
def count
Workbook WorkBook1 = Workbook.getWorkbook(new File(FilePath))
Sheet getExcelSheet = WorkBook1.getSheet("SearchCustomer")
PropertiesTestStep = TestCase.getTestStepByName("Properties")
count = PropertiesTestStep.getPropertyValue("Counter").toInteger()
Reading the excel data:
Cell Field20 = getExcelSheet.getCell(19, count)
Cell Field21 = getExcelSheet.getCell(20, count)
setting the cell values to properties:
PropertiesTestStep.setPropertyValue("propertyName1",Field19.getContents())
PropertiesTestStep.setPropertyValue("propertyValue1", Field20.getContents())
My request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ws:companyId>?</ws:companyId>
</soapenv:Header>
<soapenv:Body>
<ws:createCustomer>
<ws1:customerDTO>
<properties>
<propertyName>${Properties#propertyName1}</propertyName>
<propertyValue>${Properties#propertyValue1}</propertyValue>
</properties>
</ws1:customerDTO>
</ws:createCustomer>
</soapenv:Body>
</soapenv:Envelope>
My actual problem :
In excel data there are N no of properties parameter , In that case how can I dynamically insert properties node in request xml like below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ws:companyId>?</ws:companyId>
</soapenv:Header>
<soapenv:Body>
<ws:createCustomer>
<ws1:customerDTO>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ws:companyId>?</ws:companyId>
</soapenv:Header>
<soapenv:Body>
<ws:createCustomer>
<ws1:customerDTO>
<properties>
<propertyName>${Properties#propertyName1}</propertyName>
<propertyValue>${Properties#propertyValue1}</propertyValue>
</properties>
<properties>
<propertyName>${Properties#propertyName2}</propertyName>
<propertyValue>${Properties#propertyValue2}</propertyValue>
</properties>
<properties>
<propertyName>${Properties#propertyName3}</propertyName>
<propertyValue>${Properties#propertyValue3}</propertyValue>
</properties>
</ws1:customerDTO>
</ws:createCustomer>
</soapenv:Body>
</soapenv:Envelope>
</ws1:customerDTO>
</ws:createCustomer>
</soapenv:Body>
</soapenv:Envelope>
I have followed below post