<?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>DEV Community: samsuthen akbarali</title>
    <description>The latest articles on DEV Community by samsuthen akbarali (@samsuthen_akbarali_509e48).</description>
    <link>https://dev.to/samsuthen_akbarali_509e48</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%2F1131422%2Faad2ea20-0d33-4c4e-aa82-3530ea498d7e.png</url>
      <title>DEV Community: samsuthen akbarali</title>
      <link>https://dev.to/samsuthen_akbarali_509e48</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samsuthen_akbarali_509e48"/>
    <language>en</language>
    <item>
      <title>Passing Test Data to onTestEnd Reporter Method in Playwright</title>
      <dc:creator>samsuthen akbarali</dc:creator>
      <pubDate>Sat, 11 Nov 2023 06:13:38 +0000</pubDate>
      <link>https://dev.to/samsuthen_akbarali_509e48/passing-test-data-to-ontestend-reporter-method-in-playwright-1573</link>
      <guid>https://dev.to/samsuthen_akbarali_509e48/passing-test-data-to-ontestend-reporter-method-in-playwright-1573</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When working with Playwright for end-to-end testing, it's essential to gather meaningful data during test execution. In certain scenarios, passing test-specific data, such as configurations or test case details, to the onTestEnd reporter method can be beneficial for comprehensive reporting and analysis. This article provides guidance on how to achieve this in Playwright.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider a scenario where you have a test suite iterating over a set of records, and you want to pass individual record data to the onTestEnd method for reporting purposes. Here's a simplified example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M-djw2EM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzdsfbjziixxhgkwgc1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M-djw2EM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzdsfbjziixxhgkwgc1a.png" alt="Image description" width="800" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the onTestEnd method, you need to access the record object for reporting:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2mK2YgLD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa3kd1vkxv2ty1wf8lb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2mK2YgLD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa3kd1vkxv2ty1wf8lb3.png" alt="Image description" width="800" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Annotations in Playwright&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To pass data from each test to the &lt;code&gt;onTestEnd&lt;/code&gt; method, Playwright provides the concept of custom annotations. Annotations are key/value pairs accessible via &lt;code&gt;test.info().annotations&lt;/code&gt;. While Playwright annotations typically accept key-value pairs, they don't directly support objects. To overcome this limitation, you can stringify the object before storing it in the annotations.&lt;/p&gt;

&lt;p&gt;Here's how you can implement this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fQcEbDmT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qbrree8ukxefghjj54y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fQcEbDmT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qbrree8ukxefghjj54y.png" alt="Image description" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, JSON.stringify is used to convert the uiRecord object to a string before storing it in the annotations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reporter Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VaFqrLwW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1gx3rcspg9gk4ga0ajy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VaFqrLwW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1gx3rcspg9gk4ga0ajy.png" alt="Image description" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the onTestEnd method, the description property of the annotation is parsed back into an object using JSON.parse. Now, you have access to the original uiRecord object for reporting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
By utilizing custom annotations in Playwright, you can efficiently pass test-specific data, even objects, to the onTestEnd reporter method. This approach enhances the reporting capabilities and allows you to gather valuable insights during your test execution.&lt;/p&gt;

</description>
      <category>playwright</category>
    </item>
    <item>
      <title>Enhancing Playwright Test Automation: Real-time Failure Notifications with Microsoft Teams</title>
      <dc:creator>samsuthen akbarali</dc:creator>
      <pubDate>Mon, 18 Sep 2023 11:53:48 +0000</pubDate>
      <link>https://dev.to/samsuthen_akbarali_509e48/enhancing-playwright-test-automation-real-time-failure-notifications-with-microsoft-teams-gfd</link>
      <guid>https://dev.to/samsuthen_akbarali_509e48/enhancing-playwright-test-automation-real-time-failure-notifications-with-microsoft-teams-gfd</guid>
      <description>&lt;p&gt;Playwright, a versatile and robust testing framework, has gained immense popularity for its ability to automate end-to-end testing across various web applications. However, it's not just about running tests; it's also about monitoring and responding to test results effectively. In this blog, we'll explore how to enhance your Playwright test automation pipeline by setting up real-time failure notifications to a Microsoft Teams channel using webhooks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Real-time Notifications Matter
