0
0
Postmantesting~15 mins

Collections and folders in Postman - Build an Automation Script

Choose your learning style9 modes available
Create a Postman collection with folders and add requests
Preconditions (2)
Step 1: Click on 'New' and select 'Collection' to create a new collection named 'User API Tests'
Step 2: Inside the 'User API Tests' collection, create a folder named 'User Creation'
Step 3: Add a POST request to the 'User Creation' folder with URL 'https://api.example.com/users'
Step 4: Set the request body to JSON with fields 'name' and 'email'
Step 5: Save the request with the name 'Create User'
Step 6: Create another folder inside the collection named 'User Retrieval'
Step 7: Add a GET request to the 'User Retrieval' folder with URL 'https://api.example.com/users/{{userId}}'
Step 8: Save the request with the name 'Get User'
Step 9: Verify that the collection contains two folders each with one request
✅ Expected Result: The 'User API Tests' collection contains two folders named 'User Creation' and 'User Retrieval'. Each folder contains one request named 'Create User' and 'Get User' respectively with correct URLs and request types.
Automation Requirements - Postman Collection Runner with Newman
Assertions Needed:
Verify collection structure has two folders
Verify each folder contains exactly one request
Verify request methods and URLs are correct
Best Practices:
Use Postman Collection JSON format for defining collections and folders
Use descriptive names for collections, folders, and requests
Use variables for dynamic parts of URLs
Validate collection structure programmatically before running tests
Automated Solution
Postman
{
  "info": {
    "name": "User API Tests",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "User Creation",
      "item": [
        {
          "name": "Create User",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"John Doe\", \"email\": \"john@example.com\"}"
            },
            "url": {
              "raw": "https://api.example.com/users",
              "protocol": "https",
              "host": ["api", "example", "com"],
              "path": ["users"]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "User Retrieval",
      "item": [
        {
          "name": "Get User",
          "request": {
            "method": "GET",
            "url": {
              "raw": "https://api.example.com/users/{{userId}}",
              "protocol": "https",
              "host": ["api", "example", "com"],
              "path": ["users", "{{userId}}"]
            }
          },
          "response": []
        }
      ]
    }
  ]
}

The JSON defines a Postman collection named User API Tests. It has two folders: User Creation and User Retrieval.

Each folder contains one request. The User Creation folder has a POST request to create a user with a JSON body. The User Retrieval folder has a GET request with a variable {{userId}} in the URL.

This structure matches the manual test case steps and expected results. Using this JSON, you can import the collection into Postman or run it with Newman.

Common Mistakes - 4 Pitfalls
Not using folders inside the collection
Hardcoding dynamic values instead of using variables
Missing Content-Type header for POST requests
Incorrect JSON formatting in request body
Bonus Challenge

Now add data-driven testing by running the 'Create User' request with 3 different sets of user data

Show Hint