End-to-end automation test framework for the HR Employee Database Management System using Playwright and TypeScript.
This project covers automated testing of role-based access control and employee management features using a scalable Page Object Model, supporting multiple environments and CI/CD integration.
- Playwright - Modern web testing framework
- TypeScript - Type-safe JavaScript
- DotEnv - Environment configuration
- Faker.js - Test data generation
- Playwright Report Summary - Custom reporting
env/ # Environment configuration files
βββ local.env # Local environment settings
βββ prod.env # Production environment settings
lib/
βββ base.fixture.ts # Shared test fixture and page fixtures
pages/ # Page Object Model classes
βββ common.page.ts # Common page elements
βββ login.page.ts # Login page
βββ dashboard.page.ts # Dashboard page
βββ userManagement.page.ts # User Management page
βββ userManagementNewUser.page.ts # User Management New User page
βββ roleManagement.page.ts # Role Management page
βββ myProfile.page.ts # My Profile page
βββ myTeam.page.ts # My Team page
βββ ... # Other page objects
test_data/ # Test data files
βββ UserManagementTestData/
β βββ createTestUserData.json
β βββ userSearchTestData.json
β βββ user_create.csv
β βββ user_update.csv
β βββ employee_ids_delete.csv
β βββ UserExcelReport/
β βββ excelReport.xlsx
βββ dashboardExpectedData.json
βββ loginExpectedData.json
tests/ # Test specifications
βββ web/
βββ RoleManagement/
β βββ 1. TestShadowRole.spec.ts
β βββ 2.TestManagerRole.spec.ts
β βββ 3.TestEmployeeRole.spec.ts
βββ UserManagement/
βββ 1. UserCreateUpdateDeleteTest.spec.ts
utils/
βββ env.ts # Environment variable accessors
βββ global-setup.ts # Loads env/<name>.env via DotEnv
βββ Utility.ts # Common utilities
βββ ExcelCsvReader.ts # Excel/CSV file reader utility
.github/
βββ workflows/
βββ playwright-tests.yml # GitHub Actions workflow
playwright.config.ts # Playwright configuration
package.json # Project dependencies and scripts
- Node.js (v20 or higher) - Download from nodejs.org
- npm (v9.5.1 or higher)
-
Clone the repository
git clone <repository-url> cd HREmployeeDBAutomation
-
Install dependencies
npm install
-
Install Playwright browsers
npx playwright install --with-deps
The project supports multiple environments via .env files in the env/ directory and CI/CD environment variables.
- LOCAL - Local development
- PROD - Production
The project requires .env files in the env/ directory for different environments. Create the following files:
env/local.env- For local developmentenv/prod.env- For production/CI environment
Each environment file should include these variables:
# Environment Identifier
ENVIRONMENT_NAME=
# Application Base URL
BASE_URL=
# Super Admin Credentials
TEST_SUPER_ADMIN_EMAIL=
TEST_SUPER_ADMIN_PASSWORD=
# Admin Credentials
TEST_ADMIN_EMAIL=
TEST_ADMIN_PASSWORD=
# Manager Credentials
TEST_MANAGER_EMAIL=
TEST_MANAGER_PASSWORD=
# Employee Credentials
TEST_EMPLOYEE_EMAIL=
TEST_EMPLOYEE_PASSWORD=
# Shadow SBU User Credentials
TEST_SHADOW_SBU_EMAIL=
TEST_SHADOW_SBU_NAME=
TEST_SHADOW_SBU_PASSWORD=-
Local Development:
- Create
env/local.env - Set variables with local development values
- Variables will be loaded when running
npm run env:local
- Create
-
CI/CD Environment:
- Create
env/prod.envfor production fallback values - Set CI/CD environment variables in your pipeline
- CI/CD variables take precedence over
.envfiles - Missing values will fall back to
env/prod.env
- Create
- CI/CD environment variables (highest priority)
- Environment-specific
.envfile based onTEST_ENV - Default environment configuration (lowest priority)
These variables are exposed via utils/env.ts and can be accessed in tests using convenience accessors like ENV.SITE_BASE_URL.
Select which .env file to load by setting TEST_ENV (or test_env), default is local:
# Local .env (default)
npx playwright test
# Run tests in local environment
npm run env:local
# Run tests in production environment
npm run env:prod
# Run tests with coverage
npm run env:local:cov
npm run env:prod:covTests can be filtered using tags for selective execution:
# Run only UserManagement tests
npx playwright test --grep "@user-management"
# Run tests excluding a specific tag
npx playwright test --grep-invert "@user-management"
# Run specific test file
npx playwright test tests/web/UserManagement/1. UserCreateUpdateDeleteTest.spec.ts- Browser: Chrome (Desktop)
- Parallel Execution: Enabled locally, 1 worker in CI
- Retries: 2 retries on failure
- Timeout: 2 minutes per test
- Assertion Timeout: 1 minute
- Navigation Timeout: 3 minutes
- Headless Mode: Enabled in CI, disabled locally
The project follows the Page Object Model pattern with classes in the pages/ directory:
common.page.ts- Shared page elements and methodslogin.page.ts- Login page functionalityuserManagement.page.ts- User Management page interactionsuserManagementNewUser.page.ts- User Management New User formroleManagement.page.ts- Role Management pagedashboard.page.ts- Dashboard page- And other page objects for various features
Tests are organized in the tests/web/ directory:
- Shadow Role Tests - Tests for Shadow SBU role permissions
- Manager Role Tests - Tests for Manager role functionality
- Employee Role Tests - Tests for Employee role functionality
- User Create, Update, Delete Tests - Comprehensive CRUD operations for users
- Individual user creation and deletion
- User information updates
- Bulk user operations (create, update, delete)
- Search, filter, and export functionality
- Tagged with
@user-managementfor selective execution
Test data is stored in multiple formats in the test_data/ directory:
- JSON files - For structured test data (user data, expected results)
- CSV files - For bulk operations (user_create.csv, user_update.csv)
- Excel files - For Excel report testing
- Export Data - For testing data export functionality
Tests can be tagged for selective execution:
@user-management- All UserManagement test cases- Tags can be used with
--grepflag to run specific test suites
Key configuration options:
- Test Matching:
**.spec.tsfiles - Parallel Execution: 1 worker in CI, fully parallel locally
- Screenshots: Only on failure (local), off (CI)
- Traces: On (local), off (CI)
- Timeout: 2 minutes per test
- Assertion Timeout: 1 minute
- Navigation Timeout: 3 minutes
- Retries: 2 retries on failure
- Reporters:
- Local: HTML report, custom summary, list
- CI: JUnit XML, custom summary, GitHub annotations, list
Currently configured for:
- Chrome (Desktop)
Additional browsers can be easily added to the configuration by modifying the projects section in playwright.config.ts.
The framework provides comprehensive reporting:
- HTML Report - Interactive test results with screenshots and traces
- Custom Summary - Concise test execution summary
- JUnit Report - CI/CD integration (XML format)
- Console Output - Real-time test progress
The project includes a comprehensive GitHub Actions workflow (.github/workflows/playwright-tests.yml) for automated test execution with flexible configuration options.
- Manual Trigger (workflow_dispatch): Manually trigger tests on the
mainbranch with custom parameters - Environment Selection: Choose between
localorprodenvironment configurations - Test Filtering: Optionally filter tests by tags (e.g.,
@user-management,@role-management) - Environment Variable Validation: Automatic validation of required environment variables before test execution
- Secure Credential Management: Uses GitHub Secrets for sensitive credentials with .env file fallback
- Automated Setup:
- Node.js 20 with npm dependency caching for faster execution
- Playwright browser installation with system dependencies
- Clean dependency installation using
npm ci
- Test Execution: Runs Playwright tests with CI-optimized configuration
- Test Summary Generation: Automatic generation of detailed test execution summaries with pass/fail statistics
- Artifact Upload: Comprehensive artifact collection including reports, screenshots, and traces
- Artifact Retention: Test artifacts retained for 30 days
- Error Handling: Continues execution even on test failures to ensure artifact collection
- Job Timeout: 60-minute timeout to prevent hanging workflows
-
Navigate to Actions Tab
- Go to your GitHub repository
- Click on the Actions tab in the top navigation
-
Select Workflow
- In the left sidebar, click on Playwright Tests workflow
-
Run Workflow
- Click the Run workflow dropdown button (top right)
- Configure the workflow inputs:
-
Configure Workflow Inputs
Test Environment (required):
- Select
prodfor production environment (default) - Select
localfor local/development environment
Test Tags (optional):
- Leave empty to run all tests
- Enter
@user-managementto run only user management tests - Enter
@role-managementto run only role management tests - Use any custom tags defined in your test files
- Select
-
Start Execution
- Click the green Run workflow button
- Workflow will start executing immediately
Example 1: Run all tests in production environment
Test environment: prod
Test tags: (leave empty)
Example 2: Run user management tests in local environment
Test environment: local
Test tags: @user-management
Example 3: Run role management tests in production
Test environment: prod
Test tags: @role-management
Example 4: Run multiple tagged tests
Test environment: prod
Test tags: @user-management|@role-management
After triggering the workflow:
-
Monitor Execution
- The workflow run appears at the top of the Actions page
- Click on the run to view real-time logs
- Job name displays the selected environment: "Playwright Tests - prod environment"
-
View Test Summary
- Scroll to the bottom of the workflow run page
- The summary section displays:
- Execution details (environment, tags, triggered by)
- Test statistics (passed, failed, errors, skipped)
- Pass rate percentage
- Execution duration
- Artifact information
-
Check Individual Steps
- Click on the "test" job to expand all steps
- Review logs for each step:
- Environment variable validation
- Test execution output
- Summary generation
- Artifact upload confirmation
Test artifacts are automatically uploaded after every workflow run (success or failure):
Artifact Contents:
playwright-report/- HTML test reports and JUnit XMLtest-results/- Detailed test output and metadata- Screenshots (
.png,.jpg,.jpeg) - Visual evidence of test failures - Traces (
trace.zip,traces/) - Detailed execution traces for debugging
Artifact Naming Convention:
playwright-results-{environment}-{run_number}-{run_attempt}
Example: playwright-results-prod-42-1
How to Download Artifacts:
- Navigate to the workflow run page
- Scroll to the Artifacts section at the bottom
- Click on the artifact name to download as a ZIP file
- Extract the ZIP file locally
- Open
playwright-report/index.htmlin a browser to view the HTML report
Artifact Retention:
- Artifacts are retained for 30 days from the workflow run date
- After 30 days, artifacts are automatically deleted by GitHub
- Download important artifacts before expiration if long-term storage is needed
The workflow uses GitHub Secrets to securely manage sensitive credentials. Secrets take precedence over .env files.
Required Secrets:
BASE_URL- Application base URLTEST_SUPER_ADMIN_EMAIL- Super admin emailTEST_SUPER_ADMIN_PASSWORD- Super admin passwordTEST_ADMIN_EMAIL- Admin emailTEST_ADMIN_PASSWORD- Admin passwordTEST_MANAGER_EMAIL- Manager emailTEST_MANAGER_PASSWORD- Manager passwordTEST_EMPLOYEE_EMAIL- Employee emailTEST_EMPLOYEE_PASSWORD- Employee passwordTEST_SHADOW_SBU_EMAIL- Shadow SBU emailTEST_SHADOW_SBU_NAME- Shadow SBU nameTEST_SHADOW_SBU_PASSWORD- Shadow SBU password
Setup Instructions:
For detailed step-by-step instructions on configuring GitHub Secrets, see: π GitHub Secrets Setup Guide
The guide includes:
- How to access GitHub Secrets settings
- Complete list of required secrets with descriptions
- Step-by-step secret configuration process
- Environment variable precedence explanation
- Verification steps
- Troubleshooting common issues
Quick Setup:
- Go to repository Settings β Secrets and variables β Actions
- Click New repository secret
- Add each of the 12 required secrets listed above
- Run the workflow to verify configuration
The workflow uses a two-tier system for loading environment variables:
Precedence Order (Highest to Lowest):
-
GitHub Secrets (Highest Priority)
- Values configured in GitHub repository settings
- Encrypted and secure
- Override any other source
- Recommended for CI/CD environments
-
.env Files (Fallback)
- Located in
env/directory (env/prod.env,env/local.env) - Used when GitHub Secrets are not configured
- Loaded based on
test_envworkflow input - Useful for local development
- Located in
How It Works:
The utils/global-setup.ts file uses dotenv.config({ override: false }), which means:
- Variables already set in the environment (from GitHub Secrets) are preserved
- Missing variables are loaded from the appropriate .env file based on
test_env
Configuration Scenarios:
- Full GitHub Secrets: All secrets configured β .env files ignored (recommended for CI/CD)
- Partial GitHub Secrets: Some secrets configured β Missing values loaded from .env files
- No GitHub Secrets: All values loaded from .env files (local development only)
Environment Selection:
test_env: prodβ Falls back toenv/prod.envfor missing secretstest_env: localβ Falls back toenv/local.envfor missing secrets
The workflow includes automatic validation of required environment variables:
- Pre-execution Check: Validates all required variables before running tests
- Clear Error Messages: Lists missing variables with helpful instructions
- Fail Fast: Stops execution immediately if critical variables are missing
- Guidance: Provides links to setup documentation
If validation fails, the workflow will display:
- List of missing environment variables
- Instructions for configuring GitHub Secrets
- Alternative .env file setup instructions
Issue: "Missing required environment variables" error
- Solution: Configure all 12 required GitHub Secrets or ensure appropriate .env file exists
- See: GitHub Secrets Setup Guide
Issue: Tests run against wrong environment
- Solution: Verify
BASE_URLsecret value matches your intended environment - Check: Selected
test_envinput when triggering workflow
Issue: Workflow times out
- Solution: Review test execution time; consider splitting tests or increasing timeout
- Current Timeout: 60 minutes
Issue: Artifacts not uploaded
- Solution: Check test execution logs; ensure tests generate output files
- Verify:
playwright-report/andtest-results/directories exist after test run
Issue: Cannot trigger workflow
- Solution: Ensure you have write access to the repository
- Check: Workflow file exists at
.github/workflows/playwright-tests.yml
For more troubleshooting help, see the GitHub Secrets Setup Guide.
- Follow the existing code structure and naming conventions
- Add appropriate test data for new test cases
- Update environment configurations as needed
- Ensure all tests pass before submitting changes
- Browser Installation: Run
npx playwright install --with-depsif browsers are missing - Environment Variables: Ensure
.envfiles are properly configured - Timeout Issues: Adjust timeout values in
playwright.config.tsif needed
For debugging, you can run tests in non-headless mode:
npx playwright test --headedYou can also use Playwright's debug mode:
npx playwright test --debugAfter test execution, reports are generated in the playwright-report/ directory:
- HTML Report: Opens automatically after test completion (local only)
- Custom Summary: Available at
playwright-report/custom-summary.txt - JUnit Report: Available at
playwright-report/result.xml(CI only)
To view the HTML report manually:
npx playwright show-reportTo view trace files for debugging:
npx playwright show-trace trace.zipTrace files are available in the test-results/ directory after test execution.
This project is licensed under the ISC License.