Hello!
I’m fairly new to Postman and I’m not a Mocha expert, I’m using the “Using CSV” data to load a file with the data I need and that is working perfectly, my problem is that I need to assert one of the fields and I had research a lot in Google, StackOverflow, this forum and nothing
This is the sample response I get:
[
{
"airlineCode": "OLY",
"airlineCountryCode": "GR",
"airlineName": "Olympus",
"arrivalActualDateTime": "2018-07-04T00:37:00",
"arrivalAirport": "Tenerife Sur Airport (TFS)",
"arrivalAirportCode": "TFS",
"arrivalFlightStatus": "Arrived",
"arrivalFlightStatus2": "Arrived",
"arrivalScheduledDateTime": "2018-07-03T21:45:00",
"departureActualDateTime": "2018-07-03T20:00:00",
"departureAirport": "Hamburg Airport (HAM)",
"departureAirportCode": "HAM",
"departureFlightStatus": "Departed",
"departureFlightStatus2": "Departed",
"departureScheduledDateTime": "2018-07-03T17:35:00",
"distance": 3577,
"flightCode": "OLY246",
"flightDate": "2018-07-03",
"flightLegId": 189543873,
"flightNumber": "246",
"isArrivalActualDateTimeCalculated": false,
"isArrivalScheduledDateTimeCalculated": false,
"isDepartureActualDateTimeCalculated": false,
"isDepartureScheduledDateTimeCalculated": false,
"operatingAirlineCode": "OLY",
"operatingCarrierCode": null,
"operatingFlightNumber": 246,
"problemFlightId": null,
"scheduleId": null
}
]
From that response, I wanted to assert that the "operatingCarrierCode"
is not null or empty so I can cherry-pick from more than 2400 calls the ones that actually have a real value there.
I had tried the following code with no luck:
I know that the field type is “undefined” when I ran some code I found to check it.
//pm.test("To Check if Value is Null", function() {
var jsonData = pm.response.json();
//pm.expect(jsonData.operatingCarrierCode).not.eq('');
//pm.expect(jsonData.operatingCarrierCode).toBeNull();
//expect(context).toBeDefined();
//expect(context).not.toBeNull();
//pm.expect(jsonData.operatingCarrierCode).not.eq(NaN);
//});
//pm.test("operatingCarrierCode present", function() {
//console.log(typeof jsonData.operatingCarrierCode);
//pm.expect(jsonData.operatingCarrierCode).to.exist
//pm.expect(jsonData.operatingCarrierCode).to.not.be.null
//pm.expect(jsonData.operatingCarrierCode).to.include("null");
//});
pm.test("Body matches string", function ()
{
pm.expect(pm.jsonData.text()).to.not.include("null");
});
Can anyone be so kind to let me know how to do that? Thanks