-
Thanks to Portman's great documentation and helpful answers in this forum, I've been writing variation tests that use Postmam environment variables in request bodies. However I'm having trouble setting these attributes to integers when that is the required type. TL;DR When I use this syntax: overwrites:
- overwriteRequestBody:
- key: intAttribute
value: "{{numericPostmanVariable}}"
overwrite: true The resulting generated request body looks like this: {
"intAttribute": "{{numericPostmanVariable}}"
} This fails validation since my spec says that intAttribute is an integer. However, if I manually remove the quote marks around the variable, it works as desired. If I try to remove the quotes in the overwrite directive: overwrites:
- overwriteRequestBody:
- key: intAttribute
value: {{numericPostmanVariable}}
overwrite: true The resulting generated request body looks like this: {
"intAttribute": {}
} Is it possible to assign a request body attribute to a Postman variable without having it enclosed in quotes? I've played around with a few escape sequences but haven't gotten anything to work yet. Here is a more complete example of my configuration and the result requests in Postman, if that is helpful version: 1.0
tests:
variationTests:
- openApiOperationId: createCategory
openApiResponse: '400'
variations:
- name: groupIdIsNotGroup
overwrites:
- overwriteRequestBody:
- key: is_group
value: false
overwrite: true
- key: group_id
value: {{_categoryId}} # _categoryId is a Postman variable set to an integer in a previous test
overwrite: true
tests:
contentTests:
- responseBodyTests:
- key: message
value: Invalid Request Body
- key: errors
minLength: 1
- key: errors[0].errMsg
value: Requested 'group_id':${requestBody.group_id} is not an existing category group
- name: categoryGroupAsChild
overwrites:
- overwriteRequestBody:
- key: is_group
value: true
overwrite: true
- key: children
value: ["{{_categoryGroupId}}"] # _categoryGroupId is a Postman variable set to an integer in a previous test
overwrite: true
tests:
contentTests:
- responseBodyTests:
- key: message
value: Invalid Request Body
- key: errors
minLength: 1
- key: errors[0].errMsg
value: Specified child category id:'${id}' is a category group |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
hi @jpjpjp According to the tests
Resulting in:
Let me do some more tests, with a regular variable and your examples . |
Beta Was this translation helpful? Give feedback.
-
Thank you, @thim81! Just to be clear, I haven't been using the syntax of including '$' inside the braces but before my variable name. I also tried your syntax of using single quotes instead of double quotes, but that also seems to have the same outcome. |
Beta Was this translation helpful? Give feedback.
-
The regular variables are just I still have to find time to do the tests, to verify if the regular number variables are properly parsed. |
Beta Was this translation helpful? Give feedback.
-
hi @jpjpjp Can you try the following?
This should result in numeric (non-string) variable overwrite. If you find a clear way to describe this in the readme, feel free to make a suggestion 🤝 . |
Beta Was this translation helpful? Give feedback.
hi @jpjpjp
Can you try the following?
Make the numeric variable a string
{{{varName}}}
. Use your variable name, surrounded by{{{
at the start and}}}
at the end, with quotes around it. That will trigger Portman to convert it into a numeric variable (and not as a default string).This should result in numeric (non-string) variable overwrite.
If you find a clear way to describe this in the r…