<?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: Santosh Kulkarni</title>
    <description>The latest articles on Forem by Santosh Kulkarni (@santosh_kulkarni_ffbde129).</description>
    <link>https://forem.com/santosh_kulkarni_ffbde129</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%2F1744872%2F09a036f6-12ec-40e2-ba56-3d143a0d0993.png</url>
      <title>Forem: Santosh Kulkarni</title>
      <link>https://forem.com/santosh_kulkarni_ffbde129</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/santosh_kulkarni_ffbde129"/>
    <language>en</language>
    <item>
      <title>how to use playwright for Electron application. how to interact with pages in the application</title>
      <dc:creator>Santosh Kulkarni</dc:creator>
      <pubDate>Mon, 04 Nov 2024 08:33:31 +0000</pubDate>
      <link>https://forem.com/santosh_kulkarni_ffbde129/how-to-use-playwright-for-electron-application-how-to-interact-with-pages-in-the-application-50fm</link>
      <guid>https://forem.com/santosh_kulkarni_ffbde129/how-to-use-playwright-for-electron-application-how-to-interact-with-pages-in-the-application-50fm</guid>
      <description></description>
    </item>
    <item>
      <title>Automation using Playwright and TypeScript and JavaScript</title>
      <dc:creator>Santosh Kulkarni</dc:creator>
      <pubDate>Wed, 23 Oct 2024 11:14:00 +0000</pubDate>
      <link>https://forem.com/santosh_kulkarni_ffbde129/automation-using-playwright-and-typescript-and-javascript-493l</link>
      <guid>https://forem.com/santosh_kulkarni_ffbde129/automation-using-playwright-and-typescript-and-javascript-493l</guid>
      <description>&lt;p&gt;Playwright With TypeScript | JavaScript Installation&lt;/p&gt;

&lt;p&gt;Playwright is the modern web based and API Automation tool from Microsoft by collaborating with Puppeteer team, Puppeteer is a JavaScript library which provides a high-level API to control Chrome or Firefox over the DevTools Protocol or WebDriver BiDi. Puppeteer runs in the headless (no visible UI) by default.&lt;/p&gt;

&lt;p&gt;Playwright supports the modern web based browsers for automation of web application though single API and also supports the automation for API.&lt;/p&gt;

&lt;p&gt;Architecture of Playwright&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%2Fhu7sz4pyjvj3kfqtt8o0.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%2Fhu7sz4pyjvj3kfqtt8o0.png" alt="Image description" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Playwright works on Web Socket Protocol once connection is established will triggers the tests and sends the request in the JSON format to server using Web Socket Protocol which means once connection established by Playwright no need to establish the connection again for sending the requests to server until the complete test execution. Playwright has to disconnect the connection by playwright.quit() method.&lt;/p&gt;

&lt;p&gt;Lets us understand the difference between HTTP Protocol Connection Web Socket Protocol 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93wxambzmxw7l7l8rq3d.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%2F93wxambzmxw7l7l8rq3d.png" alt="Image description" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Difference between WebSocket &amp;amp; HTTP Protocol&lt;br&gt;
Features of Playwright :&lt;br&gt;
Any browser • Any platform • One API&lt;br&gt;
Cross-browser. Playwright supports all modern rendering engines including Chromium, WebKit, and Firefox.&lt;/p&gt;

&lt;p&gt;Cross-platform. Test on Windows, Linux, and macOS, locally or on CI, headless or headed.&lt;/p&gt;

&lt;p&gt;Cross-language. Use the Playwright API in TypeScript, JavaScript, Python, .NET, Java.&lt;/p&gt;

&lt;p&gt;Test Mobile Web. Native mobile emulation of Google Chrome for Android and Mobile Safari. The same rendering engine works on your Desktop and in the Cloud.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Resilient • No flaky tests&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Auto-wait. Playwright waits for elements to be actionable prior to performing actions. It also has a rich set of introspection events. The combination of the two eliminates the need for artificial timeouts — the primary cause of flaky tests.&lt;/p&gt;

&lt;p&gt;Web-first assertions. Playwright assertions are created specifically for the dynamic web. Checks are automatically retried until the necessary conditions are met.&lt;/p&gt;

