SOAPUI:如何重用 XML 的一部分

SOAPUI: How to reuse part of XML

我有几个 XML 对应 Header 和 body。 XML 的 header 部分与所有 XML 相同。我能以某种方式重用这部分吗?我可以将它放在一个地方,然后将它添加到我的 XML

中,而不是在所有 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>

使用property expansion。将可重复使用的 XML 内容放入 属性 并全部包含,或者使用 XPath select 您想要包含的节点。

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:

  1. Check the current context (for example the TestRunContext) for a property with the matching name
  2. Check for a matching global property
  3. 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()}