2
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

4

1 回答 1

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'); }

prev 是https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

于 2019-06-06T01:00:43.193 回答