&lt;p&gt;Tracing. Configure test retry strategy, capture execution trace, videos, screenshots to eliminate flakes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No trade-offs • No limits&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Browsers run web content belonging to different origins in different processes. Playwright is aligned with the modern browsers architecture and runs tests out-of-process. This makes Playwright free of the typical in-process test runner limitations.&lt;/p&gt;

&lt;p&gt;Multiple everything. Test scenarios that span multiple tabs, multiple origins and multiple users. Create scenarios with different contexts for different users and run them against your server, all in one test.&lt;/p&gt;

&lt;p&gt;Trusted events. Hover elements, interact with dynamic controls, produce trusted events. Playwright uses real browser input pipeline indistinguishable from the real user.&lt;/p&gt;

&lt;p&gt;Test frames, pierce Shadow DOM. Playwright selectors pierce shadow DOM and allow entering frames seamlessly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Full isolation • Fast execution&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Browser contexts. Playwright creates a browser context for each test. Browser context is equivalent to a brand new browser profile. This delivers full test isolation with zero overhead. Creating a new browser context only takes a handful of milliseconds.&lt;/p&gt;

&lt;p&gt;Log in once. Save the authentication state of the context and reuse it in all the tests. This bypasses repetitive log-in operations in each test, yet delivers full isolation of independent tests.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Powerful Tooling&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Codegen. Generate tests by recording your actions. Save them into any language.&lt;/p&gt;

&lt;p&gt;Playwright inspector. Inspect page, generate selectors, step through the test execution, see click points, explore execution logs.&lt;/p&gt;

&lt;p&gt;Trace Viewer. Capture all the information to investigate the test failure. Playwright trace contains test execution screencast, live DOM snapshots, action explorer, test source, and many more.&lt;/p&gt;

&lt;p&gt;Let us start using Playwright with TypeScript/JavaScript&lt;/p&gt;

&lt;p&gt;Installation of Playwright for TypeScript/JavaScript&lt;br&gt;
Pre-requisites for installation as follows : Node.js 18+&lt;/p&gt;

&lt;p&gt;Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).&lt;br&gt;
macOS 13 Ventura, or macOS 14 Sonoma.&lt;br&gt;
Debian 11, Debian 12, Ubuntu 20.04 or Ubuntu 22.04, Ubuntu 24.04, on x86–64 and arm64 architecture.&lt;br&gt;
Get started by installing Playwright using npm, yarn or pnpm. Alternatively you can also get started and run your tests using the VS Code Extension.&lt;/p&gt;

&lt;p&gt;Create the folder, for example TypeScriptWithPlaywright likewise create folder for JavaScriptwithPlaywright and navigate to folder and open the command prompt of the windows&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%2Fn8y0rnhe0m9p80cgxwjb.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%2Fn8y0rnhe0m9p80cgxwjb.png" alt="Image description" width="800" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Playwright Installation&lt;br&gt;
Click on the enter and following screen will appear and choose the Scripting language and then press the enter&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%2Fd4h6q4qwatyz4si20bnv.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%2Fd4h6q4qwatyz4si20bnv.png" alt="Image description" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the Scripting Language&lt;br&gt;
After selecting the scripting language and then press enter following screen will appear and will ask where you want to put your end to end tests. lets be it like that.&lt;/p&gt;

&lt;p&gt;Playwright Installation&lt;br&gt;
Now it will ask for GitHub Actions workflow. If you want to configure then Press Y or else N. It will ask you for to install browser, if you want to install then Select Y which means true. following screen will appear.&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%2Fzy8bul3w8k89kv7ffwc3.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%2Fzy8bul3w8k89kv7ffwc3.png" alt="Image description" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note : Playwright browsers can be installed by manually via below command&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%2Fcfwnofirbfa9l5pv5rcf.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%2Fcfwnofirbfa9l5pv5rcf.png" alt="Image description" width="800" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;npx playwright install&lt;/p&gt;

&lt;p&gt;Playwright Installation&lt;br&gt;
Now press enter and the following screens will appear.&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%2F3e84ryz4vgjx9oxar70k.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%2F3e84ryz4vgjx9oxar70k.png" alt="Image description" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Playwright Installation&lt;br&gt;
Playwright Installation&lt;/p&gt;

