How to verify .csv file null value in test script

Hi Team,
I am trying to verify null value in test script as compare to the .csv file.
Step to reproduce:

  1. Create a .csv file with header and value e.g. Header-orderType and value-null
  2. Create a test script
    pm.test(“null valueverification”, function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData[0].nextScheduledPremierOrder.orderType).to.eql(String(data.orderType ));
    });
  3. Hit the url and get the response and verify the response.
    [{
    “id”: “2002”,
    “nextScheduledPremierOrder”: {
    “qv”: “286.38000000”,
    “orderType”: null
    }}]
    4.Getting the error as AssertionError: expected null to deeply equal ‘null’

Note:Tried with chai assertion but no luck, Any solution?



cc @allen.helton @dannydainton

Before we head down a similar road as we did a few days ago.

Have you opened up that csv file in a text editor to check the formatting? Atom, notepad++, sublime, VSCode, etc are all good options.

My fear is that using excel to create these csv files is adding these invisible characters that are not showing in the views that you have.

Yes, I already checked the formatting via notepad++ and Atom.No invisible character hidden there.

image

The value in your csv is a string whose contents is the word “null”.

You can do a little bit of preprocessing before your assertion:

pm.test(“null valueverification”, function () {
  let jsonData = pm.response.json();
  let orderType = data.orderType;
  if(orderType === "null"){
    orderType = null;
  }
  pm.expect(jsonData[0].nextScheduledPremierOrder.orderType).to.eql(String(data.orderType ));
});

Another option could be to just try not casting data.orderType as a string in the first place.

No luck, with the both way tried and not working.

cc @allen.helton

it looks like it is still comparing null as a string, I see there was a mistake in my script

pm.test(“null valueverification”, function () {
  let jsonData = pm.response.json();
  let orderType = data.orderType;
  if(orderType === "null"){
    orderType = null;
  }
  pm.expect(jsonData[0].nextScheduledPremierOrder.orderType).to.eql(orderType);
});

Thanks!! Even I haven’t noticed the repetition of data.orderType when already assigned to the orderType variable. It"s working fine but looks like not feasible in long term solution.

Scenario:- We are following data driven approach(.csv file) where as all values maintained in .csv file with respect to the objects/header.
Basically values change based on the run time database response,Each time any of the objects can have null values so practically not possible to change script based on the runtime null values.

Looking forward to hear any suggestions.

Solution:
A. I tried to put “null” in .csv file but it"s not working.
B. Yes, I can make above script for all of the objects but again it will be very long script and not in optimize way.

You could make a function that does this check/coalesce so you don’t have to keep writing it over and over. I just don’t see another way to do this if all your values are nullable.

pm.test(“null valueverification”, function () {
  let jsonData = pm.response.json();
 
  pm.expect(jsonData[0].nextScheduledPremierOrder.orderType).to.eql(replaceNull(data.orderType));
  pm.expect(jsonData[0].nextScId).to.eql(replaceNull(data.nextScId));
});

function replaceNull(value) {
  if(value === "null") {
    value = null;
  }

  return value;
}

Thanks!! Working fine.

1 Like