What is Playwright?

 What is Playwright?


Playwright is a browser automation framework developed by Microsoft. It allows you to automate Chromium, Firefox, and WebKit browsers for testing web applications.


It supports:


JavaScript

TypeScript

Python

Java

.NET

Step 1: Install Node.js


Playwright works with Node.js.


Download Node.js


Go to:


Node.js Official Website


Download the LTS version.


Verify Installation


Open Terminal or Command Prompt and run:


node -v


You should see something like:


v22.0.0


Also verify npm:


npm -v

Step 2: Create a Project Folder


Create a new folder for your Playwright project.


mkdir playwright-project

cd playwright-project

Step 3: Initialize Node Project


Run:


npm init -y


This creates a package.json file.


Step 4: Install Playwright


Install Playwright using npm:


npm install -D playwright

Step 5: Install Browsers


Now install supported browsers:


npx playwright install


This downloads:


Chromium

Firefox

WebKit

Step 6: Verify Installation


Check the installed version:


npx playwright --version


Example:


Version 1.54.0

Step 7: Create Your First Test


Create a file named:


example.spec.js


Add this code:


const { test, expect } = require('@playwright/test');


test('homepage has title', async ({ page }) => {

  await page.goto('https://playwright.dev/');


  await expect(page).toHaveTitle(/Playwright/);

});

Step 8: Install Playwright Test Runner


Install the test package:


npm init playwright@latest


This command:


Installs Playwright Test

Creates test folders

Adds example tests

Creates configuration files

Step 9: Run Tests


Run:


npx playwright test


You’ll see test results in the terminal.


Step 10: Open HTML Report


After tests finish:


npx playwright show-report


A browser report opens automatically.


Project Structure Example

playwright-project/

├── tests/

├── playwright.config.js

├── package.json

└── node_modules/

Install Playwright with TypeScript (Optional)


If you want TypeScript support:


npm init playwright@latest


Choose:


TypeScript


during setup.


Install Playwright for Python


If you use Python:


Install Package

pip install playwright

Install Browsers

playwright install


Official docs:


Playwright Python Docs


Common Commands

Command Purpose

npx playwright test Run all tests

npx playwright test file.spec.js Run one file

npx playwright codegen Record actions

npx playwright show-report Open test report

Useful Features


Playwright supports:


Cross-browser testing

Auto waiting

Screenshots

Video recording

Parallel execution

Mobile emulation

API testing

Learn Playwright Course At Quality Thought Training Institute in Hyderabad

Get Directions

Comments

Popular posts from this blog

Handling Frames and Iframes Using Playwright

Working with Cookies and Local Storage in Playwright

Cybersecurity Internship Opportunities in Hyderabad for Freshers