scenarios:
RedirectURL:
variables:
baseurl: https://www.example.com
headers:
Authorization: example
retrieve-resources: false
follow-redirects: true
requests:
- url: https://www.example.com
method: GET
assert:
- contains:
- 301
subject: http-code
assume-success: true
我看到在Taurus中,我们可以检查返回码,还可以在将要显示的HTML页面上的主体上进行断言。是否可以捕获页面将重定向到的URL并对其进行断言?示例:如果我希望https://www.example.com
仅重定向到https://www.example.com/test/
,但是如果重定向到https://www.example.com/testing/
失败,我该如何实现。 TIA
答案 0 :(得分:1)
使用JSR223后处理器有选择地将SampleResult更改为失败
scenarios:
RedirectURL:
variables:
baseurl: https://www.example.com
headers:
Authorization: example
retrieve-resources: false
follow-redirects: true
requests:
- url: https://www.example.com
method: GET
assert:
- contains:
- 200 # Response code of the url after the redirect
subject: http-code
jsr223:
- language: groovy
execute: after
script-text: if (prev.getUrlAsString() != 'https://www.example.com/test/') { prev.setSuccessful(false); prev.setResponseMessage('Unexpected URL'); }
上一个是https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html