&lt;p&gt;Playwright Installation&lt;/p&gt;

&lt;p&gt;Playwright Installation Complete&lt;br&gt;
Playwright by default executes the test scripts which is executed in headless mode and following commands will explore to execute with specific browsers and debug, generating test scripts using codegen.&lt;/p&gt;

&lt;p&gt;npx playwright test&lt;br&gt;
    Runs the end-to-end tests.&lt;/p&gt;

&lt;p&gt;npx playwright test --ui&lt;br&gt;
    Starts the interactive UI mode.&lt;/p&gt;

&lt;p&gt;npx playwright test --project=chromium&lt;br&gt;
    Runs the tests only on Desktop Chrome.&lt;/p&gt;

&lt;p&gt;npx playwright test example&lt;br&gt;
    Runs the tests in a specific file.&lt;/p&gt;

&lt;p&gt;npx playwright test --debug&lt;br&gt;
    Runs the tests in debug mode.&lt;/p&gt;

&lt;p&gt;npx playwright codegen&lt;br&gt;
    Auto generate tests with Codegen.&lt;/p&gt;

&lt;p&gt;We suggest that you begin by typing:&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;Now lets execute the test scripts by using the following command and to view the report. Playwright will execute the tests in chromium, Firefox and WebKit Parallelly.&lt;/p&gt;

&lt;p&gt;npx playwright test&lt;/p&gt;

&lt;p&gt;npx playwright show-report&lt;/p&gt;

&lt;p&gt;Playwright by default report supports only TypeScript/JavaScript&lt;br&gt;
Playwright by default configure your test scripts to execute in the following browsers with headless mode. The configuration will present in the folder named as playwright.config.js&lt;/p&gt;

&lt;p&gt;import { defineConfig, devices } from '@playwright/test';&lt;/p&gt;

&lt;p&gt;/**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read environment variables from file.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/motdotla/dotenv" rel="noopener noreferrer"&gt;https://github.com/motdotla/dotenv&lt;/a&gt;
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;/**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;See &lt;a href="https://playwright.dev/docs/test-configuration" rel="noopener noreferrer"&gt;https://playwright.dev/docs/test-configuration&lt;/a&gt;.&lt;br&gt;
&lt;em&gt;/&lt;br&gt;
export default defineConfig({&lt;br&gt;
testDir: './tests',&lt;br&gt;
/&lt;/em&gt; Run tests in files in parallel &lt;em&gt;/&lt;br&gt;
fullyParallel: true,&lt;br&gt;
/&lt;/em&gt; Fail the build on CI if you accidentally left test.only in the source code. &lt;em&gt;/&lt;br&gt;
forbidOnly: !!process.env.CI,&lt;br&gt;
/&lt;/em&gt; Retry on CI only &lt;em&gt;/&lt;br&gt;
retries: process.env.CI ? 2 : 0,&lt;br&gt;
/&lt;/em&gt; Opt out of parallel tests on CI. &lt;em&gt;/&lt;br&gt;
workers: process.env.CI ? 1 : undefined,&lt;br&gt;
/&lt;/em&gt; Reporter to use. See &lt;a href="https://playwright.dev/docs/test-reporters" rel="noopener noreferrer"&gt;https://playwright.dev/docs/test-reporters&lt;/a&gt; &lt;em&gt;/&lt;br&gt;
reporter: 'html',&lt;br&gt;
/&lt;/em&gt; Shared settings for all the projects below. See &lt;a href="https://playwright.dev/docs/api/class-testoptions" rel="noopener noreferrer"&gt;https://playwright.dev/docs/api/class-testoptions&lt;/a&gt;. &lt;em&gt;/&lt;br&gt;
use: {&lt;br&gt;
/&lt;/em&gt; Base URL to use in actions like &lt;code&gt;await page.goto('/')&lt;/code&gt;. */&lt;br&gt;
// baseURL: '&lt;a href="http://127.0.0.1:3000" rel="noopener noreferrer"&gt;http://127.0.0.1:3000&lt;/a&gt;',&lt;/p&gt;

