<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: GaryParker12</title>
    <description>The latest articles on Forem by GaryParker12 (@garyparker12).</description>
    <link>https://forem.com/garyparker12</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F984474%2F3b43ffc3-ec64-4114-8eff-3f1580d6a6ec.jpeg</url>
      <title>Forem: GaryParker12</title>
      <link>https://forem.com/garyparker12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/garyparker12"/>
    <language>en</language>
    <item>
      <title>Playwright Tutorial: Getting Started With Playwright Framework</title>
      <dc:creator>GaryParker12</dc:creator>
      <pubDate>Tue, 06 Dec 2022 13:12:17 +0000</pubDate>
      <link>https://forem.com/testmuai/playwright-tutorial-getting-started-with-playwright-framework-4d1l</link>
      <guid>https://forem.com/testmuai/playwright-tutorial-getting-started-with-playwright-framework-4d1l</guid>
      <description>&lt;p&gt;Playwright is a framework that I’ve always heard great things about but never had a chance to pick up until earlier this year. And since then, it’s become one of my favorite &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation frameworks&lt;/a&gt; to use when building a new automation project. It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks I’ve worked with.&lt;/p&gt;

&lt;p&gt;I’m going to get you through this Playwright tutorial, which will enable you to write end-to-end tests for your future projects. We will also dig into the extensive features it offers, how we can prepare tests for execution on the LambdaTest cloud grid, and an overview of other popular integrations.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright testing&lt;/a&gt; tutorial, I’ll be stepping through each part of the process so you can follow along, from the initial installation of the Playwright framework until the full execution of a test suite.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an online Selenium Grid to run your browser &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt; scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Playwright framework?
&lt;/h2&gt;

&lt;p&gt;Built by the Microsoft team, Playwright is a framework for &lt;a href="https://www.lambdatest.com/blog/guide-to-end-to-end-testing-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;end-to-end testing&lt;/a&gt; and automation, which has slowly been building up popularity. You will see it at the top of most people’s favorite frameworks to work with.&lt;/p&gt;

