Continuous Testing with Postman

Hi All,
As we know, Automation is key for any agile project whereas Continuous testing play major role.

I cam across situation whereas I feel need to follow continuous testing process, Any help will be helpful.

Scenario: So lets suppose I need to verify next 2 lines within one test case and If there is case when 1st steps got failed then 2nd steps should also share the result.

Script:

pm.test("Buffer", function (){
    var  frontlineClientsCount=pm.environment.get("frontlineClientsCount");
    var  newGen0ClientsCount=pm.environment.get("newGen0ClientsCount");
   pm.expect(pm.response.json().clients.frontlineClientsCount).to.eql(frontlineClientsCount); //1st step
   pm.expect(pm.response.json().clients.newGen0ClientsCount).to.eql(newGen0ClientsCount); //2nd step
});

Now lets assume 1st step got failed, then Test result will show about failure reason but it will not show result about second steps
In that case I can assure about 1st step but not about 2nd step. Is there any chance How I can see all result means 2nd step should run and will not depend on 1st step.

P.S. Yes we can do through separate/new test and there I can give separate steps but lets assume I have more then 15 steps so not feasible to create 15 different test cases.

Let me know still needed more info.

You can’t do that. Once chai sees an invalid assertion it will skip the rest of the assertions in the test.

Based on your example, it looks to me like you could easily script this out.

bufferTest('frontlineClientsCount');
bufferTest('newGen0ClientsCount');
//etc...

function bufferTest(jsonData, variableName) {
  const variable = pm.environment.get(variableName);
  
  pm.test(`Buffer ${variableName}`, function(){
    pm.expect(jsonData.clients[variableName]).to.eql(variable);
  }
}

It would be even easier if you prefixed your environment variables, but I won’t go into detail on that unless you like the above solution. :slight_smile:

Sorry @allen.helton but not sure what gonna be helpful above script, Would love to understand in more details.

Thanks!!

The function I wrote makes this easier because it’s just one line for each test case. It could get even easier if you prefixed all your variables for this scenario with something.

Imagine you had 15 environment variables you wanted to test and they were all prefixed with buffer-. i.e. buffer-frontlineClientsCount.

You could write a script that will automatically test the response for every one of those variables. When you need to test more fields, just add them as environment variables and they will automatically be tested.

_.each(Object.keys(pm.environment.variables()).filter(key => key.startsWith('buffer-')), (key) => {
  bufferTest(key);
});

function bufferTest(jsonData, variableName) {
  const variable = pm.environment.get(variableName);
  
  pm.test(`Buffer ${variableName}`, function(){
    pm.expect(jsonData.clients[variableName]).to.eql(variable);
  }
}