&lt;/h2&gt;

&lt;p&gt;When you have a suite of automated tests, it's essential to stay informed about their execution status. Real-time notifications provide several advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster Issue Resolution&lt;/strong&gt;: Immediate notifications enable faster identification and resolution of issues, minimizing downtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team Collaboration&lt;/strong&gt;: Notifications in a Teams channel facilitate collaboration among team members, allowing them to discuss and address failures promptly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous Monitoring&lt;/strong&gt;: You can keep a constant watch on your test suite's health without manual intervention.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's dive into the implementation steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, make sure you have the following in place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Playwright project set up with your test scripts.&lt;/li&gt;
&lt;li&gt;Microsoft Teams channel where you want to receive notifications.&lt;/li&gt;
&lt;li&gt;Webhook URL for your Teams channel.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Configure Webhook in Microsoft Teams
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In your Microsoft Teams channel, click on the three dots (...) to open the context menu and select 'connectors'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--08kNeweT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkgdjsh0dq9hhwz9z0oq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--08kNeweT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkgdjsh0dq9hhwz9z0oq.png" alt="Image description" width="613" height="872"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search for 'Incoming Webhook' and click on it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W_f1yXFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hg430chis5z2lwjt3cz2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W_f1yXFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hg430chis5z2lwjt3cz2.png" alt="Image description" width="800" height="636"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Follow the prompts to configure the webhook, and you will receive a unique URL. This URL is essential for sending notifications to your Teams channel.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YxwIxLil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6bttil8jcgetrbjr813.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YxwIxLil--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6bttil8jcgetrbjr813.png" alt="Image description" width="800" height="831"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Implement Notification Logic
&lt;/h2&gt;

&lt;p&gt;In your Playwright project, implement notification logic for test failures. Here's a sample TypeScript code snippet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yZStp7kM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wy72sslpe92yo20uk7ng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yZStp7kM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wy72sslpe92yo20uk7ng.png" alt="Image description" width="800" height="709"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure Playwright Reporter
&lt;/h2&gt;

&lt;p&gt;You can create a custom Playwright reporter that integrates the notification logic. Here's an example reporter script:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w3sd5cRA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klreqn0qtsea2lae3dh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w3sd5cRA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klreqn0qtsea2lae3dh5.png" alt="Image description" width="725" height="941"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Integrate Custom Reporter
&lt;/h2&gt;

&lt;p&gt;Integrate the custom reporter into your Playwright test execution. You can specify it in your test configuration file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cqZU_qlx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gb0l68na0f4psu4viyek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cqZU_qlx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gb0l68na0f4psu4viyek.png" alt="Image description" width="436" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Notification Is Displayed Like This
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6qi2nvwi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ve7elb19nw2e0v9ja8ea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6qi2nvwi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ve7elb19nw2e0v9ja8ea.png" alt="Image description" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;By implementing real-time failure notifications in your Playwright test automation pipeline, you can streamline issue resolution and collaboration within your team. These notifications empower you to act swiftly, ensuring the reliability of your web applications. Playwright, combined with Teams integration, provides a powerful solution for modern test automation.&lt;/p&gt;

&lt;p&gt;Enhance your testing workflow today by implementing these real-time notifications and experience the benefits firsthand.&lt;/p&gt;

&lt;p&gt;Happy testing!&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>testing</category>
      <category>automation</category>
    </item>
    <item>
      <title>Extract Text from Image using Tesseract in Playwright TypeScript Project</title>
      <dc:creator>samsuthen akbarali</dc:creator>
      <pubDate>Tue, 15 Aug 2023 11:14:45 +0000</pubDate>
      <link>https://dev.to/samsuthen_akbarali_509e48/extract-text-from-image-using-tesseract-in-playwright-typescript-project-1b28</link>
      <guid>https://dev.to/samsuthen_akbarali_509e48/extract-text-from-image-using-tesseract-in-playwright-typescript-project-1b28</guid>
      <description>&lt;p&gt;Sometimes, you might come across a situation where you need to extract text from an image within your Playwright TypeScript project. This could be for various reasons, such as extracting information from screenshots or images generated during test execution. In this guide, we'll explore how to achieve this using Tesseract.js, a popular JavaScript library for Optical Character Recognition (OCR).&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before you begin, ensure you have the necessary dependencies installed. You'll need Node.js and the Playwright library installed. Additionally, you'll need the Tesseract.js library, which can be installed using the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install tesseract.js@2.1.1&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing Playwright Test Code
