This repository contains the example code for the Modern Cross Browser Testing in JavaScript using Playwright workshop led by Pandy Knight and hosted by Applitools.
Full instructions for the workshop are provided in WORKSHOP.md
.
Testing web apps in 2022 is hard. Not only are apps more complex than ever, but their pages must also be validated against an exploding number of combinations of browsers, devices, and versions – an industry average of 81,480 screens to 681,296 for the top 33%.
Testing tools are also changing. While browser automation tools like Selenium WebDriver and cross-browser testing architectures like Selenium Grid have been industry mainstays for years, new tools are emerging that offer faster, more reliable automation with richer features.
In this 1-hour workshop, “Automation Panda” Andy Knight will explain how to automate cross-browser tests in JavaScript using Playwright, a relatively new open-source, end-to-end test framework from Microsoft, and how to integrate them into CI/CD to provide feedback on quality across all browser/device combinations in seconds.
Highlights:
- The importance and evolution of cross-browser testing
- Critical requirements for a scalable cross-browser testing initiative and pros/cons of different approaches
- How to accelerate cross-browser and cross-device testing for integration into CI/CD using JavaScript with Playwright
- Traditional cross-browser testing
- Writing a typical login test
- Running the test locally
- Running the test against multiple browsers
- Scaling out cross-browser testing yourself
- Scaling out cross-browser testing as a service
- Modern cross-browser testing
- Reconsidering what should be tested
- Introducing Applitools Ultrafast Grid
- Rewriting login as a visual test
- Running visual tests across multiple browsers
- Integrating modern cross-browser testing with CI/CD
To complete this workshop, you will need:
- An Applitools account
- Register here for a free account
- Node.js
- This project was created with v16.13.1
- Visual Studio Code
- Add the Playwright Test for VS Code extension
This project is a small JavaScript test automation project containing Playwright test cases for an Applitools demo site. Each test case covers the same login behavior, but they do so in different ways:
traditional.spec.js
covers login using traditional assertions on a local machine.visual.spec.js
covers login using Visual AI with Applitools Eyes and Ultrafast Grid.
You'll need to run a few commands to run tests:
- To install project dependencies, run
npm install
. - To install browser projects, run
npx playwright install
. - To launch all tests, run
npx playwright test
.
Before running the visual test,
you must set the APPLITOOLS_API_KEY
OS environment variable to your Applitools API key
so that the test can connect to the Applitools cloud.
There are also two versions of the demo site under test:
- The original version of the site
- A changed version of the site with visual differences
To control which version to test, set the DEMO_SITE
environment variable to original
or changed
.
This project also provides a number of npm scripts to make launch commands simpler:
npm test
- runs all tests using all browser projectsnpm run traditional
- runs the traditional test using all browser projectsnpm run traditional:original
- runs the traditional test against the original site using all browser projectsnpm run traditional:changed
- runs the traditional test against the changed site using all browser projectsnpm run visual
- runs the visual test using Chromium locallynpm run visual:original
- runs the visual test against the original site using Chromium locallynpm run visual:changed
- runs the visual test against the changed site using Chromium locally
You can also append any Playwright command line options
to these npm
commands by adding them after --
.