A robust API testing framework built with Playwright for testing RESTful APIs. This framework follows best practices for API testing with support for data generation, request handling, and comprehensive logging.
tests/- Root directory containing all test-related files and foldersfunctions/- Contains reusable function modulesrestfulAPI/- API service layer implementationsRestFullAPIService.js- Core service class handling all API operations with clean interfaces
tests/support/- Contains all supporting utilities and configurationsconfig/- Configuration related filesAPIConfig.js- Centralized API endpoints and configuration settings
dataGenerator/- Test data generation utilitiesactions/randomDataGenerator/- Random data generation modulesDataGenerator.js- Generates random test data for API requests
utils/- Utility functions and helper classesenums/- Enumeration and constant valuesEnums.js- Centralized enum definitions for the framework
APIUtils.js- Core HTTP request handling utilityTestAssertions.js- Common test assertion methods
tests/testcases/- Contains all test suitestestCaseAPI/- API-specific test casesObjects.spec.js- Test suite for object-related API endpoints
RestFullAPIService.js: Service class that handles all API operations and provides a clean interface for test cases
APIUtils.js: Core utility for making HTTP requests and handling responsesAPIConfig.js: Configuration file containing API endpoints and other settingsEnums.js: Enumeration values used across the frameworkTestAssertions.js: Common assertion methods for test validation
DataGenerator.js: Generates random test data for API requests
Objects.spec.js: Test suite for object-related API endpoints implementing CRUD operations
- Service-Based Architecture: Organized API interactions through service classes
- Data Generation: Random data generation for test scenarios
- Request Handling: Centralized request management through APIUtils
- Response Validation: Structured response validation and assertions
- Enum Management: Centralized management of constant values
- CRUD Testing: Complete coverage of Create, Read, Update, and Delete operations
- Service Layer Pattern: API operations are abstracted through service classes
- Reusable Utilities: Common functionalities are centralized in utility classes
- Data Generation: Dynamic test data generation for robust testing
- Structured Assertions: Standardized validation through TestAssertions
- Clean Code Structure: Well-organized project structure with clear separation of concerns
- Install dependencies:
npm install- Configure environment variables in
.envfile:
API_BASE_URL=your_api_base_urlTo run the tests:
npx playwright testTo run a specific test file:
npx playwright test tests/testcases/testCaseAPI/Objects.spec.jsTo view the HTML test report:
# Default port (9323)
npx playwright show-report
# If port 9323 is in use, specify a different port
npx playwright show-report --port 9324If you encounter a port in use error (EADDRINUSE), try these solutions:
For Windows:
netstat -ano | findstr :9323
taskkill /PID <PID> /FFor Mac/Linux:
lsof -i :9323
kill -9 <PID>| View Profile | View Profile | View Profile | View Profile |
| View Profile | View Profile | View Profile | View Profile |