artillery

Artillery: How can I mark a test scenario as failed using artillery load test and show the same in some report?


I am working on some test requirement where I have to fail a load test scenario when p95>100ms. I have written below test snippet:

config:
  target: "https://news.google.com"
  # Responses have to be sent within 10 seconds or the request will be aborted
  timeout: 10
  ensure:
      p95: 800
  phases:
    - duration: 10
      arrivalRate: 1

scenarios:
  - name: "Hit news google"
    flow:
    - get:
          url: "/dssw.js_data?_reqid=34556&rt=j"
          expect:
            - statusCode: 300
            - contentType: json

I want this test scenario to be visible in some kind of reports as how many test case has been failed and pass. Artillery generates the report only showing the performance stats but how to show the report as per the test performance assertion failed in some kind of report.


Solution

  • One option is to implement a hook in javascript that looks at the status code and if deems the status as failed returns an error trough the next function.

    Example js hook function:

    function exitOnFail(requestParams, response, context, ee, next) {
      const statusCode = parseInt(response.statusCode);
      if (statusCode > 399) {
        next(new Error(`${requestParams.url} StatusCode: ${statusCode}`));
      } else {
        next();
      }
    }
    

    and connecting the hook to the request:

    config:
     ...
     processor: './scriptfile.js'
    
     ...
    
    scenarios:
      - flow:
        - get:
            url: some/url
            ...
            afterResponse: 'exitOnFail'