What is Playwright? - Browser automatisation made easy
Tags: playwright, javascript, testing, puppeteer
Published: 2020-07-06 22:09:12

---
title: What is Playwright? - Browser automatisation made easy
published: true
description: Introduction and walkthrough into the Playwright framework: a Node.js library to automate Chromium, Firefox and WebKit with a single API.
tags: playwright, javascript, testing, puppeteer
canonical_url: https://playwright.tech/blog/what-is-playwright
---

Over the past 3 years where the [Puppeteer](https://github.com/puppeteer/puppeteer) ecosystem has evolved and developers around the globe have adopted the framework to automate their browsers, the framework has gained a lot of popularity. Puppeteer itself has now over 60k stars on GitHub and is by that one of the [most starred projects](http://gitmostwanted.com/top/stars/solid/2) on the platform. Due the big audience and the people who integrated it into their projects to use it e.g. to perform end-to-end tests or create automated screenshots, Puppeteer reached his limitations. The community asked for better browser support, for this specific request they delivered [puppeteer-firefox](https://github.com/puppeteer/puppeteer#q-what-is-the-status-of-cross-browser-support) which was announced at the [Google I/O 2019](https://youtu.be/MbnATLCuKI4). But also smaller core concept changes would ease up the usage like less flakiness by waiting automatically if an element appears on the page or isolating the session on a context instead of the whole browser to provide better reusability.

For all of that the core team which is now primarily working at Microsoft has worked over the past few months and released on January 2020 the first version of Playwright. It has features like:

- Scenarios that span multiple page, domains and iframes
- Auto-wait for elements to be ready before executing actions (like click, fill)
- Intercept network activity for stubbing and mocking network requests
- Emulate mobile devices, geolocation, permissions
- Support for web components via shadow-piercing selectors
- Native input events for mouse and keyboard
- Upload and download files

Until now (June 2020) the project already got 13k stars on GitHub and big projects like Visual Studio Code, CodeceptJS or xterm.js have adopted it.

<a href="https://star-history.t9t.io/#microsoft/playwright" target="_blank">
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/nepj2cx52ureuldmg7pm.png" alt="Star history Playwright Q1 2020"/>
</a>



The usage of Playwright is extremely straightforward. Most of the calls are async based, that means you have to wrap them either in a Promise or you have to use async/await which is the more common way.

```js
const playwright = require("playwright");

(async () => {
  for (const browserType of ['chromium', 'webkit', 'firefox']) {
    const browser = await playwright[browserType].launch();
    const page = await context.newPage();
    await page.goto('http://whatsmyuseragent.org/');
    await page.screenshot({ path: `example-${browserType}.png` });
    await browser.close();
  }
})();
```


After importing the library we're gonna loop over the different browsers and launch them as headless browsers. Launching means in Playwright wording, that a real browser instance will be opened as a headless instance per default. Once we have our browser we are creating an actual page object out of it. With the page you can interact by clicking on buttons, making screenshots, getting text out of your DOM Nodes, or navigating to other URLs for example. In this case we are visiting a website and then making a screenshot which we store on the disk including the browser's name. Once we are done we'll close the whole browser.

If you want to find out more about Playwright, you can check out the examples with [Try Playwright](https://try.playwright.tech) to get an interactive experience of how the different browser engines behave.

Due to all of that it can be advised for further usage to use Playwright instead of [Puppeteer](https://pptr.dev). The API is in most cases the same or only slightly different. [Here](https://medium.com/@davert/puppeteer-to-playwright-migration-guide-6c86ea66e85e) you can find a migration guide with the differences. And an official link to their documentation including the JavaScript API you can find under [playwright.dev](https://playwright.dev).


{% github microsoft/playwright %}