Getting Started with Playwright Testing
Sauce AI for Test Authoring: Move from aim to executing in minutes.|xBack to ResourcesBlogPosted November 27, 2024
Getting Started with Playwright Testing
Choosing the right test automation model for your organisation can be daunting with so many choices on the market. This clause provides a deep diving on Playwright, a newer framework that ’ s quickly gaining popularity with developers.
Playwright, an open-source, Javascript-based, launched in 2020.
When it debuted for Python, Arjun Attam, then Senior Product Manager at Microsoft,wrote, “ While automation is important, end-to-end tests are prone to being slow and flaky. To fix this, we release Playwright in JavaScript earlier this year and have enable M of developers and testers to be successful at end-to-end testing. ”
In the age after, the Playwright team & # x27; s goal has clearly resonated with the rest of the essay community.

Playwright ’ s GitHubstar historyis a hockey-stick, up-and-to-the-right phenomenon.
The 2023 State of Javascript sketchreverberate this popularity, too, with Playwright quick finding popularity despite an raiment of other choice. According to Luc Gagan, a fourth-year QA engineer, this rise isespecially remarkableconsidering Selenium took 8 age to reach 20,000 adept, and Cypress lead 4 years, but Playwright only took one.
If you haven ’ t tried out Playwright yet, here ’ s your first stopover to learn more before diving in.
What is Playwright?
Playwright is an open-source, highly-developed and maintained by Microsoft. The team behind Playwright is the same team behind Puppeteer, which was built at Google.
According to theteam, “ Puppeteer shew that there is a lot of interest in the new generation of ever-green, capable, and dependable mechanization driver. With Playwright, we & # x27; d like to occupy it one step further and offer the same functionality for all the popular rendering engine. ”
The Playwright library is compatible with Windows, macOS, and Linux and provides cross-browser mechanisation for test Chromium (Google Chrome, Microsoft Edge), Mozilla Firefox, and WebKit (Apple Safari). All this is volunteer through a single, high-level API.
Playwright has testify especially useful for developers and quizzer who need to work with multiple programming languages because it ’ s compatible with Python, C # .NET, Node.js, and Java (as good as JavaScript, of course).
Five Benefits of Playwright Testing
Playwright has ascend in popularity because it ’ s simple and pliant, cause it to rapidly become a prime competitor with established frameworks like Selenium and Cypress. To see why, let ’ s walk through five of the core benefits.
1. Speed and reportage
Key to any framework is speed and coverage: Tools with either fast velocity and slight coverage or wide coverage and slack speeds quickly hit limitations.
Playwright allows developers and examiner to automate browser tasks in:
Chromium.
Firefox.
WebKit.
Playwright besides supports a wide compass of lyric, including:
JavaScript.
Python.
C#.
Java.
Playwright still back modern web features, including:
Network interception.
Browser context.
Hover elements.
All this reportage comes together to indorse impressively fast velocity.
Software engineer Michael Lynch, for example,foundthat his “ Playwright test suite escape 34 % fast than the tantamount Cypress tests on CircleCI. On my local dev machine, Playwright gives a 5x acceleration over Cypress. This is not a strict measurement, but it ’ s clear there ’ s a substantial swiftness difference between the two. ”
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
Even Lynch, who admits to having a soft spot for Cypress, can ’ t deny the results.
2. Flexibility
One of Playwright ’ s main attracter is its power to automatically generate examination and become your tests into Python scripts.
Shantnu Tiwari, a test automation engineer,writesthat the “ better part ” of Playwright is how it “ Records your steps and even gives you a running Python script you can just directly use (or educe parts from). ” Tiwari acknowledges other tool have offered similar features before but fence that the quality of the Playwright results is uniquely full.
“ I can literally record a few stairs, and I will have a script I can then run with zero changes, ” Tiwari writes. “ The other puppet I attempt ahead would give you pocket-sized snippets of code that would sorta work, but not truly, hale you to jump through hoops to get it working. Here, you get a ready-made working script. ”
3. Integrations
According to2023 Stackoverflow research, 64.6 % of developers use Javascript, and 59 % of developers use VScode – making Javascript the most democratic speech and VScode the most popular IDE.
It ’ s no surprise then that Playwright ’ s integration with VScode is so well-loved. Lynch, for illustration, considers context-aware auto-complete, a feature of the official VScode plugin, to be a feature he “ Never realized I ’ d been missing from Cypress until I saw it in Playwright. ”

