Automated test suite for the JSONPlaceholder Posts API: https://jsonplaceholder.typicode.com/posts
This project demonstrates a professional, maintainable test automation framework using Python and pytest.
conftest.py → Pytest fixtures and configuration
core/ → HTTP layer (base API client)
└── api_client.py → Reusable API client with error handling
pages/ → Page Object Model (POM) pattern
└── post_page.py → Posts API abstraction layer
tests/ → Test cases
├── test_posts.py → Positive tests
└── test_negative_posts.py → Negative/error scenario tests
data/ → Test data and constants
└── test_data.py → Test data definitions
utils/ → Utilities
├── config.py → Configuration (base URL, timeouts)
├── exceptions.py → Custom exceptions
└── logger.py → Logging configuration
✅ Python and Pytest - Modern test framework
✅ Positive Tests - Validates API functionality
✅ Negative Tests - Error handling and edge cases
✅ Schema Validation - Ensures response structure and data types
✅ Logging - File and console logging for debugging
✅ Exception Handling - Custom exceptions and error management
✅ Reusable Components - API client and page objects
✅ Maintainable Structure - Clean architecture for scalability
- Python 3.7+
- pip (Python package manager)
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtThis installs:
pytest- Test frameworkrequests- HTTP client library
pytestpytest -vpytest tests/test_posts.py -v
pytest tests/test_negative_posts.py -vpytest tests/test_posts.py::TestPosts::test_get_all_posts -vpytest --log-cli-level=INFO-
test_get_all_posts - Validates fetching all posts
- Checks HTTP 200 status
- Verifies response is a list
- Validates schema and data types of each post
-
test_get_single_post - Validates fetching a post by ID
- Checks HTTP 200 status
- Verifies correct post ID in response
- Validates schema and data types
- Ensures non-empty required fields
-
test_get_post_with_invalid_id - Tests handling of non-existent IDs
- Expects HTTP 404 status
- Verifies empty response body
-
test_get_post_with_out_of_range_id - Tests out-of-range IDs
- Expects HTTP 404 status
-
test_get_post_with_invalid_data_type - Tests invalid input handling
- Tests with non-integer ID values
- Verifies proper error handling
Each post object is validated to contain:
userId(integer, positive value)id(integer, positive value)title(non-empty string)body(non-empty string)
Edit utils/config.py to customize:
BASE_URL = "https://jsonplaceholder.typicode.com/" # API base URL
TIMEOUT = 10 # Request timeout in secondsLogs are generated in the logs/ directory:
- Console: INFO and above
- File: DEBUG and above
Configure in utils/logger.py
Custom exception APIException is raised for:
- Connection errors
- Timeout errors
- HTTP errors
- Unexpected errors
See requirements.txt:
- pytest>=7.0.0
- requests>=2.25.0
✓ Page Object Model (POM) pattern for maintainability
✓ Centralized configuration
✓ Comprehensive logging
✓ Reusable fixtures
✓ Clear test naming
✓ Detailed assertions with messages
✓ Schema validation
✓ Error scenario testing
✓ DRY (Don't Repeat Yourself) principle
Ensure you're in the project root directory when running pytest.
Verify the API is accessible: https://jsonplaceholder.typicode.com/posts
Increase timeout in utils/config.py:
TIMEOUT = 20 # Increase to 20 seconds