&lt;p&gt;/* Collect trace when retrying the failed test. See &lt;a href="https://playwright.dev/docs/trace-viewer" rel="noopener noreferrer"&gt;https://playwright.dev/docs/trace-viewer&lt;/a&gt; */&lt;br&gt;
trace: 'on-first-retry',&lt;br&gt;
},&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;/* Configure projects for major browsers */&lt;br&gt;
  projects: [&lt;br&gt;
    {&lt;br&gt;
      name: 'chromium',&lt;br&gt;
      use: { ...devices['Desktop Chrome'] },&lt;br&gt;
    },&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  name: 'firefox',
  use: { ...devices['Desktop Firefox'] },
},

{
  name: 'webkit',
  use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
//   name: 'Mobile Chrome',
//   use: { ...devices['Pixel 5'] },
// },
// {
//   name: 'Mobile Safari',
//   use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
//   name: 'Microsoft Edge',
//   use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
//   name: 'Google Chrome',
//   use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;],&lt;/p&gt;

&lt;p&gt;/* Run your local dev server before starting the tests */&lt;br&gt;
  // webServer: {&lt;br&gt;
  //   command: 'npm run start',&lt;br&gt;
  //   url: '&lt;a href="http://127.0.0.1:3000" rel="noopener noreferrer"&gt;http://127.0.0.1:3000&lt;/a&gt;',&lt;br&gt;
  //   reuseExistingServer: !process.env.CI,&lt;br&gt;
  // },&lt;br&gt;
});&lt;br&gt;
Now let us modify to execute the test scripts non headleases mode( UI) and with adding additional browsers. Playwright also provides the options for to record the test script execution and trace view options which will be useful for debugging. If you enable the trace viewer option can able to see what is the status before test, what is the status during test and what would be status after test. I have modified the playwright config file and it is as below :&lt;/p&gt;

&lt;p&gt;// @ts-check&lt;br&gt;
const { defineConfig, devices } = require('@playwright/test');&lt;/p&gt;

&lt;p&gt;module.exports = defineConfig({&lt;br&gt;
  testDir: './tests',&lt;br&gt;
  fullyParallel: true,&lt;br&gt;
  forbidOnly: !!process.env.CI,&lt;br&gt;
  retries: process.env.CI ? 2 : 0,&lt;br&gt;
  workers: process.env.CI ? 1 : undefined,&lt;br&gt;
  reporter: 'html',&lt;br&gt;
  use: {&lt;br&gt;
    trace: 'on', // Enable tracing&lt;br&gt;
    video: 'on', // Record video for each test&lt;br&gt;
    headless: false, // Run tests in headed mode&lt;br&gt;
  },&lt;br&gt;
  projects: [&lt;br&gt;
    {&lt;br&gt;
      name: 'chromium',&lt;br&gt;
      use: { ...devices['Desktop Chrome'] },&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      name: 'firefox',&lt;br&gt;
      use: { ...devices['Desktop Firefox'] },&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      name: 'webkit',&lt;br&gt;
      use: { ...devices['Desktop Safari'] },&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      name: 'Microsoft Edge',&lt;br&gt;
      use: {&lt;br&gt;
        ...devices['Desktop Edge'],&lt;br&gt;
        channel: 'msedge'&lt;br&gt;
      },&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      name: 'Google Chrome',&lt;br&gt;
      use: {&lt;br&gt;
        ...devices['Desktop Chrome'],&lt;br&gt;
        channel: 'chrome'&lt;br&gt;
      },&lt;br&gt;
    },&lt;br&gt;
  ],&lt;br&gt;
});&lt;br&gt;
Now test scripts can execute the tests on the browsers mentioned in the config file in non headless mode with recording, trace viewer option.&lt;/p&gt;

&lt;p&gt;Happy Learning !! Happy Automation !! Happy Testing&lt;/p&gt;

&lt;p&gt;Feel free to connect me any information/Questions on &lt;a href="mailto:santoshvqa@gmail.com"&gt;santoshvqa@gmail.com&lt;/a&gt; &amp;amp; LinkedIn Profile&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/santosh-kulkarni-ab571639/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/santosh-kulkarni-ab571639/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>automaton</category>
      <category>playwright</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
