Is there a way to include Soft Assert in Postman tests?

Viewed 387

So that it should not stop the deployment in Pipeline if any of the tests fail.

Refer the screenshot to view the Status

1 Answers

Unfortunately, soft assertions with a test are not possible at the moment in Postman tests.

However, an alternative is to simply split the tests up into different tests.

This:

pm.test('Status code is 201', () => {
    pm.response.to.have.status(201);
});

const json = pm.response.json();

pm.test('Idea External Id is present', () => {
    pm.expect(json)
        .to.have.property('external_id')
        .to.have.lengthOf(16);

    pm.environment.set("idea-external-id", json.external_id);
});

pm.test('Expected Idea is returned', () => {
    pm.expect(json)
        .to.have.property('title', 'Make Bed $0.50');
    pm.expect(json)
        .to.have.property('description', 'Make your bed.');
    pm.expect(json)
        .to.have.nested.property('call_to_action.uri', 'https://youtu.be/Du0M6yVjKlA');
    pm.expect(json)
        .to.have.nested.property('call_to_action.label', 'Instructional Video');
    pm.expect(json)
        .to.have.property('key', 'chore_chart');
    pm.expect(json)
        .to.have.property('created_at');
    pm.expect(json)
        .to.have.property('updated_at');
    pm.expect(json)
        .to.have.nested.property('_links.self.href')
        .to.match(new RegExp(`.+/idea/${pm.environment.get("idea-external-id")}`));
});

Becomes this:

pm.test('Status code is 201', () => {
    pm.response.to.have.status(201);
});

const json = pm.response.json();

pm.test('Idea External Id is present', () => {
    pm.expect(json)
        .to.have.property('external_id')
        .to.have.lengthOf(16);

    pm.environment.set("idea-external-id", json.external_id);
});

pm.test('Expected Idea title is returned', () => {
    pm.expect(json)
        .to.have.property('title', 'Make Bed $0.50');
});

pm.test('Expected Idea description is returned', () => {
    pm.expect(json)
        .to.have.property('description', 'Make your bed.');
});

pm.test('Expected Idea call_to_action.uri is returned', () => {
    pm.expect(json)
        .to.have.nested.property('call_to_action.uri', 'https://youtu.be/Du0M6yVjKlA');
});

pm.test('Expected Idea call_to_action.uri is returned', () => {
    pm.expect(json)
        .to.have.nested.property('call_to_action.label', 'Instructional Video');
});

pm.test('Expected Idea key is returned', () => {
    pm.expect(json)
        .to.have.property('key', 'chore_chart');
});

pm.test('Idea created_at is returned', () => {
    pm.expect(json)
        .to.have.property('created_at');
});

pm.test('Idea updated_at is returned', () => {
    pm.expect(json)
        .to.have.property('updated_at');
});

pm.test('Expected Idea _links is returned', () => {
    pm.expect(json)
        .to.have.nested.property('_links.self.href')
        .to.match(new RegExp(`.+/idea/${pm.environment.get("idea-external-id")}`));
});

Related