artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
7.91k stars 505 forks source link

How to validate response and stop flow on error? #356

Open markb-trustifi opened 7 years ago

markb-trustifi commented 7 years ago

I would like to have some Jasmine/Chai style response validations:

expect(response.statusCode, response.statusMessage).to.be.within(200, 201);
expect(response.body).to.be.not.null;
expect(response.body.message).to.be.eq('some error');

and, when expect fails the flow should stop with custom error message. Right now it can be achieved only by the javascript functions:

function afterResponseHandler(requestParams, response, context, event, next) {
    if(response.statusCode !== 200 && response.statusCode !== 201) {
        if(response.statusMessage)
            console.error(response.request.method +":"+ response.request.uri.path, response.statusCode+": "+response.statusMessage);

        let err = new Error();
        err.code = response.statusCode;
        return next(err);
    }

    return next(); 
}

Is there solution out-of-the-box?

hassy commented 7 years ago

Expectations are on the roadmap.

spinningarrow commented 5 years ago

For anyone who came here recently, this can be done with the artillery expect plugin.

trajano commented 2 years ago

The link ends up with a 404