Skip to content

Latest commit

Β 

History

History
111 lines (75 loc) Β· 2.46 KB

File metadata and controls

111 lines (75 loc) Β· 2.46 KB

API Testing with Playwright

A TypeScript-based API testing framework using Playwright for testing REST APIs.


πŸ“‹ Prerequisites

  • Node.js (v18 or later recommended)
  • npm

πŸš€ Getting Started

1. Install dependencies

npm install

2. Install Playwright browsers

npx playwright install

3. Configure environment variables

This project uses a .env file to store sensitive credentials that are never committed to source control.

Create a .env file in the project root by copying the example below:

DL_USERNAME=your_username
DL_PASSWORD=your_password

⚠️ Important: The .env file must not be committed to the repository. Make sure .env is listed in your .gitignore.


πŸ§ͺ Running Tests

npm test

To run a specific test file:

npx playwright test tests/delivery/auth.spec.ts

To open the HTML report after a run:

npx playwright show-report

πŸ”§ Other Scripts

Script Description
npm test Run all Playwright tests
npm run lint Lint test files with ESLint
npm run prettier:check Check formatting with Prettier
npm run prettier:format Auto-format test files with Prettier

πŸ”’ CI / Secrets Configuration

When running tests in a CI environment, do not store credentials in a .env file. Instead, configure the environment variables as CI secrets/environment variables.

GitHub Actions

The workflow file is already provided at .github/workflows/playwright.yml.

  1. Go to your repository β†’ Settings β†’ Secrets and variables β†’ Actions.
  2. Click New repository secret and add each variable:
    • DL_USERNAME
    • DL_PASSWORD
  3. The workflow will automatically pick them up:
- name: Run tests
  env:
    DL_USERNAME: ${{ secrets.DL_USERNAME }}
    DL_PASSWORD: ${{ secrets.DL_PASSWORD }}
  run: npm test

πŸ“ Project Structure

.
β”œβ”€β”€ dto/                  # Data Transfer Objects (request/response models)
β”œβ”€β”€ helpers/              # Reusable API helper functions
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ delivery/         # Authenticated API tests
β”‚   └── example-no-auth/  # Unauthenticated / simple API tests
β”œβ”€β”€ .env                  # Local environment variables (⚠️ not committed)
β”œβ”€β”€ playwright.config.ts  # Playwright configuration
└── package.json