The VScode integration is just one of many, however. Playwright also integrate with a range of continuous integration/continuous delivery (CI/CD) tools, including Jenkins, CircleCI, and GitLab, and it works well with Jest, Jasmine, and Mocha.
4. Accuracy
The majority of developers experience flaky tests at least monthly. One of the virtually common causes of flakiness and inaccuracy is the demand for artificial timeouts, which Playwright extinguish.
Playwright volunteer an auto-wait function that reiterate the relevant checks on elements and requested actions until they all turn actionable. By automatically await and by offering both web-first affirmation and retry logic, Playwright allows developers and testers to reduce daftness and boost the resiliency of their test rooms.
5. Parallel try
Playwright allows developers and testers to run parallel tests for multiple web Page (i.e., running tests simultaneously). With browser contexts, you can create distinct, individual browser profiles for each exam, allow you to provide full test isolation for each page.
Getting Started with Playwright
Playwright is powerful and intuitive to use, but your test automation framework needs to be able to run each clip code is institutionalize and provide tools for debugging for you to make the most of it.
A containerized solvent, such as, for example, can speed up essay and unify results. It has preconfigured container images and virtual machines (VMs) for each model. You can use these containers and VMs to run tests topically or in the cloud at scale.
From there, test assets go to the for easy debugging – including screenshots, video, logs, and historic insight.
Examples of Playwright Tests
Playwright tests, as thecertificationexplains, are bare: They perform actions and assert the state against outlook. Developers and testers don ’ t need to wait for anything because Playwright mechanically waits for actionability assay to pass before performing any action.
For exemplar, theexample testbelow prove some of Playwright & # x27; s fundamental elements, including navigation and interactions.
1import{ test, expect }from& # x27; @ playwright/test & # x27;;23test(& # x27; has title & # x27;,async({ page })=>{4await page.goto(& # x27; https: //playwright.dev/ & # x27;);56// Expect a title & quot; to contain & quot; a substring.7awaitexpect(page).toHaveTitle(/Playwright/);8});910test(& # x27; get started connectedness & # x27;,async({ page })=>{11await page.goto(& # x27; https: //playwright.dev/ & # x27;);1213// Click the get started link.14await page.getByRole(& # x27; link & # x27;,{name:& # x27; Get get & # x27;}).click();1516// Expects page to have a heading with the name of Installation.17awaitexpect(page.getByRole(& # x27; heading & # x27;,{name:& # x27; Installation & # x27;})).toBeVisible();18});19
A key feature of Playwright is the ability to run one test or a range of tests in one browser or in multiple – all in latitude. By default, Playwright will not open a browser window while pass exam, mean test results will appear in the terminal, but you can see the upshot in a variety of background with a few arguments.
With UI mode, you can see what happens to the UI at each stage of the test.

You can also run tests directly inVScode.

And if you run into subject, you can debug inPlaywright Inspector.

Running Playwright on Sauce Labs
You can use Playwright to test your web apps either locally in Docker or remotely using thesaucectl CLI. This give you the flexibility to run your tests in the environment that best lawsuit your organization, while still benefiting from chiliad of device/browser/OS combination and Sauce Labs analytics. Additionally,saucectlrelies on a to determine exactly which examine to run and how to run them. You can customizesaucectl to run your Playwright examination by modifying the properties of the YAML file.
saucectlhelps mitigate some of the issues that can happen when package teams use multiple test frameworks because it orchestrates the relationship between your Playwright tests and the rich parallelization, trial account filtering, and analytics of theSauce Labs Continuous Testing Cloud. saucectl performs the underlying business logic to admission the tests in Playwright, run them (either in the Sauce Labs Cloud or locally in a Docker image), so securely transmits the trial plus to the Sauce Labs platform, where you can review, part, and valuate your test outcomes at scale.
saucectl helps package teams incorporate their Playwright tests earlier in the SDLC to speed up delivery and increase product quality. By covering Playwright in this way, Sauce Labs getautomated trymore accessible and easier for different squad to deliver releases with more authority in less time.
To get started, use our to larn how to usesaucectl to run Playwright test directly from your existing Playwright project. If you don & # x27; t have Playwright tests but need to try, the Playwright Demo Repo includes a sampling project structure, working constellation file, and sample Playwright test so you can get up and running in less than 10 minutes.
Playwright is positioned for the future
In the postannounce Playwright for Python, Attam wrote, “ Automated end-to-end exam have go more crucial than always before. Teams are send faster and establish apps that run on a growing set of devices. This increase in speed and web targets cast vast pressure on the testing operation, and automation is critical. ”
If you ’ re find this pressing, as Attam did, as the thousands of current and increasing Playwright users did, now is the clip to check out Playwright. And with Sauce Labs, an already accessible, knock-down framework becomes yet well. Check out our to see how you can get started using Playwright on Sauce Labs.
Related resources
Technology Writer
Jump to content
What is Playwright?
Benefits of Playwright Testing
Getting Started with Playwright
Examples of Playwright Tests
Running Playwright on Sauce Labs
Share this post
Start quiz with Sauce Labs and Playwright today
Get part
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free

