Ask a Question

How to dynamically insert xml nodes based on parameters from excel sheet in SoapUi using groovy

vic_2407
New Contributor

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-parameteri...

2 REPLIES 2
HimanshuTayal
Community Hero

@vic_2407 : In that case you need to write your custom groovy code, also you can refer below link and get some help on the same.

 

How-to-Generate-a-Request-Body-Dynamically 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

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.

create.jpg

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.

 

cancel
Showing results for 
Search instead for 
Did you mean: