{"id":3068,"date":"2025-01-14T14:40:37","date_gmt":"2025-01-14T14:40:37","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/?p=3068"},"modified":"2025-01-17T10:29:04","modified_gmt":"2025-01-17T10:29:04","slug":"playwright-javas-record-capability","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/14\/playwright-javas-record-capability\/","title":{"rendered":"Playwright-Java&#8217;s &#8216;Record&#8217; capability\u00a0"},"content":{"rendered":"<p><em>In this blog, we will learn about Playwright-Java&#8217;s &#8216;Record&#8217; capability that enables users to create scripts by recording their actions on a web page, making it a convenient tool for test automation.<\/em><\/p>\n<p><strong>Topics that we will cover:<\/strong><\/p>\n<ul>\n<li>\u2018Record\u2019 capability in Playwright-Java<\/li>\n<li>Source code (before Record operation)<\/li>\n<li>Source code (after Record operation)<\/li>\n<\/ul>\n<p><strong>\u2018Record\u2019 capability in Playwright-Java&nbsp;<\/strong><\/p>\n<p>In order to utilize the &#8216;Record&#8217; feature in playwright inspector, we can create a basic test and incorporate the page.pause() method as demonstrated below. This will enable us to pause the execution at specific points during the test<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3071\" width=\"619\" data-init-width=\"1208\" height=\"295\" data-init-height=\"576\" title=\"Screenshot 2025-01-14 at 8.12.02\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.12.02\u202fPM.png\" data-width=\"619\" data-height=\"295\" style=\"aspect-ratio: auto 1208 \/ 576;\"><\/span><\/p>\n<p>&nbsp;Execute the script.<\/p>\n<p>The webpage is launched simultaneously with the inspector, which includes a &#8216;Record&#8217; button, see below&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3072\" width=\"544\" data-init-width=\"1208\" height=\"259\" data-init-height=\"576\" title=\"Screenshot 2025-01-14 at 8.12.49\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.12.49\u202fPM.png\" data-width=\"544\" data-height=\"259\" style=\"aspect-ratio: auto 1208 \/ 576;\"><\/span><\/p>\n<p>On the webpage you can see username and password fields.<\/p>\n<p>Let us click \u2018Record\u2019 to start recording. Notice below that \u2018Record\u2019 menu comes up<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3073\" width=\"543\" data-init-width=\"1208\" height=\"649\" data-init-height=\"1444\" title=\"Screenshot 2025-01-14 at 8.13.40\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.13.40\u202fPM.png\" data-width=\"543\" data-height=\"649\" style=\"aspect-ratio: auto 1208 \/ 1444;\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"3074\" width=\"529\" data-init-width=\"1208\" height=\"529\" data-init-height=\"1208\" title=\"Screenshot 2025-01-14 at 8.15.23\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.15.23\u202fPM.png\" data-width=\"529\" data-height=\"529\" style=\"aspect-ratio: auto 1208 \/ 1208;\"><\/span><\/p>\n<p>The actions are automatically recorded in the inspector, as shown below<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3075\" width=\"526\" data-init-width=\"1208\" height=\"309\" data-init-height=\"710\" title=\"Screenshot 2025-01-14 at 8.17.06\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.17.06\u202fPM.png\" data-width=\"526\" data-height=\"309\" style=\"aspect-ratio: auto 1208 \/ 710;\"><\/span><\/p>\n<p>Let us copy line#3 and lines#12-16 and paste them in notepad<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3076\" width=\"614\" data-init-width=\"1208\" height=\"342\" data-init-height=\"672\" title=\"Screenshot 2025-01-14 at 8.18.55\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.18.55\u202fPM.png\" data-width=\"614\" data-height=\"342\" style=\"aspect-ratio: auto 1208 \/ 672;\"><\/span><\/p>\n<p>&nbsp;Let us close the playwright inspector window.<\/p>\n<p>Insert the recorded code snippet into our test, at line 7 and lines 19 to 23<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3077\" width=\"588\" data-init-width=\"1208\" height=\"327\" data-init-height=\"672\" title=\"Screenshot 2025-01-14 at 8.19.45\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.19.45\u202fPM.png\" data-width=\"588\" data-height=\"327\" style=\"aspect-ratio: auto 1208 \/ 672;\"><\/span><\/p>\n<p>&nbsp;It is important to have the pause() command positioned at the end of line 25 (see above).<\/p>\n<p>Execute the code.<\/p>\n<p>Below, you can see the script being replayed and the subsequent entry of the username and password<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3078\" width=\"595\" data-init-width=\"1208\" height=\"844\" data-init-height=\"1714\" title=\"Screenshot 2025-01-14 at 8.20.54\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.20.54\u202fPM.png\" data-width=\"595\" data-height=\"844\" style=\"aspect-ratio: auto 1208 \/ 1714;\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"3079\" width=\"558\" data-init-width=\"1208\" height=\"381\" data-init-height=\"824\" title=\"Screenshot 2025-01-14 at 8.21.58\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.21.58\u202fPM.png\" data-width=\"558\" data-height=\"381\" style=\"aspect-ratio: auto 1208 \/ 824;\"><\/span><\/p>\n<p>So, recording actions in playwright is made simple with this approach.<\/p>\n<p><strong>Source code (before Record operation)<\/strong><\/p>\n<p><strong>package<\/strong> com.rsa.playwrightjava;<\/p>\n<\/p>\n<p><strong>import<\/strong> org.junit.jupiter.api.Test;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Page;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/p>\n<\/p>\n<p><strong>public<\/strong><strong>class<\/strong> Blog5_Record {<\/p>\n<p>@Test<\/p>\n<p><strong>public<\/strong><strong>void<\/strong> PlaywrightJTest() {<\/p>\n<p>Playwright pt = Playwright.<em>create<\/em>();<\/p>\n<p>Page pg1 = pt.chromium().launch(<strong>new<\/strong> BrowserType.<\/p>\n<p>LaunchOptions().<\/p>\n<p>setHeadless(<strong>false<\/strong>)).<\/p>\n<p>newPage();<\/p>\n<p>pg1.navigate(&#8220;https:\/\/www.facebook.com\/&#8221;);<\/p>\n<p>pg1.pause();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p><strong>Source code (after Record operation)<\/strong><\/p>\n<p><strong>package<\/strong> com.rsa.playwrightjava;<\/p>\n<\/p>\n<p><strong>import<\/strong> org.junit.jupiter.api.Test;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Page;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/p>\n<p><strong>import<\/strong><strong>static<\/strong> com.microsoft.playwright.assertions.PlaywrightAssertions.<em>assertThat<\/em>;<\/p>\n<\/p>\n<p><strong>public<\/strong><strong>class<\/strong> Blog5_Record {<\/p>\n<p>@Test<\/p>\n<p><strong>public<\/strong><strong>void<\/strong> PlaywrightJTest() {<\/p>\n<p>Playwright pt = Playwright.<em>create<\/em>();<\/p>\n<p>Page pg1 = pt.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>)).<\/p>\n<p>newPage();<\/p>\n<p>pg1.navigate(&#8220;https:\/\/www.facebook.com\/&#8221;);<\/p>\n<p>pg1.getByTestId(&#8220;royal_email&#8221;).click();<\/p>\n<p>pg1.getByTestId(&#8220;royal_email&#8221;).fill(&#8220;playwrightjava@gmail.com&#8221;);<\/p>\n<p>pg1.getByTestId(&#8220;royal_pass&#8221;).click();<\/p>\n<p>pg1.getByTestId(&#8220;royal_pass&#8221;).fill(&#8220;playwright&#8221;);<\/p>\n<p>pg1.getByTestId(&#8220;royal_login_button&#8221;).click();<\/p>\n<p>pg1.pause();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<\/p>\n<p>Thanks.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will learn about Playwright-Java&#8217;s &#8216;Record&#8217; capability that enables users to create scripts by recording their actions on a web page, making it a convenient tool for test automation. Topics that we will cover: \u2018Record\u2019 capability in Playwright-Java Source code (before Record operation) Source code (after Record operation) \u2018Record\u2019 capability in Playwright-Java&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":750,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"class_list":["post-3068","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-playwright","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3068"}],"version-history":[{"count":6,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3068\/revisions"}],"predecessor-version":[{"id":3695,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3068\/revisions\/3695"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/750"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}