Skip to content

This repository contains a project for automating REST API testing using Playwright. It leverages Playwright's powerful capabilities for making HTTP requests and validating API responses, ensuring robust and reliable API test coverage.

Notifications You must be signed in to change notification settings

BharathaSachintha/restAPI_playwright

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Testing Framework with Playwright Codacy Badge

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.

Project Structure

Core Service Files

  • tests/ - Root directory containing all test-related files and folders
    • functions/ - Contains reusable function modules
      • restfulAPI/ - API service layer implementations
        • RestFullAPIService.js - Core service class handling all API operations with clean interfaces

Support Files

  • tests/support/ - Contains all supporting utilities and configurations
    • config/ - Configuration related files
      • APIConfig.js - Centralized API endpoints and configuration settings
    • dataGenerator/ - Test data generation utilities
      • actions/randomDataGenerator/ - Random data generation modules
        • DataGenerator.js - Generates random test data for API requests
    • utils/ - Utility functions and helper classes
      • enums/ - Enumeration and constant values
        • Enums.js - Centralized enum definitions for the framework
      • APIUtils.js - Core HTTP request handling utility
      • TestAssertions.js - Common test assertion methods

Test Cases

  • tests/testcases/ - Contains all test suites
    • testCaseAPI/ - API-specific test cases
      • Objects.spec.js - Test suite for object-related API endpoints

Key Components

Service Layer

  • RestFullAPIService.js: Service class that handles all API operations and provides a clean interface for test cases

Support Utilities

  • APIUtils.js: Core utility for making HTTP requests and handling responses
  • APIConfig.js: Configuration file containing API endpoints and other settings
  • Enums.js: Enumeration values used across the framework
  • TestAssertions.js: Common assertion methods for test validation

Data Generation

  • DataGenerator.js: Generates random test data for API requests

Test Cases

  • Objects.spec.js: Test suite for object-related API endpoints implementing CRUD operations

Framework Features

  • 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

Best Practices Implemented

  1. Service Layer Pattern: API operations are abstracted through service classes
  2. Reusable Utilities: Common functionalities are centralized in utility classes
  3. Data Generation: Dynamic test data generation for robust testing
  4. Structured Assertions: Standardized validation through TestAssertions
  5. Clean Code Structure: Well-organized project structure with clear separation of concerns

Environment Setup

  1. Install dependencies:
npm install
  1. Configure environment variables in .env file:
API_BASE_URL=your_api_base_url

Test Execution

To run the tests:

npx playwright test

To run a specific test file:

npx playwright test tests/testcases/testCaseAPI/Objects.spec.js

To 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 9324

If you encounter a port in use error (EADDRINUSE), try these solutions:

For Windows:

netstat -ano | findstr :9323
taskkill /PID <PID> /F

For Mac/Linux:

lsof -i :9323
kill -9 <PID>

Contributors

View Profile

Design & Infrastructure:

Bharatha Sachintha
View Profile

Scope & Management:

View Profile

Documentation(s):

Bharatha Sachintha
View Profile

Development / System Integrations:

Bharatha Sachintha
View Profile

Test Cases / QA:

View Profile

Scripting:

Bharatha Sachintha
View Profile

DevOps:

View Profile

Releases

Initial Release
19 Jan 2025
Bharatha Sachintha
V1.01.00
19 Jan 2025
Bharatha Sachintha

About

This repository contains a project for automating REST API testing using Playwright. It leverages Playwright's powerful capabilities for making HTTP requests and validating API responses, ensuring robust and reliable API test coverage.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published