i try to get formData for validate my data for that should be string but its not getting formdata :
let formData = pm.request.body.formdata;
let checkString = ["email", "password"];
for (var i = 0; i < formData.length; i++) {
var currentField = formData[i];
console.log(currentField)
for (var j = 0; j < checkString.length; j++) {
var allowedProperty = checkString[j];
console.log(allowedProperty);
// Ensure that the property is not undefined
pm.expect(currentField.value).to.not.be.undefined, `${allowedProperty} should not be undefined in field ${i + 1}`;
// Ensure that the property is a number (data type check)
pm.expect(currentField.value).to.be.a('number', `${allowedProperty} should be a number in field ${i + 1}`);
// Log the value of the property
console.log(`${allowedProperty} in field ${i + 1}: ${currentField.value}`);
// Check if the property has an empty value
if (currentField.value === "") {
pm.expect.fail(`${allowedProperty} in field ${i + 1} has an empty value`);
}
}
}
I can see that you’re using pm.expect() but I don’t see these within a pm.test() function That wouldn’t show anything in the Test results section without that.
This should be let formData = pm.request.body.formdata.all(); I believe, to access that array.
If we’re discussing the actual test, I don’t understand it at all as its just checking what you’ve set in the request which surely you should know.
I’m not quite seeing the value of the test.
Yes, you can run tests in the pre-request scripts, and yes you can check the request details, but usually tests are against the responses. There is an assumption that you know what information you are sending.