Playwright is a relatively new tool for automation of e2e flows. It is one the few tools that supports a host of languages ( JS, TS, Java,C#, Python), and is very powerful in its features. Playwright is maintained by a team from Microsoft and hence there are very frequent updates and bug fixes.

In this series we will look into the questions that can be asked when appearing for a Playwright interview. This is the part 1 of a multi-series questionnaire on Playwright.

What is Playwright?

Ans : This is what the Playwright website mentions

Playwright enables reliable end-to-end testing for modern web apps.

Playwright can be best described as a new cross-browser, cross-language automation tool that helps in the complete end-to-end testing of a web application. Playwright also enables testing your code on the mobile emulation of Google Chrome on Android and Mobile Safari for iOS devices.

Can I use Playwright with Java or C#?

Ans: Yes , absolutely. Right now Playwright supports the following languages –

  1. Java
  2. C# .NET
  3. Python
  4. JavaScript
  5. TypeScript

This is mentioned in their landing page on the Playwright website.

How can I install Playwright with NodeJS.

Ans: There are two ways to install Playwright for NodeJS – one you can either using npm or yarn to download the vanilla JS (JavaScript) bindings or you can use either of the download managers to download the TS (TypeScript) bindings.

Using npm

For JS

npm i playwright

For TS

npm i -D @playwright/test

npx playwright install

Using yarn

For JS

yarn add playwright

For TS

yarn add playwright-test

The second way is to use a VSCode extension to install Playwright.

  1. Install this extension -> VSCode Extension for Playwright
  2. Now for Mac Users , go to Help -> Show All Commands -> Type “Install Playwright”

You can follow this step by step in the documentation here.

Which browsers are supported by Playwright?

When you’re downloading Playwright, it comes with it’s own bundle of browsers. As of now, Playwright has support for

  1. Chromium
  2. Google Chrome
  3. Firefox
  4. MS Edge
  5. Webkit

Besides, Playwright also gives the freedom for you to either accept the bundled version or download only specific browsers that you want. Read the documentation about browsers here.

Is there any Webdriver dependency in Playwright?

Ans: No. Playwright doesn’t has any dependency on any Webdriver bindings.

Can you explain the architecture of Playwright?

Playwright architecture is completely different from what Selenium architecture is. Both Seelnium and Playwright use to send all browser automation commands and recieve responses in JSON format.

Selenium uses separate HTTP requests for every command like launching the browser, opening the page, taking screenshots and so forth.

However, sending a new HTTP request for every command requires sending and receiving a lot of redundant information such as HTTP headers. Such approach tends to be slower than using one permanent communication channel for all commands which is alive while browser is running.
Playwright uses this approach and communicates with browser using one long-living web-socket connection. The web-socket connection gets established inside launch() method implementation which also automatically starts browser process for you.

This architecture has been explained in detail by Naveen here on his channel.

What is Chrome DevTools?

Ans: You can read about Chrome Devtools in detail here -> Link

What browsers comes baked with Playwright?

Ans: Playwright comes baked with Chromium, Firefox and WebKit browsers.

Can I use MSEdge with Playwright?

Ans: Yes, absolutely. Since MSEdge uses the core of Chromium open source project, you can use Playwright to automate scenarios in MSEdge too. This can be done via the channel key in the playwright.config.ts file

Check this link from Microsoft about configuring MSEdge.

Walk through the process of installing Playwright for JS.

Ans: Playwright can be installed either using npm or yarn for JS.

Using npm

For JS

npm i playwright

Using yarn

For JS

yarn add playwright

Can you give me a simple script to open a web page using Playwright?

Ans: Yes, below is a simple script to launch a webpage –

// example.js
const playwright = require('playwright');

(async () => {
const browser = await playwright.chromium.launch({
channel: 'chrome',
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://www.microsoft.com/edge');
await page.screenshot({ path: 'example.png' });

await browser.close();
})();

Does Playwright gives the ability to open in a current browser session? How?

Ans: Yes, this can be achieved using the browserType.connectOverCDP() method. You can read about a thorough conversation about this issue on Github

Can I use Jasmine as test runner for Playwright?

Ans: Yes, since Jest has almost same syntax as Jasmine, we can use Jasmine as test runner for Playwright.

Does Playwright support handling network level request intercepting and mocking?

Ans: Yes, Playwright has full capabilities regarding handling request intercepting and mocking. It can be used for making API requests as well.

I’ll add an example in future sections.

When a browser is rendered headless or headful, what are the differences?

Ans: There are no differences as per the Playwright team. So Playwright should work equally well in both conditions.

Can I use Playwright to run tests in parallel?

Ans: Running tests in parallel is the property of a test-runner. If you’re using a third party test runner like Jest/Mocha, then capabilities are provided at test-runner level for parallelism.

This brings to an end of the Part-1 of Playwright questions. Stay tuned for the next part.