我是SOAP UI的新手,所以有什么方法可以从SOAP UI中提取键>值对。 即读取 SOAP 接口必须提供的"索引"?喜欢从SNMP阅读MIB?
例如,我可以请求:
<SOAP:Body>
<find xmlns="xmlapi">
<fullClassName>Persons</fullClassName>
<resultFilter class="Persons.Data">
<attribute>Name</attribute>
</resultFilter>
</find>
</SOAP:Body>
类名"人"是我知道的,但是有没有办法检索 SOAP UI 必须提供的"类"列表?
如果你想在
<find>
中获取特定请求的所有<fullClassName>
元素,一种可能的方法是例如在时髦的testStep中使用XmlSlurper:
// get your response
def response = context.expand( '${TestRequest#Response}' )
// parse it
def xml = new XmlSlurper().parseText(response)
// find all `<fullClassName>` in your xml
def classNames = xml.'**'.findAll { it.name() == 'fullClassName' }
// print all values
classNames.each{
log.info "fullClassName: $it"
}
由于您是SOAPUI的新手(也许也是Groovy),这里有一些提示:
context.expand( '${TestRequestName#Property}' )
从某个作用域元素获取特定属性的内容。在这种情况下,必须指定请求名称,并将响应作为属性。有关详细信息,请参阅属性扩展文档
Groovy自动使用it
作为闭包的变量。这就是为什么我在each
和findAll
中使用it
。
更新
如果想知道<fullClassName>
支持的所有可能值,可以使用以下选项:
- 检查架构中定义的
<fullClassName>
的类型是否具有<xs:restiction>
,<xs:enumeration>
可能的值。 - 如果在架构中类型只是
<xs:string>
或其他类型,它没有为您提供有关允许值的任何线索,请联系提供程序以查看替代方案,例如是否有另一个返回值的 SOAP 服务...
对于第一种情况,如果你有.xsd
尝试添加一个时髦的testStep来分析.xsd
并获取<xs:enumeration>
值,请参阅以下示例:
def xsd = '''<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<simpleType name="fullClassNameType">
<restriction base="string">
<enumeration value="Persons"/>
<enumeration value="AnotherClassName"/>
<enumeration value="AnotherOne"/>
</restriction>
</simpleType>
</schema>'''
// parse the xsd
def xml = new XmlSlurper().parseText( xsd )
// find your type by name attribute
def fullClassNameType = xml.depthFirst().find { it.@name == 'fullClassNameType' }
// get an array with value attribute of enumeration elements
def allowedValues = fullClassNameType.restriction.enumeration*.@value
log.info allowedValues // [Persons, AnotherClassName, AnotherOne]
希望对您有所帮助,