0
0
Postmantesting~10 mins

Collection sharing in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that a Postman collection can be shared successfully with a team member and that the shared collection is accessible to them.

Test Code - Postman
Postman
pm.test("Share collection with team member", async function () {
    // Step 1: Authenticate as collection owner
    const ownerToken = pm.environment.get("owner_token");

    // Step 2: Share collection via API
    const collectionId = pm.environment.get("collection_id");
    const shareWithUserId = pm.environment.get("team_member_id");

    const shareResponse = await pm.sendRequest({
        url: `https://api.getpostman.com/collections/${collectionId}/share`,
        method: 'POST',
        header: {
            'X-Api-Key': ownerToken,
            'Content-Type': 'application/json'
        },
        body: {
            mode: 'raw',
            raw: JSON.stringify({
                userId: shareWithUserId,
                permission: 'edit'
            })
        }
    });

    pm.expect(shareResponse.code).to.eql(200);

    // Step 3: Authenticate as team member and verify access
    const memberToken = pm.environment.get("team_member_token");

    const accessResponse = await pm.sendRequest({
        url: `https://api.getpostman.com/collections/${collectionId}`,
        method: 'GET',
        header: {
            'X-Api-Key': memberToken
        }
    });

    pm.expect(accessResponse.code).to.eql(200);
    pm.expect(accessResponse.json().collection.id).to.eql(collectionId);
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Authenticate as collection owner using API key from environmentOwner token is loaded from environment variables-PASS
2Send POST request to share collection with team member using owner tokenAPI receives share request with userId and permissionResponse code is 200 indicating successful sharePASS
3Authenticate as team member using their API keyTeam member token is loaded from environment variables-PASS
4Send GET request to retrieve shared collection using team member tokenAPI returns collection details to team memberResponse code is 200 and collection id matches shared collectionPASS
Failure Scenario
Failing Condition: Sharing fails due to invalid owner token or incorrect userId
Execution Trace Quiz - 3 Questions
Test your understanding
What indicates that the collection was shared successfully?
AThe share API response code is 200
BThe team member token is loaded
CThe collection id is retrieved
DThe POST request is sent
Key Result
Always verify both the action (sharing) and the effect (access by shared user) to ensure sharing works end-to-end.