&lt;/h2&gt;

&lt;p&gt;Let's assume you have a Playwright test project set up, and you want to extract text from an image within a specific test case. Here's an example of how you can achieve this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZjgUhL61--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9062brn60k3xn20hbl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZjgUhL61--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9062brn60k3xn20hbl4.png" alt="Image description" width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing the Tesseract Code
&lt;/h2&gt;

&lt;p&gt;You've created a separate function to handle the Tesseract OCR process. Here's the implementation for the convertToText function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FyAdPyl9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/35d3mtw5t20g0rxx6e9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FyAdPyl9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/35d3mtw5t20g0rxx6e9g.png" alt="Image description" width="800" height="301"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This function uses the Tesseract.js library to recognize text from the image and logs the extracted text to the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Element screenshot:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XOUg_wmw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbx1qg9znhxj2dsytrbu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XOUg_wmw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbx1qg9znhxj2dsytrbu.png" alt="Image description" width="207" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CColQNfH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/em68cchrhnvazdrqhpjs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CColQNfH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/em68cchrhnvazdrqhpjs.png" alt="Image description" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;By integrating Tesseract.js with your Playwright TypeScript project, you can easily extract text from images and use it in your test automation scenarios. This capability can be particularly useful when dealing with dynamically generated content in your web application. Remember to handle potential errors during the OCR process to ensure the stability of your test suite.&lt;/p&gt;

&lt;p&gt;With these steps, you're well-equipped to extract text from images within your Playwright TypeScript project using Tesseract.js. Happy testing!&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>playwrighttest</category>
    </item>
    <item>
      <title>Executing Playwright Tests in Multiple Environments</title>
      <dc:creator>samsuthen akbarali</dc:creator>
      <pubDate>Thu, 10 Aug 2023 12:41:27 +0000</pubDate>
      <link>https://dev.to/samsuthen_akbarali_509e48/executing-playwright-tests-in-multiple-environments-4dcg</link>
      <guid>https://dev.to/samsuthen_akbarali_509e48/executing-playwright-tests-in-multiple-environments-4dcg</guid>
      <description>&lt;p&gt;Automated testing is a crucial aspect of ensuring the reliability and functionality of your web applications across different environments. Playwright, a powerful automation framework, allows you to execute tests seamlessly in multiple environments. In this blog post, we'll explore the reasons behind testing in multiple environments and provide a step-by-step guide to set up Playwright tests for various scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Execute Tests in Multiple Environments?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Environment Variability:&lt;/strong&gt; Web applications are accessed from different environments such as development, testing, staging, and production. Each environment might have unique configurations, settings, and data, which can impact the behavior of your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Bug Detection:&lt;/strong&gt; By testing in various environments, you can uncover issues that might not arise in a single environment. This helps you identify bugs early and ensure consistent performance across the board.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Configuration Validation:&lt;/strong&gt; Executing tests in different environments validates whether your application's configuration settings are correctly applied and functional.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and Setup
&lt;/h2&gt;

&lt;p&gt;Before we dive into executing tests in multiple environments, make sure you have the necessary dependencies installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the &lt;code&gt;dotenv&lt;/code&gt; package to manage environment variables:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm install dotenv&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;cross-env&lt;/code&gt; for managing environment variables across different platforms:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm install cross-env&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Environment Profiles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create environment profile files (e.g., .env.dev, .env.test, .env.uat) for each environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2F2njmksxncaezh79lk3lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F2njmksxncaezh79lk3lg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Define unique keys for configuration settings in each environment file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fnb8wxcjdz2ys9udn533z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fnb8wxcjdz2ys9udn533z.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create unique keys for separate env.ts file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fnwamx7z4a62w05998py9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fnwamx7z4a62w05998py9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fdb17111a7anzvwqgld0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fdb17111a7anzvwqgld0e.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Global Setup
&lt;/h2&gt;

