Setting Up Playwright for the First Time
Setting Up Playwright for the First Time
Playwright is a powerful end-to-end testing framework developed by Microsoft. It supports multiple browsers (Chromium, Firefox, WebKit) and allows testing on modern web apps with speed and reliability.
Here’s a step-by-step guide to help you set it up for the first time:
๐ง 1. Prerequisites
Before installing Playwright, make sure you have:
Node.js (version 14 or higher recommended)
Check by running:
bash
Copy
Edit
node -v
npm or yarn (comes with Node.js)
Check by running:
bash
Copy
Edit
npm -v
๐ฆ 2. Install Playwright
Open your terminal and run the following command in your project directory:
bash
Copy
Edit
npm init playwright@latest
This command will:
Install Playwright
Create a basic project structure
Ask if you want GitHub Actions for CI
Ask which browsers to install (Chromium, Firefox, WebKit)
After setup, you’ll see a folder structure like:
lua
Copy
Edit
tests/
playwright.config.ts
package.json
๐งช 3. Run a Test
You can run the sample test using:
bash
Copy
Edit
npx playwright test
This will execute the default test in the tests folder and give you output in the terminal.
๐ 4. Open Test Report
Playwright generates an HTML report for test results. You can view it by running:
bash
Copy
Edit
npx playwright show-report
๐งฐ 5. Record a Test (Optional)
To generate a test by interacting with a page manually:
bash
Copy
Edit
npx playwright codegen https://example.com
This opens a browser where you can click around, and Playwright will generate code for your actions.
๐ง 6. Configure Playwright
The playwright.config.ts or playwright.config.js file lets you customize settings like:
Base URL
Test timeouts
Parallel execution
Browser/device settings
Example:
ts
Copy
Edit
use: {
baseURL: 'https://your-app.com',
headless: false,
viewport: { width: 1280, height: 720 },
}
✅ Conclusion
Playwright is easy to set up and provides a powerful toolkit for browser automation. Once it's installed, you can quickly start writing and running tests across all major browsers.
Learn Testing Tools Training in Hyderabad
Read More
How to Write BDD Tests in Cucumber
Mobile Automation with Appium 101
Test Automation Basics with Katalon
Open Source vs Paid Testing Tools
Visit Our IHUB Talent Training Institute in Hyderabad
Comments
Post a Comment