Installation guide

Installation guide

Before installing Playwright, ensure your system meets the following requirements:

In my Setting up my environment course I defined all kinds of checks you can do in order to validate if your environment is ready for testing

Installation Steps

  1. Open Terminal or Command Prompt: Navigate to your project directory or where you wish to install Playwright.
  2. Create a new Node.js project (if necessary): If you are starting a new project,

npm init -y

This command creates a new package.json file.

Install Playwright:

Run the following command to install Playwright and its browser binaries:


npm i playwright

This command installs Playwright along with Chromium, Firefox, and WebKit browsers.


npx playwright --version

This command displays the installed version of Playwright, indicating a successful installation.

Post-Installation Checks

const { chromium } = require('playwright');(async () => {
const browser = await chromium.launch({ headless: false })
const page = await browser.newPage();
 await page.goto('https://learnautomatedtesting.com');
 await page.screenshot({ path: `learnautomatedtesting.png` });
 await browser.close();

})();

Run the test using:


node test.js

This script opens the Playwright documentation page in a browser, takes a screenshot, and saves it as example.png

Check Browser Binaries: Verify that the browser binaries are installed correctly by checking the .cache directory in your Node.js project or the global cache location.