-
I'm wondering if it's possible to create a content test to see if a field in a response body matches one of a few postman environment variables. I've tried the following: tests:
contentTests:
- responseBodyTests:
- key: children
minLength: 2
- key: childrend[0].id
oneOf: ["{{{_testCreatedCategoryId}}}", "{{{_testCreatedCategoryId2}}}"]
- key: childrend[1].id
oneOf:
- "{{_testCreatedCategoryId}}"
- "{{_testCreatedCategoryId2}}" Both syntaxes are accepted by portman, but neither generates a valid test. Here is what the above generates: // Response body should have "childrend[0].id"
pm.test("[PUT]::/categories/:id - Content check if 'childrend[0].id' exists", function() {
pm.expect(_resChildrend0Id !== undefined).to.be.true;
});
// Response body should be one of the values "{{{_testCreatedCategoryId}}},{{{_testCreatedCategoryId2}}}" for "childrend[0].id"
if (_resChildrend0Id !== undefined) {
pm.test("[PUT]::/categories/:id - Content check if value for 'childrend[0].id' is matching one of: '{{{_testCreatedCategoryId}}},{{{_testCreatedCategoryId2}}}'", function() {
pm.expect(jsonData.childrend[0].id).to.be.oneOf(["pm.collectionVariables.get("{_testCreatedCategoryId}")","pm.collectionVariables.get("{_testCreatedCategoryId2}")"]);
})};
// Set property value as variable
const _resChildrend1Id = jsonData?.childrend?.[1]?.id;
// Response body should have "childrend[1].id"
pm.test("[PUT]::/categories/:id - Content check if 'childrend[1].id' exists", function() {
pm.expect(_resChildrend1Id !== undefined).to.be.true;
});
// Response body should be one of the values "{{_testCreatedCategoryId}},{{_testCreatedCategoryId2}}" for "childrend[1].id"
if (_resChildrend1Id !== undefined) {
pm.test("[PUT]::/categories/:id - Content check if value for 'childrend[1].id' is matching one of: '{{_testCreatedCategoryId}},{{_testCreatedCategoryId2}}'", function() {
pm.expect(jsonData.childrend[1].id).to.be.oneOf(["pm.collectionVariables.get("_testCreatedCategoryId")","pm.collectionVariables.get("_testCreatedCategoryId2")"]);
})}; If this isn't supported, that is fine. Please don't treat this as a must-have feature request or bug report. I was just wondering if there was a different syntax that might work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
hi @jpjpjp, Let me run some tests, how portman handles it. At first glance, I suspect an unneeded string conversion using backticks. |
Beta Was this translation helpful? Give feedback.
hi @jpjpjp
We just released Portman v1.30.2, this contains the improvements with handling collectionVariables for oneOf.
Can you try it out and see if this works like in my screenshot?