In this article, we will see how we can use a Test Data Profile for data driven testing in REST API Steps.
Steps for using Test Data Parameter in REST Steps for data driven testing
Before we begin, let us clear it out that Test Data Parameter can be used only in the URL for a REST API Test Step as of now. More features will be added going forward.
Here are the steps that need to be followed:
1. Create/Import a Test Data Profile.
2. Select the Test Data Profile and enable Data driven toggle while creating or editing the Test Case.
3. Append the Test Data Parameter in the URL.
Following is the Test Data Profile that we are going to use:
Assuming the Test Data Profile is created and selected in the Test Case, we can proceed onto using the Test Data Parameter in our REST Step.
And for this, we simply need to append the Test Data Parameter with the URL as it is used in normal Test Steps. The Test Data parameter will be translated into its value when the REST Step is run.
For Test Data Sets that are present in the Test Data Profile, as many iterations will be performed.
Please check the below guide for more details on usage of Test Data Profile for data driven testing - How to use Test Data Profile in Test Steps?
We will be using the API Endpoint https://jsonplaceholder.typicode.com/posts/<post id> as an example. For a GET Request with the <post id> replaced by a number from 1 to 100, the API Response contains a JSON Object for a single post with id <post_id>.
For example, https://jsonplaceholder.typicode.com/posts/1 returns the first post as shown below.
Info: We will be truncating the Response to first 3 JSON Objects for brevity.
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
Using Test Data Parameter in the REST Step
Append the Test Data Parameter id in the URL for the REST API Test Step as shown below:
Since there are 3 Test Data Sets with id values 1,2, and 3 in the Test Data Profile Posts Index as given above, there will be three iterations in the Test Results as shown below.
Also, we can confirm that the URL is parsed correctly in the Request Details as shown below:
Above given is the Step Result for the first iteration.
That's how we can use Test Data Parameters in REST APIs to perform Data driven Testing.