&lt;p&gt;To dynamically load environment variables before test execution, create a &lt;code&gt;globalSetup.ts&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fetzqf5fjyqezejfpycmb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fetzqf5fjyqezejfpycmb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Playwright
&lt;/h2&gt;

&lt;p&gt;In your Playwright configuration file, specify the path to the &lt;code&gt;globalSetup.ts&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Ffnsq5u9l2u7lo0oy32vx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Ffnsq5u9l2u7lo0oy32vx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution Commands
&lt;/h2&gt;

&lt;p&gt;In your &lt;code&gt;package.json&lt;/code&gt;, add execution commands for each environment:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fnp3r7s3gro78p0he4upr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fnp3r7s3gro78p0he4upr.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Executing the Playwright Tests
&lt;/h2&gt;

&lt;p&gt;To run tests in a specific environment, use the corresponding npm script:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For testing in the test environment: &lt;code&gt;npm run env:test&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;For testing in the uat environment: &lt;code&gt;npm run env:uat&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;For testing in the dev environment: &lt;code&gt;npm run env:dev&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Executing Playwright tests in multiple environments is a fundamental practice for ensuring your web applications' functionality and reliability across various scenarios. By following these steps, you'll be equipped to seamlessly test your applications in different environments, catch bugs early, and maintain consistent performance.&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>testing</category>
      <category>automation</category>
    </item>
    <item>
      <title>Exploring Playwright TypeScript Visual Comparison Testing</title>
      <dc:creator>samsuthen akbarali</dc:creator>
      <pubDate>Thu, 10 Aug 2023 05:27:41 +0000</pubDate>
      <link>https://dev.to/samsuthen_akbarali_509e48/exploring-playwright-typescript-visual-comparison-testing-4d6k</link>
      <guid>https://dev.to/samsuthen_akbarali_509e48/exploring-playwright-typescript-visual-comparison-testing-4d6k</guid>
      <description>&lt;p&gt;In the world of software automation testing, ensuring the visual consistency of web applications is paramount. Imagine a scenario where a tiny code change inadvertently leads to a visual glitch in your application's UI. To prevent such mishaps, visual comparison testing comes to the rescue. In this blog post, we'll dive into the realm of Playwright and TypeScript for effective visual comparison testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Unveiling Visual Comparison Possibilities&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Visual comparison testing with Playwright and TypeScript opens up a realm of possibilities. You can conduct visual comparisons at different levels to capture and analyze potential visual discrepancies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Page Comparison:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By capturing screenshots of entire web pages, you can easily identify any unexpected visual changes caused by code alterations. Consider the following code snippet that encapsulates this approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("Page compare", async ({ page }) =&amp;gt; {
  await expect(page).toHaveScreenshot(['Login', 'starter.png']);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default screenshot name is autogenerated. However, if you want more control, you can optimize the toHaveScreenshot or toMatchSnapshot function by passing an array parameter. Here, 'Login' refers to a folder name created under a specific test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text or Image Comparison:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dive deeper into the UI by comparing specific text content or images within elements. The following code demonstrates how you can achieve this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('Text content compare', async ({ page }) =&amp;gt; {
  expect(await page.textContent('p[class="intro-subtitle"]')).toMatchSnapshot(['Login','hero.txt'])
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Element Comparison:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Sometimes, focusing on specific UI elements is crucial. Here's how you can compare elements like a pro:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('Element compare', async ({ page }) =&amp;gt; {
  expect(await page.locator('div[class="starter-logo-box"]').screenshot()).toMatchSnapshot(['Login', 'ncsclogo.png']);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Taming Pixel Differences
&lt;/h2&gt;

&lt;p&gt;To account for minor visual discrepancies due to various factors, you can configure pixel differences in Playwright's config file or at the test level:&lt;/p&gt;

&lt;p&gt;In the Playwright config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expect: {
  toHaveScreenshot: { maxDiffPixels: 500 },
  toMatchSnapshot: { maxDiffPixels: 500 },
}

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

&lt;/div&gt;



&lt;p&gt;At the test level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await expect(page).toHaveScreenshot({ maxDiffPixels: 100 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Challenges and CI Integration
&lt;/h2&gt;

&lt;p&gt;However, there's a challenge that emerges when executing tests across different platforms and Continuous Integration (CI) environments. Snapshot naming conventions can vary, leading to inconsistencies. For instance, while running tests locally, a snapshot name might look like &lt;code&gt;example-test-1-chromium-darwin.png&lt;/code&gt;. But if you pass a snapshot name as "Image," on a Windows machine, it could become &lt;code&gt;Image-win32.png&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When executing tests through CI on a Linux environment, the discrepancy in snapshot naming can lead to failures. This is where Docker comes to the rescue. By containerizing your code and ensuring consistent naming conventions, you can avoid this issue altogether.&lt;/p&gt;

&lt;p&gt;However, if you're determined to run tests locally without Docker, a nifty workaround exists:&lt;/p&gt;

&lt;p&gt;By creating a fixture that removes the snapshot suffix, you can achieve uniform snapshot names across all platforms. Here's how you can implement it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_autoSuffix: [
  async ({}, use, testInfo) =&amp;gt; {
    testInfo.snapshotSuffix = `${testInfo.title}`;
    await use();
  },
  { auto: true },
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This fixture modifies the snapshot suffix based on the test title, ensuring uniformity in snapshot names.&lt;/p&gt;

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

&lt;p&gt;Visual comparison testing with Playwright and TypeScript is a powerful approach to maintain the visual integrity of your web applications. Armed with the ability to compare entire pages, specific elements, and text or images, you can catch visual discrepancies with precision. By configuring pixel differences and tackling challenges like snapshot naming, you pave the way for more reliable and robust automated testing practices.&lt;/p&gt;

</description>
      <category>playwright</category>
    </item>
    <item>
      <title>How to Download Files Using Playwright in Typescript</title>
      <dc:creator>samsuthen akbarali</dc:creator>
      <pubDate>Tue, 08 Aug 2023 07:43:09 +0000</pubDate>
      <link>https://dev.to/samsuthen_akbarali_509e48/how-to-download-files-using-playwright-in-typescript-5g44</link>
      <guid>https://dev.to/samsuthen_akbarali_509e48/how-to-download-files-using-playwright-in-typescript-5g44</guid>
      <description>&lt;p&gt;Are you struggling with downloading files using Playwright in your Typescript projects? In this guide, I will walk you through a step-by-step solution to tackle this issue.&lt;/p&gt;

&lt;p&gt;Specifically, we’ll focus on scenarios where there is a download button in the browser, and upon clicking it, a new tab opens to start the download. After the download is completed, the new tab closes automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Download Button&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step is to create a function that clicks the download button and waits for the new tab to open. I will use Playwright waitForEvent method to handle this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function clickDownloadButton(){
    const [newTab] = await Promise.all([
        this.page.waitForEvent("popup"),
        this.waitAndClick(this.elements.button_downloadButton)
    ]);
    return newTab;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above function, we utilize waitForEvent("popup") to wait for the new tab to open. Once the download button is clicked, we capture the new tab object in the newTab variable and return it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling the Download Event&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to handle the download event in the newly opened tab. The following code snippet does just that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newTab = await dashboard.clickDownloadButton();
const [download] = await Promise.all([
    newTab.waitForEvent("download")
]);
const path = download.suggestedFilename();
await download.saveAs(path);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we call the clickDownloadButton() function and get the new tab object in the newTab variable. Then, we use waitForEvent("download") to wait for the download to complete. Once the download event is triggered, we obtain the suggested filename using download.suggestedFilename(). Finally, we save the downloaded file using download.saveAs(path)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the provided code snippets, you should now be able to download files successfully using Playwright in your Typescript projects. This approach ensures you handle the download process effectively, even when dealing with new tabs and asynchronous events.&lt;/p&gt;

&lt;p&gt;Feel free to try this solution in your projects and let me know how it works for you. Happy coding!&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>playwrightautomation</category>
      <category>playwrightdownloadfile</category>
    </item>
  </channel>
</rss>
