Using the same request object for multiple test cases #106
-
scenario: I have test case1 , that uses a specific request object(read from file) and makes few key value modifications and uses it for the test cases. it('Verify creation of HCF with exisiting salesforce id', async () => {
request.createFacilityWithRequiredFields.salesforceID = configData.salesforceid
await pactum.spec()
.post(endpoints.baseUrl + endpoints.createHCF)
.withBody(request.createFacilityWithRequiredFields)
.withHeaders('Accept', 'application/json')
.withHeaders('Authorization', configData.HCFAuthorization)
.expectStatus(422)
}); I have test case2 , that uses the same specific request object(read from file) it('Verify creation of surgery facility without surgery related fields ', async () => {
await pactum.spec()
.post(endpoints.baseUrl + endpoints.createHCF)
.withBody(request.createFacilityWithRequiredFields)
.withHeaders('Accept', 'application/json')
.withHeaders('Authorization', configData.HCFAuthorization)
.expectStatus(422)
}); But the issue is changes done in test case1 to the request object, gets carried over to test case 2 also. Questions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In general objects are accessed by reference. If you update a value inside the object, it will be reflected at other places. The easiest solution is to have independent objects per test case. Using
|
Beta Was this translation helpful? Give feedback.
In general objects are accessed by reference. If you update a value inside the object, it will be reflected at other places. The easiest solution is to have independent objects per test case.
Using
clone
You can create a clone the request object for each test case and modify accordingly. Fortunately
pactum
comes with an inbuilt function to clone objects. Or useJSON.parse(JSON.stringify(object))