&lt;p&gt;The 2020 State of JavaScript survey among developers reveals that while Cypress adoption is on the upswing, Playwrights adoption remains very much in the early stages of development. However, the current trend of Playwright on GitHub shows the growing popularity of the Playwright framework (&lt;strong&gt;39.3k Star, 1.8k Fork, and 12.2k Active Users&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2722%2F0%2AvofotBf40nrsnMBB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2722%2F0%2AvofotBf40nrsnMBB.png" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not only is it versatile and easy to work with, but it has lightning-fast execution speeds and some great features that are unique to the Playwright framework, such as &lt;strong&gt;Trace Viewer&lt;/strong&gt; and &lt;strong&gt;Test Generator&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trace Viewer&lt;/strong&gt; is a GUI tool that can be used to review Playwright traces after tests have been executed. If you want to experiment with it, you can set ‘trace’ to ‘on’ in your playwright.config.js:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the test executions have been completed, there will be trace.zip files generated in your test-results folder:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AXeuyNHDcvGtLG0Dv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AXeuyNHDcvGtLG0Dv.png" width="679" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a few different ways these reports can be viewed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In your web browser through &lt;a href="https://trace.playwright.dev/" rel="noopener noreferrer"&gt;https://trace.playwright.dev/&lt;/a&gt;, where you can drag and drop the trace files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By executing the following command in your CLI:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npx playwright show-trace trace.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After following either of these processes, you will be presented with the Playwright Trace Viewer. Here you can dig deeper into the actions performed, how long they took to execute, parameters passed, network calls made, and any logs generated during execution.&lt;/p&gt;

&lt;p&gt;You can also hover over the trace film strip at the top of the page to see a magnified image of each stage in the execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2526%2F0%2AS1kjELxV-g1ToDE4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2526%2F0%2AS1kjELxV-g1ToDE4.png" width="800" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test Generator&lt;/strong&gt; is a browser tool that Playwright provides, which records the actions performed in the browser and generates the equivalent code. This is useful if you want to quickly draft some tests or upskill members of your team who are not so familiar with writing code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s run through a quick example. We are going to execute the below command, which launches Playwright codegen with the &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest’s Selenium Playground&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npx playwright codegen lambdatest.com/selenium-playground
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When this is executed, two windows will launch. The first is your website which we can interact with, performing clicks, navigating, and entering data. The second is the Playwright Inspector, where our code will be generated dynamically.&lt;/p&gt;

&lt;p&gt;On the first launch, you’ll see that the basic goto method for navigating the website has been generated.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;page.goto("https://www.lambdatest.com/selenium-playground/")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A-gUtr82h4bmt3WHv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A-gUtr82h4bmt3WHv.png" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we interact with the page by selecting some of the checkboxes from the checkbox-demo example, you’ll see code gets generated dynamically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2At6BReZuiLHG8_uWX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2At6BReZuiLHG8_uWX.png" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One last thing worth mentioning is the ‘Target’ dropdown in the upper right of the Playwright Inspector. You can select from a list of different languages and export the code in whichever you require:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ag3GUJSX1hRRrkiOx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ag3GUJSX1hRRrkiOx.png" width="750" height="671"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Watch this Playwright tutorial covers everything you need to get you up and running with the Microsoft Playwright framework with TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wawbt1cATsk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automate Cypress tests and perform browser automation &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress testing&lt;/a&gt; with LambdaTest. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use the Playwright framework?
&lt;/h2&gt;

&lt;p&gt;It’s an open-source framework relatively new to the market but is building up popularity fast. Microsoft maintains it and, as a result, receives regular updates and improvements. If we look at the number of downloads for similar frameworks which have been on the market for a while, you can see Playwright has burst onto the scene.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2640%2F0%2ALkZMfnQpAmBqc5vB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2640%2F0%2ALkZMfnQpAmBqc5vB.png" width="800" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Releases
&lt;/h2&gt;

&lt;p&gt;The Playwright team also provides their release notes in the form of video walkthroughs in addition to their standard release notes. This is something I haven’t seen from any of the other major frameworks and is a nice touch for gaining insight from the team building the product.&lt;/p&gt;

&lt;p&gt;Here is a small snapshot from their most recent release, where they discuss their new implementation for Component testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2214%2F0%2ASezFsZSfmQ5evkb-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2214%2F0%2ASezFsZSfmQ5evkb-.png" width="800" height="646"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Competitors
&lt;/h2&gt;

&lt;p&gt;You may be trying to decide to migrate away from a well-established framework such as &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; or on to &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress test automation framework&lt;/a&gt;, which is also gaining popularity in the community.&lt;/p&gt;

&lt;p&gt;My main reason for picking Playwright over others is how intuitive it is and the flexibility with which it can interact with the browser across multiple pages and domains. And lastly, execution speed. Speed is everything. If you can’t run your tests quickly and &lt;a href="https://www.lambdatest.com/blog/speed-up-testing-cycle/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;speed up your test cycle&lt;/a&gt;, you can’t deliver your product quickly. If you can’t deliver your product quickly, you’ll have a lot of unhappy stakeholders and customers.&lt;/p&gt;

&lt;p&gt;This is a benchmark report that the ChecklyHQ team produced after performing in-depth execution speed monitoring on the major automation tools. As you can see, it pretty much speaks for itself. Playwright tops 2 out of 3 of the scenarios, closely followed by Puppeteer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ao8q6xuHASqYCrpcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ao8q6xuHASqYCrpcg.png" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Execute &amp;amp; analyze Cypress test scripts online. Deploy quality builds faster with 40+ browser versions on &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress Cloud&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrations
&lt;/h2&gt;

&lt;p&gt;This is personally one of the most important factors for me when selecting a new tool or framework. Does it integrate well with our current architecture? The worst feeling is implementing something, only to realize later that it doesn’t have native integration, and we have to start building custom webhooks or plugins.&lt;/p&gt;

&lt;p&gt;Thankfully the Playwright team has this covered. There are Docker images, so you can quickly execute tests in an isolated and controlled environment. And native CI tool integrations for the popular and &lt;a href="https://www.lambdatest.com/blog/best-ci-cd-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;top CI/CD tools&lt;/a&gt;, including GitHub Actions, Azure Pipelines, CircleCI, Jenkins, and GitLab.&lt;/p&gt;

&lt;p&gt;They also provide support for your existing JavaScript test runners, such as Jest/Jasmine, AVA, and Mocha, which is useful if you are porting from an existing code base.&lt;/p&gt;

&lt;p&gt;Lastly, there is direct integration with &lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt;. This is vital if you plan on running larger suites of tests at scale and require a grid environment to manage parallel execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key features of the Playwright framework
&lt;/h2&gt;

&lt;p&gt;Here are a few of the key features of Playwright and why you should check it out!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Support for cross-browser platforms built on Chromium, WebKit, and Firefox — which includes Chrome, Edge, Firefox, Opera, and Safari.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support for cross-platform execution on Windows, Linux, and macOS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support for cross-language, including JavaScript, TypeScript, Python, Java, and .NET — write tests in the environment that suits you while still covering all areas and formats.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auto-wait built-in, smart assertions that retry until the element is found, and test data tracing — keep track of logs, videos and screenshots easily.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built with modern architecture and no restrictions — interact with multi-page, multi-tab websites like a real user, and tackle frames and browser events with ease.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecture: Playwright framework
&lt;/h2&gt;

&lt;p&gt;We’ve covered some of the reasons why Playwright is great to work with on a feature and implementation level, but what is going on internally? What makes the test execution more stable and faster to execute?&lt;/p&gt;

&lt;p&gt;So a good way to understand this is to compare it with Selenium — Selenium sends each command as a separate HTTP request and receives JSON responses. So every interaction, such as opening the browser, clicking an element, or &lt;a href="https://www.lambdatest.com/blog/how-to-use-selenium-sendkeys/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;sending keys in Selenium&lt;/a&gt;, is sent as a separate HTTP request.&lt;/p&gt;

&lt;p&gt;As you can imagine, this results in slower execution as we wait for responses and introduces a layer of potential flakiness.&lt;/p&gt;

&lt;p&gt;Playwright, on the other hand, communicates all requests through a single WebSocket connection, which stays in place until test execution is completed. This reduces the points of failure and allows commands to be sent quickly on a single connection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ASw_Xi-X8vPBCK8A6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ASw_Xi-X8vPBCK8A6.png" width="565" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This Cypress automation testing tutorial will help you learn the benefits of &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cypress test automation&lt;/a&gt;, and how to install Cypress and execute Cypress automation testing over scores of browsers and operating systems online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started with the Playwright Tutorial
&lt;/h2&gt;

&lt;p&gt;Let’s cover some of the basic prerequisites that are needed before we get deeper into installation and setup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ensure you have NodeJS installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install a code editor. We will be using Visual Studio Code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating your first Playwright project
&lt;/h2&gt;

&lt;p&gt;I’m going to cover a full introduction in this Playwright tutorial, starting with the initial commands all the way up to having a fully functioning automation project. There are a few different ways we can install Playwright.&lt;/p&gt;

&lt;p&gt;Watch this video to learn how to run multiple projects in Playwright and execute them on the LambdaTest platform.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mb-bkyGK9Ss"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Playwright using the VS Code extension
&lt;/h3&gt;

&lt;p&gt;Follow the below steps to install Playwright using the VS Code extension:&lt;/p&gt;

&lt;p&gt;1- Install VS Studio from the Visual Studio Marketplace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AYObfFthqHYlZKHQnmdv0GQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AYObfFthqHYlZKHQnmdv0GQ.png" width="384" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Once this is installed, open the ‘Command palette’ under the ‘View’ tab, and type ‘install Playwright.’ Ensure you have created a folder for your project, which is currently open in VS Code, as this is where the new Playwright files will be generated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AwDA6JMXnaMn19zKwWgTZZA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AwDA6JMXnaMn19zKwWgTZZA.png" width="360" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- After selecting this, you’ll be presented with the following dropdown options, where you can choose which browsers to install. You can also add GitHub Actions, which will generate a YAML build file for you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AoyGi0DmvC2RYgnOozZnBdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AoyGi0DmvC2RYgnOozZnBdw.png" width="596" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- When this is successfully installed, you should see the following message in the command line, which presents you with a few commands you can execute to get started:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ATXRS5OLeYkISJ3ZWeOUMLg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ATXRS5OLeYkISJ3ZWeOUMLg.png" width="493" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you’ll have the project created that looks something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVEtlqX_tt0u7F82iH8VmVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVEtlqX_tt0u7F82iH8VmVg.png" width="216" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Watch this video to learn more about setting up the &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright test&lt;/a&gt; automation framework:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/06HIhFcpBDo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn the advantages of Cypress automation, how to install Cypress, and how to carry out online &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cypress automation&lt;/a&gt; testing across a wide range of browsers and operating systems with the aid of this lesson on Cypress automation testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing the Playwright NPM package from the command line
&lt;/h3&gt;

&lt;p&gt;This is fairly simple, and I’ll run through it step-by-step to explain what we are executing and what it is doing.&lt;/p&gt;

&lt;p&gt;1- Run this command to install Playwright.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm init playwright@latest new-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ‘new-project’ parameter is the folder that will be created, containing all your project files. This can be anything, so feel free to use a name that suits your project type.&lt;/p&gt;

&lt;p&gt;2- Once this is executed, you will be presented with multiple prompts which outline how you would like to configure the project. These can be selected with the arrow keys or keyboard selections. Once you have selected all options, the project will be initialized.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ARcD7ymQZFVNAQKvNughBUA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ARcD7ymQZFVNAQKvNughBUA.png" width="456" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- After following these steps, you’ll have a similar project structure as the VS Code extension workflow. The only difference is that the command line installation offers slightly more customization in choosing between JavaScript and TypeScript, and test folder location.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A0QbaU43ZatrGees2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A0QbaU43ZatrGees2.png" width="214" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some of the files and folder names may vary based on your selections during initialization, but here is a quick run-through of what we have.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;workflows/playwright.yml&lt;/strong&gt;: This is the GitHub Actions workflow yaml file. It is what will build and execute your tests from the GitHub platform.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    name: Playwright Tests
    on:
      push:
        branches: [ main, master ]
      pull_request:
        branches: [ main, master ]
    jobs:
      test:
        timeout-minutes: 60
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-node@v2
          with:
            node-version: '14.x'
        - name: Install dependencies
          run: npm ci
        - name: Install Playwright Browsers
          run: npx playwright install --with-deps
        - name: Run Playwright tests
          run: npx playwright test
        - uses: actions/upload-artifact@v2
          if: always()
          with:
            name: playwright-report
            path: playwright-report/
            retention-days: 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, for a quick run-through of what it’s actually doing — In simple terms, ‘&lt;strong&gt;on&lt;/strong&gt;’ any code push or merged pull request to the main/master branch, a build will be triggered. This build will run on a ubuntu-latest agent, it will checkout your code, install node and your npm dependencies. Then it will install Playwright framework, begin test execution, and upload a test execution report at the end.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;node_modules&lt;/strong&gt;: If you’ve worked with JavaScript before you’re probably very familiar with these, they are additional libraries which we can install in the project. In our case, you can see Playwright modules, which allow us to access additional functions from the Playwright library.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVEqBuGq1fg9hG62hHyrR-w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVEqBuGq1fg9hG62hHyrR-w.png" width="155" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tests/example.spec.js&lt;/strong&gt;: This is the example spec file that is generated when initializing Playwright. There are 75 tests in total covering various different scenarios. This is ideal for understanding the syntax and general approach to writing tests.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // @ts-check
    const { test, expect } = require('@playwright/test');

    test.beforeEach(async ({ page }) =&amp;gt; {
      await page.goto('https://demo.playwright.dev/todomvc');
    });

    const TODO_ITEMS = [
      'buy some cheese',
      'feed the cat',
      'book a doctors appointment'
    ];


    test.describe('New Todo', () =&amp;gt; {
      test('should allow me to add todo items', async ({ page }) =&amp;gt; {
        // Create 1st todo.
        await page.locator('.new-todo').fill(TODO_ITEMS[0]);
        await page.locator('.new-todo').press('Enter');

        // Make sure the list only has one todo item.
        await expect(page.locator('.view label')).toHaveText([
          TODO_ITEMS[0]
        ]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;.gitignore:&lt;/strong&gt; This is a common Git file, which will exclude folders that we do not want to commit to our remote repository. They will be generated dynamically during the build and test execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AZqGUwvjeSdcuH4k10VeApg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AZqGUwvjeSdcuH4k10VeApg.png" width="444" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;package-lock.json/package.json:&lt;/strong&gt; The package.json file is generated during the initialization of the project and contains information regarding your project, entry points for test execution, custom scripts, and package dependencies. The package-lock.json plays a slightly different role. It tracks the exact version of every package installed. For more detailed information on why these files are important, refer to the official NPM package.json and package-lock.json docs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Playwright.config.js:&lt;/strong&gt; This file contains all the configuration required for your Playwright project. You can configure timeouts, parallelism, retries, reporters, and browsers, just as a brief example! It is open to tons of customization and adjustment to meet your test suite’s requirements. You can find the full configuration docs here: &lt;a href="https://playwright.dev/docs/test-configuration" rel="noopener noreferrer"&gt;https://playwright.dev/docs/test-configuration&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/06HIhFcpBDo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest playwright tutorial also discover tutorials around topics like &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;mobile app testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running your first Playwright test
&lt;/h2&gt;

&lt;p&gt;Let’s run some tests to make sure everything is working. Execute the following in the terminal:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx playwright test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will run headless, so you should see activity in the terminal as tests are executed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AOTGBCso4FOPbJB5R.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AOTGBCso4FOPbJB5R.png" width="663" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have 75 passing tests, executed in 42 seconds. Good stuff!&lt;/p&gt;

&lt;p&gt;If you want to look into the tests which were just run, you can open the example.spec.js. The test cases are marked by the syntax ‘test.describe’, and at the top of the file, you can see required packages, steps executed before each test, and some list data used within the tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AVp1kF6pQqBVB5B8H.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AVp1kF6pQqBVB5B8H.png" width="800" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Workers
&lt;/h3&gt;

&lt;p&gt;There are a few things also to note — we have 8 workers being used. This means 8 different processes running in parallel to execute our tests. Refer to the Playwright’s official docs for more detailed information on parallelism and sharding.&lt;/p&gt;

&lt;p&gt;By default, the number of workers being used will always be 8 (undefined), and when running in a CI environment, it will be 1. You can change these values in your playwright.config.js to run more or fewer tests in parallel, depending on your hardware capabilities. This is worth experimenting with in small increments to get a feel of what best suits your needs while maintaining a fast test execution time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AB-P792uM5Lm85qUm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AB-P792uM5Lm85qUm.png" width="604" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reports
&lt;/h3&gt;

&lt;p&gt;Another thing you may have noticed after your test execution is this snippet:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//To open last HTML report run:

  npx playwright show-report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you execute that command, a browser window will launch on localhost, which looks something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A4EwH1SNKGkL1Bu-c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A4EwH1SNKGkL1Bu-c.png" width="800" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It gives you a nice report of your most recent test execution, with information regarding test outcomes, test cases, browsers executed on and test execution times.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AMgzm7pkweNV66P5r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AMgzm7pkweNV66P5r.png" width="800" height="820"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a basic Playwright test
&lt;/h3&gt;

&lt;p&gt;Now that we’ve executed some basic tests let’s try adding some of our own! Add a file to your tests folder called ‘form.spec.js’&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AnClhvxD6owj_u38U.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AnClhvxD6owj_u38U.png" width="219" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to add a line to the start of the file to access the Playwright module and test functions. From there, we define our test case ‘input form data’.&lt;/p&gt;

&lt;p&gt;We are creating an instance of ‘page’ to access the most common Playwright methods. The first one we will be using is ‘goto’, which will navigate us to the defining url.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { test } = require('@playwright/test');

test('input form data', async ({ page }) =&amp;gt; {
  await page.goto('https://www.lambdatest.com/selenium-playground/input-form-demo');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the terminal, navigate to the tests folder and execute the below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx playwright test form.spec.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The output should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AJGUK-FjMAughFhDw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AJGUK-FjMAughFhDw.png" width="325" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we know that our new test can execute successfully, let’s add a bit more complexity and an assertion, to ensure our test will catch actual issues.&lt;/p&gt;

&lt;p&gt;This is what the page looks like on &lt;a href="https://www.lambdatest.com/selenium-playground/input-form-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest’s Selenium Playground&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AF8ZTtbhjKxK6N1E-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AF8ZTtbhjKxK6N1E-.png" width="744" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to enter data into all of the fields. The code will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      await page.locator('[placeholder="Name"]').fill('Mr Test');
      await page.locator('[placeholder="Email"]').fill('randomemail@test.com');
      await page.locator('[placeholder="Password"]').fill('Abc123');
      await page.locator('[placeholder="Company"]').fill('Fake company');
      await page.locator('[placeholder="Website"]').fill('Fake website');
      await page.locator('select[name="country"]').selectOption('GB');
      await page.locator('[placeholder="City"]').fill('London');
      await page.locator('[placeholder="Address 1"]').fill('123 New road');
      await page.locator('[placeholder="Address 2"]').fill('New street');
      await page.locator('[placeholder="State"]').fill('New state');
      await page.locator('[placeholder="Zip code"]').fill('abc123');
      await page.locator('button:has-text("Submit")').click();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we are using the page.locator method, followed by the element locator, and we are using this to fill the empty fields and click the submit button.&lt;/p&gt;

&lt;p&gt;If we execute this test as it is, it will still pass. We need an assertion of some kind to verify the success criteria of the test, which will fail if it is not met.&lt;/p&gt;

&lt;p&gt;Following submission of the form, the following page is displayed with a confirmation message:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Abf_3C7yytUKnMD54.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Abf_3C7yytUKnMD54.png" width="763" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will assert that the confirmation message element is visible to the user, with the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const locator = page.locator('text=Thanks for contacting us, we will get back to you shortly.');
  await expect(locator).toBeVisible();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can execute this test, and we will once again see it passes successfully. Let’s change the assertion to something different and make sure it’s a valid test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const locator = page.locator('text=Welcome back');
      await expect(locator).toBeVisible();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see after running this test again, it is now failing at line 20, where the expected locator is not displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ADFeoyPWgMHj3syQm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ADFeoyPWgMHj3syQm.png" width="737" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This terminal logging is very helpful for quickly finding out where and why the test is failing. Let’s revert the change and run the full test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AnS6qoX899zFOe5wG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AnS6qoX899zFOe5wG.png" width="343" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nice! Full form submission and an assertion in 4 seconds.&lt;/p&gt;

&lt;p&gt;Let’s run the same test across 3 different browsers and take a look at the report. Add –browser=all to the end of your command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npx playwright test form.spec.js --browser=all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AGys4-hAeePoo0sIw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AGys4-hAeePoo0sIw.png" width="430" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if we use the command we learned earlier, we can view the html report:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npx playwright show-report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2010%2F0%2AZ5aQ8luKj9k0mNz7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2010%2F0%2AZ5aQ8luKj9k0mNz7.png" width="800" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article of the Playwright tutorial series, we have seen how to set up the Playwright framework for the end-to-end test automation. So far, we have learned how to execute a simple test using the Playwright test automation framework.&lt;/p&gt;

&lt;p&gt;Though Playwright comes with a lot of features to leverage, its true potential can be evaluated only over a cloud-based grid. In the upcoming blogs of this Playwright tutorial series, we will learn to run Playwright tests on a cloud grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/benefits-of-cloud-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cloud testing&lt;/a&gt; platforms like LambdaTest allow you to perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 50+ browsers and browser versions of Chrome, Chromium, Microsoft Edge, Mozilla Firefox, and even Webkit. You can even run your Playwright test scripts in parallel and cut down your test execution time by multiple folds.&lt;/p&gt;

&lt;p&gt;Watch this video to learn more about handle user inputs, buttons, checkboxes, and other UI elements in Playwright with the help of live examples:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/GJtI_KWzPIo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Are you using Playwright for automation testing? Run your &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;playwright test&lt;/a&gt; scripts instantly on 50+ browser/OS combinations using the LambdaTest cloud. Sign up for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  VS Code extensions for Playwright
&lt;/h2&gt;

&lt;p&gt;Now, before we wrap up, I’d like to run through some of the awesome functionality you get from installing the Playwright test extension in VS Code. As a reminder, you can find that here, after opening the extensions tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ayp_hEof19afjUzhq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Ayp_hEof19afjUzhq.png" width="422" height="110"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you’ll notice we have a Testing icon on the lower left of the screenshot below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AVAcii0Va_lXNy-B1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AVAcii0Va_lXNy-B1.png" width="461" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, we can see all the tests in the project. Not only that, but it also opens up some very nicely integrated functionality for us to use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test Execution&lt;/strong&gt;
We can execute tests by selecting the ‘Run test’ icon, and as the test progresses, the line of code being executed is highlighted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2186%2F0%2Aaz2aSwlMKIY3Puke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2186%2F0%2Aaz2aSwlMKIY3Puke.png" width="800" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to that, you will also notice at the end of each line is the execution time in milliseconds. I personally love this kind of data, as it allows you to tweak and optimize your code based on the information you can easily access.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Debug Tests&lt;/strong&gt;
If we set a breakpoint in our test by selecting to the left of the line numbers and run the test in debug mode, the test execution will stop at this point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AQ5hvYUrk7oJ9OxlFVbU3tg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AQ5hvYUrk7oJ9OxlFVbU3tg.png" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, I’ve set a breakpoint at the company field, so we can pause here and see exactly what the test is doing.&lt;/p&gt;

&lt;p&gt;On a side note, to make your life of testing easy and fuss-free while debugging, you can try the &lt;a href="https://www.lambdatest.com/lt-debug?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LT Debug Chrome extension&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Real-Time Code Editing&lt;/strong&gt;
Now, here is an additional feature I find amazing, mostly due to how it’s embedded in the test execution. We can edit the element in the code in real-time, and it will update in the browser window. For example, I’ve changed the locator from ‘Company’ to ‘Password,’ and we can see it’s moved the highlighted locator:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2382%2F1%2AS4EBDghr3t8Jvph1R2v60A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2382%2F1%2AS4EBDghr3t8Jvph1R2v60A.png" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Record&lt;/strong&gt;
Lastly is the ‘Record’ option. This behaves similar to ‘codegen,’ which we experimented with earlier in this blog. When you select ‘Record,’ a window will be launched, and a spec file will be generated:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ABvBNQ1JE0ML1bdabfRUBEw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ABvBNQ1JE0ML1bdabfRUBEw.png" width="800" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we start to navigate and interact with the page, code will be generated in real-time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AHzgAPxgcQo3o8vzEb7VZ9A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AHzgAPxgcQo3o8vzEb7VZ9A.png" width="800" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As mentioned previously, this is great for quickly structuring a test or training more junior members of your team, they can piece together how interactions with the page align with the written code.&lt;/p&gt;

&lt;p&gt;Watch this video to learn about some exciting features offered by Playwright, like recording tests, taking screenshots of tests, auto-wait mechanism, and much more.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/1INdYpaXqLE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Playwright is an incredibly versatile framework with features that are just plain enjoyable to use, which is something special when put side-by-side with other frameworks in the industry, which can sometimes be more of a chore.&lt;/p&gt;

&lt;p&gt;It makes writing automation tests very simple, and you’ll be building up large suites of tests in a fraction of the time you would with others. Also, the entry bar is kept low, so it won’t be intimidating if you introduce it to a new team.&lt;/p&gt;

&lt;p&gt;I hope you gained some insight from this Playwright tutorial, and may it be top of your favorite automation frameworks to use in the future.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How To Run Your First Playwright Test On Cloud</title>
      <dc:creator>GaryParker12</dc:creator>
      <pubDate>Mon, 05 Dec 2022 13:42:17 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-run-your-first-playwright-test-on-cloud-4kd6</link>
      <guid>https://forem.com/testmuai/how-to-run-your-first-playwright-test-on-cloud-4kd6</guid>
      <description>&lt;p&gt;One of the biggest problems I’ve faced when building a &lt;a href="https://www.lambdatest.com/learning-hub/test-suite?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test suite&lt;/a&gt; is not the writing of the tests but the execution. How can I execute 100s or 1000s of tests in parallel?If I try that on my local machine, it would probably catch fire — so we need a remote environment to send these to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; has been the gold standard solution for a long time, it allows you to distribute tests across multiple machines, and at present, it is fairly easy to manage. The second problem I’ve faced is where do we get these machines? Do we use the hardware we own, or do we purchase VMs from a cloud provider — both require quite a bit of maintenance and configuration.&lt;/p&gt;

&lt;p&gt;The solution a lot of organizations end up moving towards is some form of &lt;a href="https://www.lambdatest.com/automate-cloud-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cloud Grid&lt;/a&gt; facilitating &lt;a href="https://www.lambdatest.com/blog/benefits-of-cloud-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud testing&lt;/a&gt;. It’s an environment where you can send your tests and not worry about what is happening in the background. Your tests are distributed in parallel, they execute the necessary commands, and you’re given test results. It’s much more accessible for the user and requires little to no maintenance.&lt;/p&gt;

&lt;p&gt;We will run a test suite locally on a basic Selenium Grid configuration to understand how it works and its limitations. We will then execute tests remotely on a Cloud Grid, with a higher level of parallelism — not only in test cases but also browser and operating system types.&lt;/p&gt;

&lt;p&gt;On a global scale, users interact with a wider range of devices and platforms daily, and this ability to run automated tests at scale becomes increasingly important.&lt;/p&gt;

&lt;p&gt;This &lt;a href="https://www.lambdatest.com/playwright?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright tutorial&lt;/a&gt; will look at writing and running your first Playwright test on a cloud grid like LambdaTest.&lt;/p&gt;

&lt;p&gt;Before we begin, I’m going to give an overview of what we are aiming to achieve in this tutorial on &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright testing&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Build a simple test suite&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Execute tests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On your local machine&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On Selenium Grid&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On a Cloud Grid environment&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this article, we look at &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is regression testing&lt;/a&gt;, its importance and types, and how to perform it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Playwright test suite
&lt;/h2&gt;

&lt;p&gt;We will be using the Playwright framework to build our tests. Playwright is a relatively new framework but is growing in popularity as its powerful features continue to prove valuable for application developers. Microsoft contributes many of these features as Playwright gets regular updates and improvements. Playwright has overtaken many similar &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing frameworks&lt;/a&gt; in terms of downloads due to its powerful features and overall appeal to users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fig13l86rgu3acavdj6ab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fig13l86rgu3acavdj6ab.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we get deeper into installation and setup, here are some basic prerequisites.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ensure you have NodeJS installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install a code editor. I will be using Visual Studio Code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need to get up to speed with installation and setup, follow my earlier blog on getting started with the &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright framework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For this tutorial on running your first Playwright test, we will be writing tests for the &lt;a href="https://ecommerce-playground.lambdatest.io/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest eCommerce Playground&lt;/a&gt; with dummy data and content — perfect for experimenting with test automation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test approach for writing your first Playwright test
&lt;/h3&gt;

&lt;p&gt;Before we jump into writing the tests for &lt;a href="https://www.lambdatest.com/blog/playwright-end-to-end-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright end to end testing&lt;/a&gt;, I’ll give a brief overview of the approach and end product. The test cases I’ve selected are quite common journeys, and there is a good chance you’ve written similar tests or had to consider similar scenarios, regardless of the product background.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first is ‘&lt;strong&gt;ADD TO CART&lt;/strong&gt;,’ the site’s core functionality as a user. We should be able to select an item, add it to our cart and progress to the checkout journey. Any discrepancies in product items or selection along the way should be caught by our test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second combines ‘&lt;strong&gt;SEARCH&lt;/strong&gt;’ and ‘&lt;strong&gt;FILTERING&lt;/strong&gt;.’ We should be able to search for a particular item or category of items and then filter the list returned. The common filtering techniques could be by most popular, lowest price, or most recently added.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once both tests are added, we will expand upon these user journeys by adding slight variations. This is a good technique to increase &lt;a href="https://www.lambdatest.com/blog/code-coverage-vs-test-coverage/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test coverage&lt;/a&gt; while reusing existing code — we add value to the test suite with minimal effort. The final project structure should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbb8r06t8g5g7g3ir4we4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbb8r06t8g5g7g3ir4we4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Watch this Playwright tutorial that covers everything you need to get you up and running with the Microsoft Playwright framework with TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wawbt1cATsk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Want to know more about how to perform &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;regression test&lt;/a&gt;? Let’s have a look at the detailed guide of Regression Testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing your first Playwright test
&lt;/h2&gt;

&lt;p&gt;This is a fairly standard user journey, I’d like to choose an item to purchase, add it to my cart, and the item should be visible when I go to checkout.&lt;/p&gt;

&lt;p&gt;In the playwright.config.js, I’ve defined the eCommerce playground base URL, so all of our tests will start from here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; use: {
        /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
        actionTimeout: 0,
        /* Base URL to use in actions like `await page.goto('/')`. */
        // baseURL: 'http://localhost:3000',

        /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
        trace: 'on-first-retry',
        baseURL: 'https://ecommerce-playground.lambdatest.io'
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the lambdatest-setup.js, which is referenced in our test files, we are defining our test platform capabilities, which will be used for local and remote execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // LambdaTest capabilities
     const capabilities = {
       'browserName': 'Chrome', // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
       'browserVersion': 'latest',
       'LT:Options': {
         'platform': 'Windows 10',
         'build': 'Playwright Build - Full suite',
         'name': 'Playwright Test',
         'user': process.env.LT_USERNAME,
         'accessKey': process.env.LT_ACCESS_KEY,
         'network': true,
         'video': true,
         'console': true,
         'tunnel': false, // Add tunnel configuration if testing locally hosted webpage
         'tunnelName': '', // Optional
         'geoLocation': '', // country code can be fetched from https://www.lambdatest.com/capabilities-generator/
       }
     }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the complete test file for add-to-cart.spec.js, I’ll walk through each step and explain why we have taken this approach.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @ts-check
const { test } = require('../../lambdatest-setup')
const { expect } = require('@playwright/test')

test.describe('Add to cart', () =&amp;gt; {
  test('Add to cart', async ({ page }) =&amp;gt; {

    // Navigate to base url
    await page.goto('https://ecommerce-playground.lambdatest.io')

    // Click Shop by Category
    await page.locator('text=Shop by Category').click();

    // Click Laptops &amp;amp; Notebooks
    await page.locator('text=Laptops &amp;amp; Notebooks').click();

    // Hover over product
    await page.locator('text=Add to Cart Add to Wish List HTC Touch HD $146.00 HTC Touch - in High Definition').hover()

    // Wait for element
    await expect(page.locator('text=Add to Cart Add to Wish List HTC Touch HD $146.00 HTC Touch - in High Definition &amp;gt;&amp;gt; button &amp;gt;&amp;gt; nth=0')).toBeVisible()

    await page.waitForTimeout(2000)

    // Click add to cart
    await page.locator('text=Add to Cart Add to Wish List HTC Touch HD $146.00 HTC Touch - in High Definition &amp;gt;&amp;gt; button').first().click()

    // Click view cart
    await page.locator('text=View Cart').click()

    // Assert correct product added to cart
    await expect(page.locator('#content &amp;gt;&amp;gt; text=HTC Touch HD')).toBeVisible()
    })
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The completed test suite we will be referencing is on GitHub if you want to follow along.&lt;/p&gt;

&lt;p&gt;There is a simple goto navigation, which extends upon our base URL. This is useful if we navigate to sub-pages within the website, as we won’t need to type the full base URL every time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        // Navigate to base url
          await page.goto('/')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will launch a page that looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2554%2F0%2Ai-MQ4epY-W7FJO3U.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2554%2F0%2Ai-MQ4epY-W7FJO3U.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, there are a few different ways to browse products on the page. There is ‘Shop by Category, ’ which opens a sub-menu, the search bar at the top, the main banners, and additional product icons as we navigate further down the page.&lt;/p&gt;

&lt;p&gt;For our first Playwright test, we will use the ‘Shop by Category’ menu to find our product. Firstly we need to click the menu, so it expands. For readability, I prefer to use text as our identifier — even if there are multiple elements with the same name, it’s still fairly easy to drill down further.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt; — To find the elements, I like to use a mix of &lt;a href="https://www.lambdatest.com/blog/playwright-python-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright Codegen&lt;/a&gt; and also manually inspect the elements in DevTools when needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         // Click Shop by Category
          await page.locator('text=Shop by Category').click();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AbQl8YJhYLYdyp_2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AbQl8YJhYLYdyp_2l.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AOw2O_9syKfnNlByw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AOw2O_9syKfnNlByw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we’ve expanded the menu, we have to decide which category we want to purchase an item from. I think a laptop would be good! Let’s use the same text &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;locator strategy&lt;/a&gt; as before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      // Click Laptops &amp;amp; Notebooks
          await page.locator('text=Laptops &amp;amp; Notebooks').click();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AK__z46_0wDMDSZxN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AK__z46_0wDMDSZxN.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following that action, we’ve landed on the Laptops &amp;amp; Notebooks product page — ignore the images that are not Laptops or Notebooks. It’s just placeholder content for testing purposes.&lt;/p&gt;

&lt;p&gt;If we hover over an item in the gallery, we will notice a menu presenting a few options.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AKcXp5f8T-K7FEgRe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AKcXp5f8T-K7FEgRe.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are interested in the first option, so we will need to hover over the product and click the first icon — this will add the product to our cart.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     // Hover over product
      await page.locator('text=Add to Cart Add to List HTC Touch HD $146.00 HTC Touch - in High Definition').hover()

      // Wait for element
      await expect(page.locator('text=Add to Cart Add to Wish List HTC Touch HD $146.00 HTC Touch - in High Definition &amp;gt;&amp;gt; button &amp;gt;&amp;gt; nth=0')).toBeVisible()

      // Click add to cart
      await page.locator('text=Add to Cart Add to Wish List HTC Touch HD $146.00 HTC Touch - in High Definition &amp;gt;&amp;gt; button').first().click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Hovering over the product is fairly simple. We provide the image/product locator, followed by the .hover() action. I used the text locator in this instance as it was unique.&lt;/p&gt;

&lt;p&gt;This screenshot is taken during the Playwright Codegen recording.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2564%2F0%2A4TyxB3KoOess9rkn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2564%2F0%2A4TyxB3KoOess9rkn.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the wait to be visible and click, I had to extend the locator slightly. We used two different approaches so that you can see different solutions to the same problem.&lt;/p&gt;

&lt;p&gt;In the wait for element step, we have added to the locator path with &amp;gt;&amp;gt; nth=0, which is getting the 0 position element, which in this case is the first of the four buttons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AtqagzCvj6yQdxmA6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AtqagzCvj6yQdxmA6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the click add to cart step, we are using almost the same locator, except this time instead of adding to the path, we are using the .first method, so click the first element of the four available.&lt;/p&gt;

&lt;p&gt;This is a breakdown of our approach in this tutorial on running your first Playwright test:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Identify product locator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hover over the product.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identify the actionable element we want to select.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Drill down into the group of elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make use of the Playwright index options and nth locator options.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both approaches have valid applications. The second may be better for reusability if you have a list of elements — in which case you will also be able to use locator.nth(index), in addition to .first() and .last().&lt;/p&gt;

&lt;p&gt;If we execute the test until this point, you should see a popup appear in the upper right corner of the screen. It presents us with two options, view cart, and checkout.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AQSnk9Jiu77nX7PdP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AQSnk9Jiu77nX7PdP.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The goal of this test is just to check the product has been correctly added to the cart. So we will be clicking the button which says ‘View Cart’. In some cases, waiting for the popup to appear may also be necessary, in which case we can do something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AeqUHHBG49ocsmAnW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AeqUHHBG49ocsmAnW.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     // Wait for element
        await expect(page.locator(‘.toast-header')).toBeVisible()

      // Click view cart
      await page.locator('text=View Cart').click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The last step of the journey is on the shopping cart page. We want to be confident that every time a user selects ‘Add to Cart’ on a product, it appears on the shopping cart page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AZlpXLDgiyeUlPa_G.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AZlpXLDgiyeUlPa_G.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The product name is a good indicator that not only has an item been added to the cart, but it is also the correct product we selected earlier. So we will use a locator path that contains the product name and verify it is visible on the page.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     // Assert correct product added to cart
      await expect(page.locator('#content &amp;gt;&amp;gt; text=HTC Touch HD')).toBeVisible()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That’s it — a very simple user journey, covering a few different types of interactions and verifications with the web page. Let’s run the test!&lt;/p&gt;

&lt;p&gt;This is the script I’m using to execute the laptop-specific test in the headed mode so we can see what is going on. In the terminal, you just need to type: npm run test.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     "scripts": {
        "test": "npx playwright test tests/add-to-cart/add-to-cart-laptop.spec.js --headed"
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AUwuoMhoyuEPoWCiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AUwuoMhoyuEPoWCiz.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a base test to work with, we can create some variations on this — and then start to execute a larger number of tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Expanding the Playwright test suite
&lt;/h2&gt;

&lt;p&gt;There are many different categories and products on the eCommerce website, so we can add a few tests to expand the test coverage. These were pretty easy to create, as they were minor locator updates.&lt;/p&gt;

&lt;p&gt;In this tutorial on running your first Playwright test, we have duplicated the files and locators for ease of use, but ideally, we should use an approach, such as the &lt;a href="https://www.lambdatest.com/blog/page-object-model-in-selenium-python/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Page Object Model (POM)&lt;/a&gt;, to maintain this. It increases reusability, minimizes code duplication, and makes general maintenance much easier.&lt;/p&gt;

&lt;p&gt;Here’s an example of the added code and the spec file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  // Hover over product
  await page.locator('text=Add to Cart Add to Wish List Nikon D300 $98.00 Engineered with pro-level feature').hover()

  // Wait for element
  await expect(page.locator('text=Add to Cart Add to Wish List Nikon D300 $98.00 Engineered with pro-level feature &amp;gt;&amp;gt; button &amp;gt;&amp;gt; nth=0')).toBeVisible()

  // Click add to cart
  await page.locator('text=Add to Cart Add to Wish List Nikon D300 $98.00 Engineered with pro-level feature &amp;gt;&amp;gt; button').first().click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AP_RHoogZ2S_NMsZk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AP_RHoogZ2S_NMsZk.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can execute these Playwright tests locally and still see fairly fast execution times. I’ve modified our npm run test script to include the whole Playwright test folder:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      "scripts": {
        "test": "npx playwright test tests/add-to-cart/ --headed"
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A7LJYFVsbMgwUPjEy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A7LJYFVsbMgwUPjEy.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many elements to interact with on the website, so let’s add a test to search for an item, filter by the most popular items returned, and add the most popular ones to our cart. There is some code we will reuse, and in the future, it would be good to create page objects or helper classes instead of copying/pasting our code.&lt;/p&gt;

&lt;p&gt;I’ve used the placeholder text locator for that field, and we are filling it with the text ‘ipod’. We are then clicking the search button to return our results.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      // Fill [placeholder="Search For Products"]
      await page.locator('[placeholder="Search For Products"]').first().fill('ipod');

      // Click text=Search
      await page.locator('text=Search').click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A1KG7SvX9YbekG_aZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A1KG7SvX9YbekG_aZ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to select ‘Popular’ from the ‘Sort by’ dropdown on the search results page. We can do that by text or index. For this example, I’ve used the index of the dropdown item we are looking for.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      // Click sort by 'Popular'
      await page.locator('#input-sort-212464').selectOption({index: 2})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AsgcuaDu_ndQGb_HN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AsgcuaDu_ndQGb_HN.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will reorder the items for us, and all we need to do is select the first product returned to the list and add it to our cart.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Wait for element
      await expect(page.locator('.product-action &amp;gt; button').first()).toBeVisible()

      // Click add to cart
      await page.locator('.product-action &amp;gt; button').first().click()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AtrpqOKM_4OrTwrAt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AtrpqOKM_4OrTwrAt.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Done! Nice, so now we have a new test from which we can create iterations. In total, I’ve created 6 tests. Let’s run them in parallel and see how they perform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AMYTZG5q__qd3W2n2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AMYTZG5q__qd3W2n2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When running 6 tests, I started to see intermittent failures, despite adding waits and timeouts — this is where we start approaching the limits of a single machine for &lt;a href="https://www.lambdatest.com/learning-hub/test-execution?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test execution&lt;/a&gt; and need to look towards a distributed solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AAuiNHBjfZ1LClNvM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AAuiNHBjfZ1LClNvM.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’ve worked with automation in any form, I’m sure you’ve seen a similar diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Atswp1cY9waZUXfzt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Atswp1cY9waZUXfzt.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the basic premise of Selenium Grid — we send tests from our ‘client’ machine to our ‘hub’, and the ‘hub’ distributes the tests out to our ‘nodes.’ In this example if we had a suite of 9 tests, and each node had 3 Chrome instances available, we would see 3 tests executed on each node in parallel.&lt;/p&gt;

&lt;p&gt;We will set Selenium Grid up on our local machine — it’s not following the intended architecture of Selenium Grid, as we won’t be creating separate VMs for our nodes. Still, it should give you an understanding of how it works and its benefits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download Java (you may need to set the environment variable path).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download Selenium Server (Grid).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download the latest stable Chromedriver version.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download the latest stable Geckodriver version.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the PATH environment variable for both drivers (folder location).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Accelerate your release velocity with blazing fast &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; on cloud!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Playwright test execution
&lt;/h2&gt;

&lt;p&gt;Run the following command from your download location for Selenium Server (Grid). The version number may need to be changed if a newer version has been released.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    java -jar selenium-server-4.3.0.jar standalone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the terminal, you should see the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2094%2F0%2AHXmRHWq4T1mVXJwP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2094%2F0%2AHXmRHWq4T1mVXJwP.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It has detected 16 available processors and 2 drivers, and as a result, has created 16 instances of Chrome and Firefox. The grid has been started at &lt;a href="http://localhost:4444/" rel="noopener noreferrer"&gt;http://localhost:4444/&lt;/a&gt;. If we navigate that URL, we should see the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AR-3WJR8xUh-3Sjci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AR-3WJR8xUh-3Sjci.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we can send some tests to the grid. If we open a Git bash terminal and run the following command (replace the localhost value):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    SELENIUM_REMOTE_URL=http://localhost:4444/wd/hub npx playwright test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Playwright will execute its tests on the Selenium Grid remote URL, and we should be able to see 6 sessions actively running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AtzRT4auITT11WJ-P.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AtzRT4auITT11WJ-P.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2522%2F0%2AGIivT146WQlAFpuP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2522%2F0%2AGIivT146WQlAFpuP.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AScYH4-pAINaeHAB0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AScYH4-pAINaeHAB0.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s basically all we need to know about how to run tests on Selenium Grid at a basic level — the more involved setups involve multiple VMs, and there are many useful Docker images/compose file templates that can be used to spin up the grid environment.&lt;/p&gt;

&lt;p&gt;Once we start scaling out, we can run larger amounts of tests concurrently and at a faster speed — limited only by hardware costs and management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Run automated browser testing on the most robust cloud infrastructure. Leverage LambdaTest &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated testing&lt;/a&gt; for a more responsive, dependable, and scalable cloud experience.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Running your first Playwright test on cloud grid
&lt;/h2&gt;

&lt;p&gt;Now to take our test suite and run it on a larger scale — more platforms and more browsers. We will be using the LambdaTest Cloud Grid for these examples, so you’ll need a few things configured before we begin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/benefits-of-cloud-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cloud testing&lt;/a&gt; platforms like LambdaTest help you perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; at scale. It offers an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 50+ browsers and browser versions of Chrome, Chromium, Microsoft Edge, Mozilla Firefox, and even Webkit to run your first Playwright script.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ioJaNCYX7Qc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt;, stay updated with the latest playwright tutorial, and discover tutorials around topics like &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;mobile app testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites to run your first Playwright test on cloud
&lt;/h2&gt;

&lt;p&gt;We will use a new configuration file that references LT_USERNAME AND LT_ACCESS_KEY environment variables.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       'user': process.env.LT_USERNAME,
        'accessKey': process.env.LT_ACCESS_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can find this information under Dashboard, Automation, or User settings. Copy the values and set them as your local machines environment variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Af6l1wYJBnCk_NsrC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Af6l1wYJBnCk_NsrC.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Playwright test configuration on cloud
&lt;/h2&gt;

&lt;p&gt;In our playwright.config.js, we have now set a few new projects:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;projects: [
    {
      name: 'chrome:latest:MacOS Catalina@lambdatest',
      use: {
        viewport: { width: 1920, height: 1080 }
      }
    },
    {
      name: 'chrome:latest:Windows 10@lambdatest',
      use: {
        viewport: { width: 1920, height: 1080 }
      }
    },
    {
      name: 'MicrosoftEdge:90:Windows 10@lambdatest',
      use: {
        viewport: { width: 1920, height: 1080 }
      }
    },
    {
      name: 'pw-firefox:latest:Windows 10@lambdatest',
      use: {
        viewport: { width: 1920, height: 1080 }
      }
    },
    {
      name: 'pw-webkit:latest:MacOS Catalina@lambdatest',
      use: {
        viewport: { width: 1920, height: 1080 }
      }
    }
  ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There is logic in the lambdatest-setup.js file, which runs our tests based on the following format: &lt;strong&gt;browserName:browserVersion:platform&lt;/strong&gt; (separate by colons). You can edit and change these values or add new configurations if needed. You can also modify the viewport size and device emulation values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Which are the most wanted &lt;a href="https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated testing tools&lt;/a&gt; that have climbed the top of the ladder so far? Let’s take a look.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Playwright test execution on cloud
&lt;/h2&gt;

&lt;p&gt;With the variables and project configurations in place, we are ready to run the tests. Run the &lt;strong&gt;npm run test&lt;/strong&gt;, and you should see tests executing in the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmhT2dsjqxwQoMl1J.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AmhT2dsjqxwQoMl1J.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see 30 tests running this time, as our 6 tests are run against 5 different configurations. Some tests are passing across our chrome set up, which we would expect as this is what we tested against locally earlier on. But you’ll also notice a lot of red — as platforms we haven’t tested give unexpected results.&lt;/p&gt;

&lt;p&gt;This is good news — our tests have caught an issue with our website or our code. After looking into the test results and logs, one of the issues becomes very clear. We are testing against a mobile view, where the layout and elements have changed — for example, we no longer have the main menu bar, which has collapsed to a hamburger menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2530%2F0%2AJBhwpyNKobHcF7Qa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2530%2F0%2AJBhwpyNKobHcF7Qa.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the short term, we can change the viewport to match the others — so we still have desktop coverage against the Microsoft Edge platform. In the long term, we would need to rewrite the test logic to accommodate the mobile view or create a separate suite of tests for that platform.&lt;/p&gt;

&lt;p&gt;The last issue we have is with WebKit — initially, we had it running on Windows, so I tried on macOS to see if there were compatibility issues, but the issue occurred on both. The tests could not hover over the products and click add to cart. This is potentially a genuine issue, and for this scenario, we would manually test the website on that platform and try to debug the issue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AHJj8PI11H6RFo-gU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AHJj8PI11H6RFo-gU.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at our local setup and how it compares to the Cloud Grid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local Grid&lt;/strong&gt; — 6 tests run on Chrome Windows — with the potential to run Firefox, Edge, and WebKit. Additional configuration is required to scale and increase platform coverage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloud Grid&lt;/strong&gt; — 30 tests run on Windows and Mac platforms across Chrome, Firefox, Edge, and WebKit. Not only do we have an incredible amount of test coverage out of the box, but the configuration was minimal, and the maintenance is zero — we just have to worry about building and increasing the test suite coverage.&lt;/p&gt;

&lt;p&gt;If you are a developer, this certification is the perfect measure of your expertise as a Playwright automation tester in performing end-to-end testing for modern web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;It’s no longer good enough to run manual and automated tests on a single most popular configuration, i.e., Chrome with Windows or Safari with Mac. We need to be able to run a large number of tests, quickly and at scale, across a matrix of browsers, platforms, and resolutions.&lt;/p&gt;

&lt;p&gt;With a Cloud Grid platform, a lot of the complexity is taken away from the user, so they can focus on what matters — writing robust and effective automated tests.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
