Forum Discussion

vic_2407's avatar
vic_2407
New Contributor
5 years ago

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>

nmrao , asn_007 

I have followed below post

https://community.smartbear.com/t5/SoapUI-Open-Source/Create-Dynamic-XML-using-Groovy-amp-parameterize-the-arguments/m-p/140776#M23969

    • vic_2407's avatar
      vic_2407
      New Contributor

      Hi Himanshu, Thanks for your reply. I have gone through the link which you have provided,But I have already got those data from excel and stored in the properties. Now just i have to insert properties nodes in the below xml

      Below is the folder structure which I have followed.

      Stuck with the requirement , In the above pic  The properties node should be updated in the createCustomer Rq according to the data which is imported from excel.