{"id":3068,"date":"2025-01-14T14:40:37","date_gmt":"2025-01-14T14:40:37","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/14\/playwright-javas-record-capability\/"},"modified":"2025-01-14T14:40:37","modified_gmt":"2025-01-14T14:40:37","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"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"3068\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<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<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\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\u00a0<\/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<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194654527ff\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3071\" data-css=\"tve-u-19465454167\" data-height=\"295\" data-id=\"3071\" data-init-height=\"576\" data-init-width=\"1208\" data-width=\"619\" decoding=\"async\" height=\"295\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.12.02\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 576;\" title=\"Screenshot 2025-01-14 at 8.12.02\u202fPM\" width=\"619\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Execute the script.<\/p>\n<p>The webpage is launched simultaneously with the inspector, which includes a &#8216;Record&#8217; button, see below\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946545e18d\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3072\" data-css=\"tve-u-1946546022b\" data-height=\"259\" data-id=\"3072\" data-init-height=\"576\" data-init-width=\"1208\" data-width=\"544\" decoding=\"async\" height=\"259\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.12.49\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 576;\" title=\"Screenshot 2025-01-14 at 8.12.49\u202fPM\" width=\"544\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\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<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946546a961\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3073\" data-css=\"tve-u-1946546c677\" data-height=\"649\" data-id=\"3073\" data-init-height=\"1444\" data-init-width=\"1208\" data-width=\"543\" decoding=\"async\" height=\"649\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.13.40\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1444;\" title=\"Screenshot 2025-01-14 at 8.13.40\u202fPM\" width=\"543\"\/><\/span><\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19465483b8e\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3074\" data-css=\"tve-u-19465487a82\" data-height=\"529\" data-id=\"3074\" data-init-height=\"1208\" data-init-width=\"1208\" data-width=\"529\" decoding=\"async\" height=\"529\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.15.23\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1208;\" title=\"Screenshot 2025-01-14 at 8.15.23\u202fPM\" width=\"529\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>The actions are automatically recorded in the inspector, as shown below<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946549b589\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3075 tcb-moved-image\" data-css=\"tve-u-1946549c7c8\" data-height=\"309\" data-id=\"3075\" data-init-height=\"710\" data-init-width=\"1208\" data-width=\"526\" decoding=\"async\" height=\"309\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.17.06\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 710;\" title=\"Screenshot 2025-01-14 at 8.17.06\u202fPM\" width=\"526\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Let us copy line#3 and lines#12-16 and paste them in notepad<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194654b5a88\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3076\" data-css=\"tve-u-194654b746c\" data-height=\"342\" data-id=\"3076\" data-init-height=\"672\" data-init-width=\"1208\" data-width=\"614\" decoding=\"async\" height=\"342\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.18.55\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 672;\" title=\"Screenshot 2025-01-14 at 8.18.55\u202fPM\" width=\"614\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Let 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<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194654c367b\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3077\" data-css=\"tve-u-194654c4d9d\" data-height=\"327\" data-id=\"3077\" data-init-height=\"672\" data-init-width=\"1208\" data-width=\"588\" decoding=\"async\" height=\"327\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.19.45\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 672;\" title=\"Screenshot 2025-01-14 at 8.19.45\u202fPM\" width=\"588\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0It 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<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194654d342c\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3078\" data-css=\"tve-u-194654d54d6\" data-height=\"844\" data-id=\"3078\" data-init-height=\"1714\" data-init-width=\"1208\" data-width=\"595\" decoding=\"async\" height=\"844\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.20.54\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1714;\" title=\"Screenshot 2025-01-14 at 8.20.54\u202fPM\" width=\"595\"\/><\/span><\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194654e2cfb\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3079\" data-css=\"tve-u-194654e44e5\" data-height=\"381\" data-id=\"3079\" data-init-height=\"824\" data-init-width=\"1208\" data-width=\"558\" decoding=\"async\" height=\"381\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-8.21.58\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 824;\" title=\"Screenshot 2025-01-14 at 8.21.58\u202fPM\" width=\"558\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\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><\/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><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog5_Record {<\/p>\n<p>@Test<\/p>\n<p><strong>public<\/strong><br \/>\n<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><\/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><br \/>\n<strong>static<\/strong> com.microsoft.playwright.assertions.PlaywrightAssertions.<em>assertThat<\/em>;<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog5_Record {<\/p>\n<p>@Test<\/p>\n<p><strong>public<\/strong><br \/>\n<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><\/p>\n<p>Thanks.<\/p>\n<p><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<\/section>\n<p><\/body><\/html><\/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\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-3068","post","type-post","status-publish","format-standard","hentry","category-java","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":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3068\/revisions"}],"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}]}}