# Retry of failed tests happening folder wise instead of individual API wise for test script written for collection

**URL:** <https://community.postman.com/t/retry-of-failed-tests-happening-folder-wise-instead-of-individual-api-wise-for-test-script-written-for-collection/48104>\
**Category:** Help Hub\
**Created:** [June 2, 2023, 3:47pm UTC](https://community.postman.com/t/retry-of-failed-tests-happening-folder-wise-instead-of-individual-api-wise-for-test-script-written-for-collection/48104 "2023-06-02T15:47:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hptestingindia](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@hptestingindia](https://community.postman.com/u/hptestingindia)\
**Post date:** [June 2, 2023, 3:47pm UTC](https://community.postman.com/t/retry-of-failed-tests-happening-folder-wise-instead-of-individual-api-wise-for-test-script-written-for-collection/48104/1 "2023-06-02T15:47:23Z")

</div>

_My question_:  
Test script for Collection running folder wise instead of API wise. Created the Test script for collection. When triggered the collection , retry of failed tests happening folder wise instead of individual API wise

_Details (like screenshots)_:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/b/1b742a5ffc2d502cd81c5f28908b0bacf39f9a0f.png)

If New Request-1 failed, i am expecting only New Request-1 should run as per the retry attempts configured.  
But after execution of complete Folder-B, again complete Folder B run as per the retry attempts configured.

**Test Scripts configured for collection:**

var maxNumberOfTries = 3;  
var sleepBetweenTries = 10000;

if (!pm.environment.get(“collection\_tries”)) {  
pm.environment.set(“collection\_tries”, 1);  
}

if ((pm.expect(pm.response.code).to.be.oneOf([200,201,202,204])) && (pm.environment.get(“collection\_tries”) \< maxNumberOfTries)) {  
pm.environment.unset(“collection\_tries”);  
pm.test(“Successful request”, () =\> {  
pm.expect(pm.response.code).to.be.oneOf([200,201,202,204]);  
});

}  
else {  
var tries = parseInt(pm.environment.get(“collection\_tries”), 10);  
pm.environment.set(“collection\_tries”, tries + 1);  
setTimeout(function() {}, sleepBetweenTries);  
postman.setNextRequest(request.name);  
}
