This README provides guidelines for setting up, writing, and maintaining test cases in the LEAF QA Automation Framework. It ensures consistency and clarity for all team members working on test automation.
Before running tests, ensure you have the following installed:
- Node.js
- npm (Comes with Node.js)
- Playwright (Installed globally or locally)
Run the following command to install project dependencies:
npm install
After installing dependencies, install Playwright browsers using:
npx playwright install
This ensures that all required browsers (Chromium, Firefox, WebKit) are downloaded and available for testing.
The framework follows this folder structure:
LEAF-Automated-Tests/
├── end2end/
│ ├── tests/ # Contains all test files
│ │ ├── homepage.spec.ts # Example test file
│ │ ├── adminPanel.spec.ts # Example test file
│ │ ├── global.setup.ts # Handles global setup logic before tests
│ ├── playwright.config.ts # Configuration file for Playwright
Run all test cases using:
npx playwright test
To run tests with a visible browser UI:
npx playwright test --headed
To execute a specific test file, use:
npx playwright test end2end/tests/homepage.spec.ts
To generate an HTML report after test execution:
npx playwright test --reporter=html
This will create a detailed test report in an HTML format that you can open in a browser.
- All test files should be placed in the
tests/
folder. - Group related tests logically and use clear file names to indicate their purpose.
- Use descriptive and meaningful names.
- Example:
homepage.spec.ts
,adminPanelSettings.spec.ts
- Example:
- Always use
.spec.ts
as the suffix for Playwright compatibility.
- Keep test names concise yet descriptive.
- Good Example:
shouldDisplayErrorMessageWhenLoginFails
- Poor Example:
errorTest
- Good Example:
- Use camelCase for all variable and function names.
- Good Example:
loginButton
,validateLoginPage
- Poor Example:
btn1
,checkPage
- Good Example:
- Each test case written in the framework must match the corresponding test name in the Excel sheet.
- The Excel sheet serves as the source of truth for test case documentation and steps.
- Ensure that test names in scripts align exactly with those in the sheet to maintain traceability.
- Use Playwright's
test
blocks to define test cases:import { test, expect } from '@playwright/test'; test('should navigate to the homepage', async ({ page }) => { await page.goto('https://example.com'); await expect(page).toHaveTitle('Example Domain'); });
- Always include assertions to validate results:
await expect(page.locator('#successMessage')).toHaveText('Form saved successfully');
- Use shared setup logic with hooks like
test.beforeEach
:test.beforeEach(async ({ page }) => { await page.goto('https://example.com/login'); });
- Keep test cases modular, testing one scenario at a time.
-
Avoid hardcoding values. Store reusable test data in
.json
files or constants:{ "username": "testUser", "password": "securePassword" }
-
Use libraries like
faker
to generate random inputs when needed.
-
Add comments where necessary to explain complex test logic.
// Navigate to the login page await page.goto('https://example.com/login');
-
Avoid redundant comments that restate obvious actions.
This guide helps you set up and run tests efficiently using Playwright. For further details, refer to the Playwright Documentation.