金牛座 - 断言重定向 url 是否正确
taurus - to assert if redirected url is correct
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 中我们可以检查 return 代码,还可以在将要显示的 HTML 页面上对正文进行断言。是否可以捕获 URL 页面将被重定向到的内容并对其进行断言?示例:如果我希望 https://www.example.com
仅重定向到 https://www.example.com/test/
,如果重定向到 https://www.example.com/testing/
则失败,我该如何实现。 TIA
使用 JSR223 Post-Processor 可选择将 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'); }
prev 是 https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
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 中我们可以检查 return 代码,还可以在将要显示的 HTML 页面上对正文进行断言。是否可以捕获 URL 页面将被重定向到的内容并对其进行断言?示例:如果我希望 https://www.example.com
仅重定向到 https://www.example.com/test/
,如果重定向到 https://www.example.com/testing/
则失败,我该如何实现。 TIA
使用 JSR223 Post-Processor 可选择将 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'); }
prev 是 https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html