Multi Environment | Multi Language UI Validation
A clean, maintainable, and scalable test automation framework built with Playwright and TypeScript, designed to support:
- Multiple test environments (test / preprod / prod)
- Multi-language UI validation (TR / EN)
- Centralized configuration and test data management
- Page Object Model (POM) for reusable UI interactions
- CI/CD integration support
- End-to-End Testing: Playwright powers reliable E2E tests
- Type-Safe Tests: Written in TypeScript for maintainability
- Multi-Environment Support: Easily switch between test, preprod, and prod
- Multi-Language Validation: Validate UI in multiple languages (TR / EN etc)
- Clean Architecture: Separate layers for tests, page objects, data, and configuration
- Reusable Page Objects: Encapsulate UI interactions for cleaner test code
- Environment-Based Test Users: Different credentials per environment
- CI/CD Friendly: Easily integrates with pipelines
- Debugging Tools: Screenshots, videos, and trace viewer support
- Playwright β End-to-end testing framework
- TypeScript β Type-safe language for maintainable tests
- Azure Pipelines β CI/CD integration
- Node.js & npm/yarn β dependency management
git clone https://github.com/CemalYaver/PlaywrightCore.git
cd PlaywrightCorenpm installnpm install dotenv --save-devThis package is required to load .env files within your code.
It is only needed for local development and testing.
It is not required when deploying to production.
npx playwright install --with-depsThe environment is selected using the ENV parameter, and the language is set using the LANG parameter.
Example: Test environment in English
ENV=test LANG=en npx playwright testExample: Preprod environment in Turkish
ENV=preprod LANG=tr npx playwright testNote: Adjust the ENV and LANG values according to your testing needs.
This will create a new .env.prod file using .env.prod.example as a template.
PROD_ADMIN_EMAIL=
PROD_ADMIN_PASSWORD=
PROD_USER1_EMAIL=
PROD_USER1_PASSWORD=
PROD_USER2_EMAIL=
PROD_USER2_PASSWORD=
ENV=prod LANG=en npx playwright testNote on Environment Users
Production:
- Local .env.prod file must be created and filled with credentials.
- For running production tests in CI/CD (e.g., Azure Pipelines), make sure production environment variables are securely configured in your pipeline.
Test / Preprod:
- Users for these environments are stored directly in users.test.ts and users.preprod.ts files.
- No additional local .env files are needed.
Tests
β
Page Objects
β
Base Page (Reusable UI actions for all pages)
β
Test Data (Users, Messages β centralized test data)
β
Environment Configuration (ENV, BASE_URL, LANG β environment-specific settings)
Explanation:
-
Tests β Business logic and test scenarios are defined here.
-
Page Objects β Encapsulate UI interactions for each page, improving reusability.
-
Base Page β Contains common UI actions (click, fill, wait, etc.) shared across all pages.
-
Test Data β Centralized place for users, messages, and other test inputs.
-
Environment Configuration β Handles environment-specific settings like ENV, BASE_URL, and LANG.
PLAYWRIGHT-TS-DEMO/
β
ββ config/
β ββ baseUrls.ts
β ββ env.ts
β ββ index.ts
β ββ languages.ts
β
ββ pages/
β ββ base.page.ts
β ββ home.page.ts
β ββ login.page.ts
β
ββ test-data/
β ββ messages/
β β ββ en/
β β β ββ home.ts
β β β ββ index.ts
β β β ββ login.ts
β β β ββ profile.ts
β β ββ tr/
β β ββ home.ts
β β ββ index.ts
β β ββ login.ts
β β ββ profile.ts
β ββ users/
β ββ index.ts
β ββ preprod.ts
β ββ prod.ts
β ββ test.ts
β
ββ test-results/
β ββ .last-run.json
β
ββ tests/
β ββ login.spec.ts
β
ββ .env.prod
ββ .env.prod.example
ββ .gitignore
ββ package-lock.json
ββ package.json
ββ playwright.config.ts
ββ readme.md
ββ tsconfig.json
Test users are separated by environment. The correct dataset is automatically selected according to the ENV variable.
test-data/users/
ββ index.ts # Central export, selects users by ENV
ββ users.test.ts # Test environment users
ββ users.preprod.ts # Preprod environment users
ββ users.prod.ts # Production environment users
Note: Each file contains user credentials for its respective environment. index.ts automatically exports the correct users based on ENV.
In this framework, User Interface (UI) interactions are separated from test logic to keep the code clean, readable, and maintainable.
pages/
βββ base.page.ts # Common reusable actions for all pages
βββ login.page.ts # Login page-specific actions
βββ home.page.ts # Home page-specific actions
Benefits of POM:
-
Reusable page actions β Avoid duplicating UI code across tests.
-
Cleaner test files β Test scripts focus on business logic.
-
Easier maintenance β Changes in UI affect only page objects, not test files.
Focus on business logic; Page Objects handle UI actions.
This is an example of Login tests implemented with Playwright and Page Object Model (POM).
import { test } from '@playwright/test';
import LoginPage from '../pages/login.page';
import HomePage from '../pages/home.page';
import { users } from '../test-data/users';
test.describe('Login Tests', () => {
let loginPage: LoginPage;
test.beforeEach(async ({ page }) => {
const homePage = new HomePage(page);
loginPage = new LoginPage(page);
await homePage.open();
await homePage.changeLanguage();
await homePage.clickLoginButton();
});
test('Login with valid credentials', async () => {
await loginPage.login(users.ADMIN);
await loginPage.verifyLoginSuccess();
});
test('Login with invalid credentials', async () => {
await loginPage.login(users.USER1_INVALID_PASSWORD);
await loginPage.verifyLoginError();
});
});trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
ENV: test
LANG: en
BASE_URL: https://test.site.com
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- script: npm install
displayName: 'Install dependencies'
- script: npx playwright install --with-deps
displayName: 'Install Playwright browsers'
- script: npx playwright test
displayName: 'Run Playwright tests'Playwright provides built-in tools to help debug failing tests and analyze test runs:
- Trace Viewer β inspect test execution step by step
- Screenshots on failure β automatically capture screenshots when a test fails
- Video recordings β record test runs for visual debugging
- HTML test reports β view structured results in a browser
use: {
trace: 'on-first-retry', // records trace only on first retry
screenshot: 'only-on-failure' // captures screenshot only if the test fails
video: 'retain-on-failure', // save video if test fails
}