Using dynamic templates in a REST API POST Request
Hi,
Currently, I have a few templates that are to be used within a REST API POST request, all of which are JSON format. The templates contain fields that need to be updated at the time of each call.
Question now is, how do I load the correct template prior to assigning values to the parameters within the template before the POST command without having to create multiple API endpoint requests for each of those templates. The parameterised values are to be extracted from an Excel spreadsheet which will potentially also contain the information on which template is to be used. They essentially use the same API endpoint.
I've read that you can create a datasource using directories and files within said directory, but that does not fit with my intended purpose. The templates are to be loaded only when they are needed during the testing cycle as well as there is the possibility that there might be new template files that might need to be used in the future or that existing template files might need to be updated to cater for any future changes in testing. Thus these files need to be dynamically read at runtime, especially if it was part of a CI/CD pipeline.
So, in a nutshell, I need to be able to read a spreadsheet from one Excel file and use one of its columns to determine which template I need to be using. The template will contain the parameterised fields that then need to be filled from that spreadsheet using the corresponding columns.
Any suggestions..??
- hazel_chua,
Possibly here is what I can think of.
- have a groovy script test step before the current rest test step.
- since you knew the condition based on the current row of the data source, retrieve the respective template for the post request
- set the request to the following rest test step (I guess, sample code snippet available how to set request to the step from GitHub.com/nmrao (have search from available scripts)