This project is an advanced test automation framework using Playwright for both API and UI testing with the Page Object Model (POM) design pattern.
testautomation-playwright/
├── api/
│ └── apiClient.js
├── pages/
│ ├── basePage.js
│ └── loginPage.js
├── tests/
│ ├── apiTests/
│ │ └── apiTest.test.js
│ └── uiTests/
│ └── loginPage.test.js
├── utils/
│ ├── testData/
│ │ ├── development/
│ │ │ └── testData.js
│ │ ├── staging/
│ │ │ └── testData.js
│ │ └── production/
│ │ └── testData.js
│ ├── helpers/
│ │ └── testHelper.js
├── .gitignore
├── .eslintrc.json
├── .prettierrc
├── package.json
├── playwright.config.js
├── README.md
└── .env
-
Install dependencies:
npm install
-
Create a
.env
file:Create a
.env
file in the root directory with the following content:BASE_URL=https://api.github.com LOGIN_ENDPOINT=/api/login USER_DETAILS_ENDPOINT=/api/user/details API_KEY=your_api_key_here
-
Run tests:
npx playwright test
playwright.config.js
: Configuration file for Playwright.pages/
: Contains page object model classes.tests/
: Contains test scripts.utils/testData/
: Contains test data for different environments.utils/helpers/testHelper.js
: Contains helper functions for fetching test data.
-
To run tests with the UI visible:
npx playwright test
-
To run tests in Chrome:
npx playwright test --project=chrome
-
To run tests in Firefox:
npx playwright test --project=firefox
-
To run tests in WebKit:
npx playwright test --project=webkit
-
To run smoke tests:
npx playwright test --grep @smoke
-
To run regression tests:
npx playwright test --grep @regression
-
To run API tests:
npx playwright test --grep @api
- Screenshots, videos, and traces are retained on test failures.
- Tests are retried up to 2 times on failure.
- Test results are stored in the
reports/test-results
directory.
-
To lint the code:
npm run lint
-
To format the code:
npm run format
-
Development Environment:
dotenv -e .env.development npx playwright test
-
Staging Environment:
dotenv -e .env.staging npx playwright test
-
Production Environment:
dotenv -e .env.production npx playwright test
- ESLint Configuration:
.eslintrc.json
- Prettier Configuration:
.prettierrc
- Environment Variables:
.env
By following these instructions, you can set up and run tests using the Playwright framework for both API and UI testing.