Reusability / POM / DRY?

Hello,

The ability of working with variables, tests, collections, pre-scripts is great and has been definitely made our life easier, but things need to be reproached when dealing with big test suites of >200 requests with >800 assertions.

I’m curious to know if somebody has a more elegant solution of maintaining a collection of this size, using some reusability concepts while using the best we can from what postman has to offer.

  1. In collection/Pre-Request Scrips tab I have all my functions stored. It is more of a general/fast place to store data, search and update globally.

Ex:

postman.setGlobalVariable(“commonTests”, () => {
var jsonData = pm.response.json();

function checkjSonBodyValidateOthersShort(jsonData, address, status, sub_status, data, did_you_mean) {
pm.test(“Response body is correct”, function (){

pm.expect(jsonData.address).to.eql(address);
pm.expect(jsonData.status).to.eql(status);
pm.expect(jsonData.sub_status).to.eql(sub_status);
pm.expect(jsonData.data).to.eql(data);
pm.expect(jsonData.did_you_mean).to.eql(did_you_mean);

});
}

switch(jsonData.address)
{

    //Valid andrei
case ‘andrei’:
    eval(checkjSonBodyValidateOthersShort)(jsonData,’andrei,’valid',"", false, null,);    
    break;

//Invalid andrei
case ‘andrei2’:
eval(checkjSonBodyValidateOthersShort)(jsonData,’andrei2,’invalid’,””, true, null,);
break;
……………
default:
pm.test(Address not found in case statements, function () {
pm.expect(jsonData.address).to.eql(‘undefined’);
});

function checkResponseTime(value) {
pm.test(Response time is less than ${value}ms, function () {
pm.expect(pm.response.responseTime).to.be.below(value);
});
}

  1. I have structured most of my requests in folders with the same purpose. Ex: type of requests, methods, headers or other criteria that will allow tests to be executed and calling into collection or folder/Test tab all my tests
    Ex:
    commonTests.checkjSonBodyValidateOthersShort();
    commonTests.checkResponseTime(2500);

Same approach for asserting header, response code, specific body, etc.

Does someone use a different strategy that could allow scaling with Postman more efficient, using reusability, POM or DRY principles?