<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sumalatha Elliadka on Medium]]></title>
        <description><![CDATA[Stories by Sumalatha Elliadka on Medium]]></description>
        <link>https://medium.com/@sumalathabhat?source=rss-f1f584c88af5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Sumalatha Elliadka on Medium</title>
            <link>https://medium.com/@sumalathabhat?source=rss-f1f584c88af5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:04:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sumalathabhat/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Web automation with Playwright]]></title>
            <link>https://medium.com/testvagrant/web-automation-with-playwright-5759d767cdcb?source=rss-f1f584c88af5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5759d767cdcb</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[microsoft-playwright]]></category>
            <category><![CDATA[frameworks-and-libraries]]></category>
            <category><![CDATA[web-automation]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sumalatha Elliadka]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 04:56:25 GMT</pubDate>
            <atom:updated>2021-03-15T04:56:25.635Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ocHGhylxcp_do5jHUAFyqA.png" /></figure><p>The playwright is an open-source web automation library that is built on top of <a href="https://developers.google.com/web/tools/puppeteer">Puppeteer</a>. It is developed by the authors of Puppeteer and maintained by Microsoft. In this article, let’s look into a web-framework developed using Playwright, Playwright-test and Typescript and explore its capabilities.</p><h3><strong>Why Playwright</strong></h3><p>Most of us have worked on web automation at some point of time in our career. The common challenges we face while automating are slowness of test execution, unreliable wait scenarios, the need to write a lot of boiler-plate code for browser setup, and parallel execution, etc. The playwright tries to address these issues and makes test authoring more readable, fast and reliable. Let’s see how we can achieve this in the following sections.</p><p><strong><em>Installation: </em></strong>One of the <em>why</em> factor of using Playwright is, it’s easy to setup<strong>! </strong>Once<em> </em>you execute the line of code shown below, Playwright downloads binaries for all 3 supported browsers. With a single command, the setup is ready for web-automation!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzT8M88AE2f_zCwnXCaPdA.png" /></figure><p><strong><em>Browser, Context and Page: </em></strong>Playwright works on the principle of 3 main core concepts: Browser, Context and Page.</p><ul><li><strong>Browser</strong>: First thing we need to run tests is to launch a browser. The playwright does this using the object of Browser class which is nothing but an instance of either Chromium, Firefox or Webkit.</li><li><strong>Context</strong>: Playwright achieves parallelization through browser contexts. In the playwright’s term “Browser Context is an isolated incognito-alike session within a browser instance”.</li><li><strong>A page</strong> is a new tab or pop-up window within a context. Every action on the test will be performed on this object.</li></ul><p><strong><em>Cross-browser support</em></strong><em>: </em>Playwright supports the most commonly used 3 browser engines: Chromium, Firefox and Webkit. So, tests can be written once and can be executed across all browsers with no or minimal configuration.</p><p>Let’s look into the script section of <strong>package.json. </strong>This uses the playwright’s test-runner.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4610e174c72867195e48fde668d588e/href">https://medium.com/media/b4610e174c72867195e48fde668d588e/href</a></iframe><p>When line# 7 gets executed, all tests in your suites by default run in all 3 browsers. Of course, it is possible to run in a specific browser.</p><p>If <a href="https://jestjs.io/"><strong>Jest</strong></a> is used as a runner then browser information can be set as part of <strong>jest-playwright.config.js </strong>as shown below to run tests across all browsers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OhW9vzv85k1fSgEJ_eZ-IA.png" /><figcaption>jest-playwright.config.js</figcaption></figure><p><strong><em>Auto-waiting and reliable execution</em></strong><em>: </em>One<em> </em>of the advantages of using Playwright is that it<em> </em>auto-waits for UI elements to be available before acting. This makes the test authoring simple and avoids the extra steps of adding explicit waits. For example, let’s look into the POM class below and understand how it works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e881c501a70d8e51fac3d17e1d14c71c/href">https://medium.com/media/e881c501a70d8e51fac3d17e1d14c71c/href</a></iframe><p>When line#16 is executed, the playwright performs checks to see whether the selector is enabled to receive events, whether it’s stable, visible and attached to DOM. After all, these checks are passed, only then it performs a click action on the selector. If wait fails after default timeout of 30 secs, then timeout error will be thrown by the playwright.</p><p>It is possible that when a page contains some animation condition or dynamic contents, there is a need to wait for the set amount of time. <strong><em>WaitForTimeout </em></strong>can be used under such scenarios<strong><em>.</em></strong></p><p><strong><em>Custom waits</em></strong><em>: </em>For scenarios like lazy page loading, the playwright provides custom wait where tests can wait for a selector to be available. Similarly, it is possible to wait until certain network conditions are met.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3oEK3BliYrh1AlliJVOIA.png" /></figure><p><strong><em>Authentication</em></strong>: Authentication is a common feature in web frameworks. Playwright allows to login once and stores the session details, cookies inside a context as shown below. Once this is stored it can be used across all tests within that context and prevents the need for multiple logins. This code has to be part of setup files(in the case of Jest) / test fixtures(in the case of playwright-test runner) so that it can be applied across context objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SMCAuDNvmEcNL3e5Ty8MIw.png" /></figure><p><strong><em>Selectors: </em></strong>Apart from common selectors like id, XPath, CSS, class name etc. supported by other frameworks like Selenium, Playwright can rely on more resilient selectors like text content, accessibility labels to locate elements. Here is an example of locating element using data-test-id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucO46BphBK-QESQ1iocRfA.png" /></figure><h3>Playwright Test Runner</h3><p>The playwright can be easily integrated with JavaScript <a href="https://playwright.dev/docs/test-runners">test runners</a> like Jest, <a href="https://github.com/avajs/ava">Ava</a> and <a href="https://mochajs.org/">Mocha</a>. In this blog let’s look at the playwright’s own test runner <a href="https://github.com/microsoft/playwright-test">Playwright-test</a>.</p><p>Playwright-test is built, based on the test framework <a href="https://github.com/microsoft/folio">folio</a> and provides inbuilt support for Typescript. It uses <a href="https://jestjs.io/docs/en/expect">expect</a> for assertions and provides spec functions “it, describe etc” for automating tests.</p><p><strong><em>Installation:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_LOm2irL-0qR7jdsZgNpw.png" /></figure><p><strong><em>Default Arguments: </em></strong>As discussed earlier, the playwright needs page, context, browser objects to author tests. Playwright-test runner takes care of initializing and creating these objects either with default values or based on the configurations provided and make them available for all tests across the project.</p><p><strong><em>Fixtures: </em></strong>Playwright-test runner inherited the concept of test fixtures from <a href="https://github.com/microsoft/folio">Folio</a>. Fixtures are the setup that is required for a test to run. It could be an environment, a state or preconditions. There are 2 types of fixtures supported by the test runner.</p><ul><li><em>Test fixtures</em>: These are the setup or conditions that apply to every test.</li><li><em>Worker fixtures</em>: Folio uses the concept of workers which are nothing but a process to run each test file. It is possible to apply the fixtures at the process level as well.</li></ul><p>Below is a sample scenario of where we can apply authentication per worker process. Please note where the scope is specified as a worker. If nothing is specified, then the default scope applies to all tests. Let us save the file as <em>fixtures.ts</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/479220b74d19dbe589c55cfc00f7aa1f/href">https://medium.com/media/479220b74d19dbe589c55cfc00f7aa1f/href</a></iframe><ul><li>Once fixtures are created they can be used inside tests as shown below</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/122af6de7bcca02e85fbc03c47fc4edd/href">https://medium.com/media/122af6de7bcca02e85fbc03c47fc4edd/href</a></iframe><ul><li>It’s important to note that once fixtures are defined and built, the test functions “it, describe before each” has to be used from the object that’s being built. It’s not possible to use multiple fixtures inside the same test file.</li><li>More detailed information on various types of configurations can be found <a href="https://github.com/microsoft/playwright-test#configuration">here</a></li></ul><p><strong><em>CLI to run the tests: </em></strong>Since the playwright’s test runner uses Folio in the background, the command to execute tests requires folio as well. By default, it will allocate one worker process per file and runs all files in parallel. Tests within the file are executed sequentially.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yo68_rOv8kCTE7NSy7yDFw.png" /></figure><ul><li>browserName: When there is a need to run tests in a specific browser, then this parameter can be passed with the browser name.</li><li>headFul: If set to true, it will run the tests by opening the browsers. For CI, it is recommended to set it to false. Also running in headless mode executes the tests faster.</li><li>screenshotOnFaiure: If a test is failed then the screenshot will be stored under test-results</li><li>reporter: If specified it can generate XML style reporting similar to JUnit</li></ul><h3>Continuous Integration</h3><p>The playwright provides a docker image and can be easily integrated as part of CI. Here is a sample `.gilab-ci.yml` for integration with Gitlab.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00ac4175fec492d9ed0b8cec73380b44/href">https://medium.com/media/00ac4175fec492d9ed0b8cec73380b44/href</a></iframe><h3><strong>Conclusion</strong></h3><p>The playwright is an amazing framework to explore and is just a year old when this blog is written. Since it’s inception it has evolved a lot and has a growing community of users. It’s a node.js library and built for a highly reactive modern web application, which makes tests written using this framework, faster, capable and reliable. It was a great experience to explore this tool and good learning!</p><p><a href="https://gitlab.com/learnings_testvagrant/javascript-learning-program-2020-21/playwright_web_project"><em>Here</em></a> is the code link which touches upon the concepts explained in this blog.</p><p>Thanks to <a href="https://www.linkedin.com/in/nishant-sharma-204214126/">Nishant Sharma</a> who worked with me on Playwright!</p><h3><strong>Resources</strong>:</h3><ol><li><a href="https://github.com/microsoft/playwright">https://github.com/microsoft/playwright</a></li><li><a href="https://github.com/microsoft/playwright-test">https://github.com/microsoft/playwright-test</a></li><li><a href="https://github.com/microsoft/folio">https://github.com/microsoft/folio</a></li></ol><p>Thanks for Reading !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5759d767cdcb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/testvagrant/web-automation-with-playwright-5759d767cdcb">Web automation with Playwright</a> was originally published in <a href="https://medium.com/testvagrant">TestVagrant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>