I have several XMLs that corresponds of Header and body. The header part of the XML is the same with all XMLs. Can I reuse this part somehow? instead of adding the exact same data and part in all XMLs can I have it in one place and just add it in my XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.spv.se/forsakring/iap/flyttratt/granssnitt/InitieraTestscenario/1.0/" xmlns:ns1="http://schemas.spv.se/forsakring/iap/flyttratt/arkitekturella/1.0/">
<soapenv:Header/>
<soapenv:Body>
<ns:InitieraTestscenario>
<!--Optional:-->
<ns:Forsakringar>
<!--Zero or more repetitions:-->
<ns:Forsakringsinformation>
<!--Optional:-->
<ns:Forsakringsnummer>?</ns:Forsakringsnummer>
</ns:Forsakringsinformation>
</ns:Forsakringar>
<!--Optional:-->
<ns:Personnummer>?</ns:Personnummer>
<!--Optional:-->
<ns:TestscenarioTyp>?</ns:TestscenarioTyp>
<!--Optional:-->
<ns:Header version="0.1">
<!--Optional:-->
<ns1:SkickatFran>?</ns1:SkickatFran>
<ns1:SkickatFranBolagsID>?</ns1:SkickatFranBolagsID>
<!--Optional:-->
<ns1:SkickatTill>?</ns1:SkickatTill>
<ns1:SkickatTillBolagsID>?</ns1:SkickatTillBolagsID>
<ns1:TimeStamp>?</ns1:TimeStamp>
<!--Optional:-->
<ns1:Process>?</ns1:Process>
<ns1:PensionsPlan>?</ns1:PensionsPlan>
<ns1:Produktion>?</ns1:Produktion>
</ns:Header>
</ns:InitieraTestscenario>
</soapenv:Body>
</soapenv:Envelope>
Use property expansion. Put the reusable XML content into a property and include it all, or use XPath to select the node(s) that you want to include.
SoapUI provides a common syntax to dynamically insert ("expand") property values during processing. The syntax is as follows:
${[scope]propertyName[#xpath-expression]}
where scope can be one of the following literal values:
#Project#
- references a Project property(Reference properties across a particular SoapUI project)#TestSuite#
- references a TestSuite property in the containing TestSuite --#TestCase#
- references a TestCase property in the containing TestCase#MockService#
- references a MockService property in the containing MockService#Global#
- references a global property. Found in File>Preferences>Global Properties tab. Reference properties across all projects#System#
- references a system property. Found in Help>System properties.#Env#
- references an environment variable[TestStep name]#
- references a TestStep property
Many of the scopes will of course only work if they are available, i.e. you can not use the
#MockService#
scope within a TestCase script since there is no containing MockService to access.
If no scope is specified, the property is resolved as follows:
- Check the current context (for example the TestRunContext) for a property with the matching name
- Check for a matching global property
- Check for a matching system property
If the property expansion further includes an XPath expression, this will be used to select the corresponding value from the referenced property value (which must contain XML), for example the following example could "extract" the author value from a preceding response with:
${Search Request#Response#//ns1:Item[1]/n1:Author[1]/text()}