Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Hands-On Automated Testing with Playwright
  • Table Of Contents Toc
Hands-On Automated Testing with Playwright

Hands-On Automated Testing with Playwright

By : Faraz K. Kelhini, Butch Mayhew
5 (1)
close
close
Hands-On Automated Testing with Playwright

Hands-On Automated Testing with Playwright

5 (1)
By: Faraz K. Kelhini, Butch Mayhew

Overview of this book

Hands-On Automated Testing with Playwright draws from Faraz and Butch’s extensive experience to help you harness the full potential of Microsoft's Playwright framework. The book begins with a quick setup refresher, walking you through intermediate and advanced concepts such as dynamic content handling, accessibility testing, AI-generated test scripts, and parallel test execution. You'll explore real-world applications with end-to-end testing workflows for e-commerce and single-page applications. Alongside traditional topics such as accessibility, mobile, and visual regression testing, this book delves into modern trends such as CI/CD pipelines, DevOps integration, and AI-driven testing enhancements. Each chapter is packed with practical examples, expert techniques, and performance optimization tips, helping you gain a deep understanding of maintainable automation strategies. Whether you're transitioning from manual testing or expanding your automation toolbox, this Playwright book provides the skills and confidence to build future-proof testing systems in today's complex web development landscape. *Email sign-up and proof of purchase required
Table of Contents (22 chapters)
close
close
20
Other Books You May Enjoy
21
Index

Installing Playwright and dependencies

Before anything else, you must ensure your system is prepared to run Playwright. Playwright is built on top of Node.js, so verifying that Node and npm (or yarn) are available is the first step.

Installing Node.js

Most modern development systems already have Node installed, but if not, download it from nodejs.org. We recommend using the Long-Term Support (LTS) version. You can verify your installation with the following:

node -v
npm -v

These commands should return version numbers that confirm Node.js and npm are installed. If you’re managing multiple Node versions, consider using nvm or a similar version manager.

Initializing your project

Create a new project directory and initialize it as an npm project:

mkdir playwright-quick-setup
cd playwright-quick-setup
npm init -y

This command creates a package.json file, which is needed to manage your project’s dependencies.

Installing Playwright

As we discussed earlier in this chapter, there are two main ways to install Playwright: Playwright Library and Playwright Test.

To install the Playwright Library, you can use the following command:

npm install playwright

This installs the core Playwright library, which gives you the browser automation API. It’s suitable if you want to use Playwright’s automation capabilities programmatically or integrate it with other testing frameworks.

If you prefer an integrated testing solution, install the following:

npm install --save-dev @playwright/test

This installs the Playwright Test package, which includes a built-in test runner, assertions, and features like parallel execution.

Note that the preceding command only installs the @playwright/test package as a dev dependency in your existing project. It does not create configuration files or example tests or initialize any project structure. Also, it does not install browser binaries automatically (you need to run npx playwright install separately).

Use this approach when you’re adding Playwright Test to an existing project that already has a testing setup or if you prefer to configure Playwright manually. You will also need to set up the playwright.config.ts file and organize the test structure on your own.

If you want a guided setup with configuration and examples, or want to save time by letting Playwright scaffold the project for you, use the following:

npm init playwright@latest

This command initializes a new Playwright project with the Playwright Test framework. It sets up a complete testing environment, including the following:

  • Installing @playwright/test as a dev dependency
  • Creating a sample configuration file (playwright.config.ts)
  • Generating example test files (such as tests/example.spec.ts)
  • Optionally installing browser binaries (if you choose to do so during the setup prompts)

So, if you need to build tests using the bundled test runner, go with Playwright Test; otherwise, if you’re integrating into a different test framework, the core API is often enough. Now that your environment is set up, we can move on to building and running your first Playwright test.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Hands-On Automated Testing with Playwright
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon