我有以下针对金牛座测试的yaml:
- url: 'someURL'
method: POST
label: 'SomeLabel'
headers:
Content-Type: "application/xml"
Authorization: "auth"
remote_user: "someUser"
body-file: './requests/some.xml'
assert:
- contains:
- 200
subject: http-code
regexp: true
assert-xpath:
- xpath: "//response//someId[.='00001']"因此,当我运行这些测试时,会返回someId。根据some.xml中的数据返回Id。最近我们的需求是,如果在之前的请求中看到了数据,那么someIds就会改变,这是我不想要的。我想要的是,每当测试运行xml中的一个字段时,应该以一种以前从未见过的方式进行更改,金牛座中有没有什么东西可以满足这种要求。
发布于 2018-01-02 16:37:08
如果您需要在运行请求之前从文件中提取数据,您可以添加额外的HTTP Request采样器并使用file protocol,以便允许XPath Extractor从XPath Extractor中获取“感兴趣的”值,以便稍后能够重用它,示例金牛座测试计划演示了该方法,如下所示:
scenarios:
get-value-from-xml:
requests:
- url: file:///path/to/requests/some.xml
extract-xpath:
someid: //response//someId
execution:
- scenario: get-value-from-xml在需要的地方,您可以将提取的值引用为${someid}。
有关详细信息,请参阅Taurus JMeter Executor: Requests。
如果您需要修改该文件,可以使用JSR223 Block进行修改,请查看下面的示例以了解详细信息:
scenarios:
replace-value-in-xml:
requests:
- url: http://example.com
jsr223:
- language: groovy
script-text: 'new File("/path/to/requests/some.xml").text = new File("/path/to/requests/some.xml").text.replace("oldId","newId")'
execute: before
execution:
- scenario: replace-value-in-xmlhttps://stackoverflow.com/questions/48056906
复制相似问题