[英]How to get XML response values in karate framework
This is my XML Response and I would like to retrieve Name and LastModifiedTime from response by using karate framework这是我的 XML 响应,我想使用空手道框架从响应中检索 Name 和 LastModifiedTime
<ADELdirectory:Directory
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ADELdirectory="http://www.com/XMLSchema/MT/Generic/v1.3" xsi:schemaLocation="http://www.com/XMLSchema/MT/Generic/v1.3 ADELdirectory.xsd">
<Header>
<Title>Directory listing</Title>
<MachineID>TS01</MachineID>
<MachineType>STEdiSimulator</MachineType>
<SoftwareRelease>Unknown</SoftwareRelease>
<CreatedBy>SystemTest.EDISimulator</CreatedBy>
<CreateTime>2021-10-19T14:31:17.442Z</CreateTime>
<Comment>
<elt>url: http://174.28.39.123:8080/EDI/ADELler?cmd=list</elt>
</Comment>
<DocumentId>c0ceb67f-6498-4b5e-8c86-4f482121fb0c</DocumentId>
<DocumentType>ADELdirectory</DocumentType>
<DocumentTypeVersion>v1.3</DocumentTypeVersion>
</Header>
<Input>
<Username>SystemTestFramework</Username>
<DocumentType>ADELler</DocumentType>
<DocumentPath>/</DocumentPath>
<RequestParameterList>
<elt>
<Name>cmd</Name>
<Value>list</Value>
</elt>
</RequestParameterList>
</Input>
<Results>
<MainAttributeList/>
<EntryList>
<elt>
<Type>Document</Type>
<Name>TS01/LOT_AP_0001/2021-10-12T14:35:28.835Z</Name>
<LastModifiedTime>2021-10-12T14:50:28.836Z</LastModifiedTime>
<Size>15235986</Size>
</elt>
<elt>
<Type>Document</Type>
<Name>TS01/LOT_AP_0001/2021-10-12T14:35:35.853Z</Name>
<LastModifiedTime>2021-10-12T14:50:35.854Z</LastModifiedTime>
<Size>15235986</Size>
</elt>
</EntryList>
</Results>
</ADELdirectory:Directory>
When I run .feature file there is a error message 'no variable found with name' I need to define correct XML path.当我运行 .feature 文件时,有一条错误消息“找不到名称的变量”,我需要定义正确的 XML 路径。
* xml entryLists = $/Directory/Results/EntryList/elt
This will work:这将起作用:
* def times = $response//Results//elt/LastModifiedTime
* print times
* def names = $response//Results//elt/Name
* print names
So you get JSON string arrays back.所以你得到了 JSON 字符串数组。 Now you can easy get what you want eg
现在你可以轻松得到你想要的东西,例如
* def firstName = names[0]
* match firstName == 'TS01/LOT_AP_0001/2021-10-12T14:35:28.835Z'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.