This repository contains a comprehensive collection of Playwright tests for web automation, featuring examples in multiple languages and frameworks including TypeScript, C#, HTML, and Gherkin.
- HTML: 71.7%
- C#: 18%
- TypeScript: 10.2%
- Gherkin: 0.1%
This repository is organized into four primary projects:
A comprehensive suite of 25+ discrete test files (ranging from example.spec.ts to example23.spec.ts, and recorder examples).
Purpose: Demonstrates specific Playwright features, locator strategies, and automation techniques in TypeScript.
Key Files: Located in the tests/ directory.
A concise demonstration project containing a few test files (example.spec.ts, test-1.spec.ts, test-2.spec.ts).
This project functions as a pragmatic, encapsulated example of a Playwright test suite.
A full-featured C# implementation of Playwright tests.
-
Features: Includes Page Object Models (POM) for sites like OrangeHRM, Automation Exercise, and SwagLabs.
-
Test Framework: Utilizes NUnit/MSTest/Xunit structures for various UI challenges (Checkboxes, Radio buttons, Alerts, etc.).
A dedicated project for learning unit testing and integration testing using the xUnit framework in C#.
Content: Includes examples of MemberData, Theory, and Fact attributes for data-driven testing.
git clone <your-repository-url>
cd Playwright# For the basic examples
cd PlaywrightBasicsTypeScript
# OR
# For the demo project
cd playwrightdemo# Prerequisite: Node.js must be installed on the local system.
npm install# This process may execute automatically post-npm install
npx playwright install# Execute all tests in headless mode (default configuration)
npx playwright test
# Execute tests in headed mode for browser visualization
npx playwright test --headed
# Execute a specific test file
npx playwright test tests/example10.spec.ts
# View the generated HTML test report
npx playwright show-report
# Execute using codegen
npx playwright codegen <URL>cd PlaywrightCSharpdotnet restoredotnet builddotnet test# Single test file
dotnet test --filter "XunitBasics.CalculatorTest.cs"
# Single test with detailed output
dotnet test --filter "XunitBasics.ConsoleRunTests.cs" --logger "console;verbosity=detailed"| File/Directory | Description |
|---|---|
tests/ |
Contains all test specification (.spec.ts) files for TypeScript projects |
playwright.config.ts |
Primary configuration file for Playwright; defines project-level settings, browser configurations (Chromium, Firefox, WebKit), test timeouts, and reporter options |
pages/ |
(Within PlaywrightCSharp) Contains reusable Page Object classes |
Playwright_Practice.csproj |
Project configuration for C# automation |
package.json |
Defines the project's Node.js dependencies, including the Playwright framework |
- Multi-language support: TypeScript, C#, and Gherkin examples
- Multiple frameworks: Playwright Test, xUnit, NUnit, MSTest
- Page Object Models: Reusable test components for maintainability
- Comprehensive examples: 25+ test scenarios covering various automation techniques
- Data-driven testing: Examples of parameterized and theory-based tests
- Visual reporting: HTML test reports and trace viewer integration
- Cross-browser testing: Support for Chromium, Firefox, and WebKit
- Headless execution: Full support for headless and headed modes
- Playwright Documentation
- Playwright API Reference
- xUnit Documentation
- Page Object Model Pattern
- Playwright Best Practices
Playwright supports testing across three major browsers:
| Browser | Headless | Headed |
|---|---|---|
| Chromium | β | β |
| Firefox | β | β |
| WebKit | β | β |
All browsers run on Linux, macOS, and Windows platforms.
The playwright.config.ts file allows you to configure:
- Browser launch options
- Test timeout settings
- Retry strategies
- Reporter formats (HTML, JSON, JUnit)
- Base URL for test applications
- Device emulation settings
# Run tests in debug mode
npx playwright test --debug
# Use Playwright Inspector
npx playwright test --inspect
# Generate trace for failed tests
npx playwright test --trace onPlaywright provides a powerful code generation tool to record your actions:
# Start Playwright Codegen
npx playwright codegen <URL>
# Example: Generate tests for a website
npx playwright codegen https://example.comPlaywright/
βββ PlaywrightBasicsTypeScript/
β βββ tests/
β β βββ example.spec.ts
β β βββ example1.spec.ts
β β βββ ... (25+ test files)
β βββ playwright.config.ts
β βββ package.json
β βββ node_modules/
β
βββ playwrightdemo/
β βββ tests/
β β βββ example.spec.ts
β β βββ test-1.spec.ts
β β βββ test-2.spec.ts
β βββ package.json
β
βββ PlaywrightCSharp/
β βββ pages/
β β βββ OrangeHRMPage.cs
β β βββ AutomationExercisePage.cs
β β βββ SwagLabsPage.cs
β βββ tests/
β β βββ UITests.cs
β β βββ AlertsTest.cs
β βββ Playwright_Practice.csproj
β βββ obj/bin/
β
βββ XunitBasics/
β βββ CalculatorTest.cs
β βββ ConsoleRunTests.cs
β βββ XunitBasics.csproj
β
βββ README.md
- Choose your language: TypeScript or C#
- Navigate to the project directory
- Install dependencies (npm for TypeScript, dotnet for C#)
- Run the tests using the commands provided above
- View the results in the generated HTML report
Solution: Run the following command:
npx playwright installSolution: Increase the timeout in your test file or config:
npx playwright test --timeout=30000Solution: Specify a different port or stop the process using that port.
Solution: Ensure .NET SDK is installed:
dotnet --version
dotnet restore
dotnet build --configuration ReleaseCreated for learning and demonstrating web automation best practices using Playwright across multiple programming languages and frameworks.
This repository is provided as an educational resource for learning Playwright automation testing.