How to Parametrize gpath using XMLSLuper
Hi,
I want to parametrize Gpath in XMlSlurper from excel file.
My requirement is to provide gpath in excel file and want to parametrize gpath to get the particular tag.
Please see below for my code:
def response ='''<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:abc xmlns:ns2="http://xyz" xmlns:ns3="http://xyz" xmlns:ns4="http://xyz">
<ns2:deviceUnits>
<ns2:devicePorts>
<ns2:portNumber>1</ns2:portNumber>
<ns2:serviceEntities>
<ns2:networkId>16869467</ns2:networkId>
<ns2:didTargets>
<ns2:did>12003004001</ns2:did>
<ns2:didType>PHYS</ns2:didType>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:didTargets>
<ns2:startDate>2012-09-25</ns2:startDate>
</ns2:serviceEntities>
</ns2:devicePorts>
</ns2:deviceUnits>
</ns2:abc>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'''
def xml = new XmlSlurper().parseText(response).Body.abc.deviceUnits.devicePorts.serviceEntities.didTargets.each
{it.did }
log.info xml.size()
Uisng above code everything is working fine for me but when I am able to fetch the value of the above mentioned gpath Body.abc.deviceUnits.devicePorts.serviceEntities.didTargets from excel file and set it @ Project level property and when i am passing that variable like below then its not working. I am not sure what will be the return type of Gpath fetched from excel
def pro=testRunner.testCase.testSuite.project
def a=pro.getPropertyValue("gpath")
def xml = new XmlSlurper().parseText(response).a.each
{it.did }
log.info xml.size()
log.info xml[0]
Can someone please let me know their input on this ?
Thanks,
Himanshu