I'm trying to create a test in Postman to return different text responses depending on the outcome of the switch statement. However, i'm not sure why it says no tests available when i click 'run' I have my Get method set up correctly as when i execute it on its own it returns e.g. 200 OK. I have the below:
var statMessages ;
switch (statMessages) {
case '500':
console.log('Internal Server Error.');
break;
case '200':
console.log('200 Ok');
break;
case '503':
console.log('Service unavailable.');
break;
case '502':
console.log('502 bad gateway.');
break;
case '599':
console.log('Network connect timeout error.');
break;
case '408':
console.log('Request timedout.');
break;
default:
console.log('Sorry, we are out of ' + statMessages + '.');
}
console.log("Try again?");
If I don't misunderstood your question then I think you should try like this way. Grab HTTP Status Code like on your statMessages
var statMessages = responseCode.code; // it'll return numeric code e.g 200
switch (statMessages) {
case 500:
tests["Internal Server Error."] = statMessages === 500;
break;
case 200:
tests["200 Ok"] = statMessages === 200;
break;
case 503:
tests["Service unavailable."] = statMessages === 503;
break;
case 502:
tests["502 bad gateway."] = statMessages === 502;
break;
case 599:
tests["Network connect timeout error."] = statMessages === 599;
break;
case 408:
tests["Request timedout."] = statMessages === 408;
break;
default:
tests["Sorry, we are out of" + responseCode.code]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With