{"id":3334,"date":"2025-01-16T05:22:54","date_gmt":"2025-01-16T05:22:54","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/16\/trace-viewer-tool-and-recording-using-inspector-in-playwright-java\/"},"modified":"2025-01-16T05:22:54","modified_gmt":"2025-01-16T05:22:54","slug":"trace-viewer-tool-and-recording-using-inspector-in-playwright-java","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/16\/trace-viewer-tool-and-recording-using-inspector-in-playwright-java\/","title":{"rendered":"\u2018Trace Viewer\u2019 tool and \u2018Recording\u2019 using Inspector in Playwright-Java"},"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=\"3334\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><em>In this blog we are going to see the &#8216;Trace Viewer&#8217; feature in Playwright-Java. Using this tool users we can capture before\/after screenshots. We will also see the usage of playwright inspector to effectively record actions.<\/em><em>\u00a0<\/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>Recording actions using Playwright-Java<\/li>\n<li>Viewing the trace (recorded actions)<\/li>\n<li>Source code<\/li>\n<\/ul>\n<p><strong>Recording actions using Playwright-Java<\/strong><\/p>\n<p>Trace Viewer is a graphical user interface (GUI) tool that allows user to analyze recorded Playwright traces of their tests. Using this tool, we can navigate through each action of our test, both backward and forward, and gain a visual understanding of the events that occurred during each action.<\/p>\n<p>We will learn how to record a Trace by utilizing playwright inspector to capture the details of a simple form.<\/p>\n<p>Let us execute a simple script to launch playwright inspector. Line#20 is responsible for launching the inspector<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d91dbaf\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3337\" data-css=\"tve-u-1946d91eacf\" data-height=\"309\" data-id=\"3337\" data-init-height=\"646\" data-init-width=\"1168\" data-width=\"558\" decoding=\"async\" height=\"309\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-10.54.02\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 646;\" title=\"Screenshot 2025-01-16 at 10.54.02\u202fAM\" width=\"558\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0The inspector launches when we execute the script\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d9270d0\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3338\" data-css=\"tve-u-1946d928478\" data-height=\"467\" data-id=\"3338\" data-init-height=\"1054\" data-init-width=\"1168\" data-width=\"518\" decoding=\"async\" height=\"467\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-10.54.45\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 1054;\" title=\"Screenshot 2025-01-16 at 10.54.45\u202fAM\" width=\"518\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Enter some text in name, email and password fields<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d931307\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3339\" data-css=\"tve-u-1946d93244f\" data-height=\"265\" data-id=\"3339\" data-init-height=\"610\" data-init-width=\"1168\" data-width=\"508\" decoding=\"async\" height=\"265\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-10.55.30\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 610;\" title=\"Screenshot 2025-01-16 at 10.55.30\u202fAM\" width=\"508\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Stop recording by clicking \u2018Record\u2019 button.<\/p>\n<p>Notice below that the script gets automatically recorded inside playwright inspector<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d938a5e\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3340\" data-css=\"tve-u-1946d939dd6\" data-height=\"311\" data-id=\"3340\" data-init-height=\"682\" data-init-width=\"1168\" data-width=\"533\" decoding=\"async\" height=\"311\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-10.56.02\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 682;\" title=\"Screenshot 2025-01-16 at 10.56.02\u202fAM\" width=\"533\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0From the inspector, copy line numbers from 12-18\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d94239d\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3341\" data-css=\"tve-u-1946d9439b6\" data-height=\"414\" data-id=\"3341\" data-init-height=\"894\" data-init-width=\"1168\" data-width=\"541\" decoding=\"async\" height=\"414\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-10.56.38\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 894;\" title=\"Screenshot 2025-01-16 at 10.56.38\u202fAM\" width=\"541\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Comment page.pause()<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d959f87\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3342\" data-css=\"tve-u-1946d95d7a1\" data-height=\"304\" data-id=\"3342\" data-init-height=\"664\" data-init-width=\"1168\" data-width=\"535\" decoding=\"async\" height=\"304\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-10.57.59\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 664;\" title=\"Screenshot 2025-01-16 at 10.57.59\u202fAM\" width=\"535\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Paste it as shown below<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d980b68\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3343\" data-css=\"tve-u-1946d983361\" data-height=\"265\" data-id=\"3343\" data-init-height=\"522\" data-init-width=\"1168\" data-width=\"593\" decoding=\"async\" height=\"265\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.00.09\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 522;\" title=\"Screenshot 2025-01-16 at 11.00.09\u202fAM\" width=\"593\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0For stoping trace recording, copy the below code<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d9963ff\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3344\" data-css=\"tve-u-1946d998f7a\" data-height=\"272\" data-id=\"3344\" data-init-height=\"540\" data-init-width=\"1168\" data-width=\"589\" decoding=\"async\" height=\"272\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.02.09\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 540;\" title=\"Screenshot 2025-01-16 at 11.02.09\u202fAM\" width=\"589\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0\u2018trace.zip file (mentioned in line#40) gete auto-generated after the script execution.<\/p>\n<p>Below, you can find the code that has been written up until now<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d9adeab\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3345\" data-css=\"tve-u-1946d9b023a\" data-height=\"446\" data-id=\"3345\" data-init-height=\"882\" data-init-width=\"1168\" data-width=\"591\" decoding=\"async\" height=\"446\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.03.51\u202fAM.png\" style=\"aspect-ratio: auto 1168 \/ 882;\" title=\"Screenshot 2025-01-16 at 11.03.51\u202fAM\" width=\"591\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Execute.\u00a0<\/p>\n<p>Notice below that the 3 fields are populated<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d9ca12c\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3346\" data-css=\"tve-u-1946d9cca2d\" data-height=\"593\" data-id=\"3346\" data-init-height=\"762\" data-init-width=\"648\" data-width=\"504\" decoding=\"async\" height=\"593\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.05.45\u202fAM.png\" style=\"aspect-ratio: auto 648 \/ 762;\" title=\"Screenshot 2025-01-16 at 11.05.45\u202fAM\" width=\"504\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0<strong>Viewing the trace (recorded actions)<\/strong><\/p>\n<p>Refresh playwright project to view \u2018trace.zip\u2019 file\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d9e2b1f\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3347\" data-css=\"tve-u-1946d9e5b1d\" data-height=\"613\" data-id=\"3347\" data-init-height=\"1230\" data-init-width=\"1160\" data-width=\"578\" decoding=\"async\" height=\"613\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.07.02\u202fAM.png\" style=\"aspect-ratio: auto 1160 \/ 1230;\" title=\"Screenshot 2025-01-16 at 11.07.02\u202fAM\" width=\"578\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Go to <a class=\"\" href=\"https:\/\/trace.playwright.dev\/\" rel=\"noopener\" style=\"outline: none;\" target=\"_blank\">https:\/\/trace.playwright.dev\/<\/a>\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946d9ff368\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3348\" data-css=\"tve-u-1946da00352\" data-height=\"172\" data-id=\"3348\" data-init-height=\"380\" data-init-width=\"1160\" data-width=\"526\" decoding=\"async\" height=\"172\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.09.13\u202fAM.png\" style=\"aspect-ratio: auto 1160 \/ 380;\" title=\"Screenshot 2025-01-16 at 11.09.13\u202fAM\" width=\"526\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Click \u2018Select file\u2019, select trace.zip file and open the same<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946da07212\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3349\" data-css=\"tve-u-1946da081e7\" data-height=\"290\" data-id=\"3349\" data-init-height=\"618\" data-init-width=\"1160\" data-width=\"545\" decoding=\"async\" height=\"290\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.10.07\u202fAM.png\" style=\"aspect-ratio: auto 1160 \/ 618;\" title=\"Screenshot 2025-01-16 at 11.10.07\u202fAM\" width=\"545\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Notice above. Movie-like traces can be observed at various moments. On the left side, we can also observe the &#8216;Actions&#8217; section along with Before\/After screenshots.<\/p>\n<p>Select navgate action as shown below. Also select \u2018Before\u2019. As expected a blank screen would be shown since the navigate action is not yet complete\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946da11cf7\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3350\" data-css=\"tve-u-1946da133f5\" data-height=\"698\" data-id=\"3350\" data-init-height=\"1700\" data-init-width=\"1160\" data-width=\"476\" decoding=\"async\" height=\"698\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.10.44\u202fAM.png\" style=\"aspect-ratio: auto 1160 \/ 1700;\" title=\"Screenshot 2025-01-16 at 11.10.44\u202fAM\" width=\"476\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Similarly, below shows the \u2018Email\u2019 field<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946da1bbf2\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3351\" data-css=\"tve-u-1946da1d18c\" data-height=\"617\" data-id=\"3351\" data-init-height=\"1360\" data-init-width=\"1160\" data-width=\"526\" decoding=\"async\" height=\"617\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.11.29\u202fAM.png\" style=\"aspect-ratio: auto 1160 \/ 1360;\" title=\"Screenshot 2025-01-16 at 11.11.29\u202fAM\" width=\"526\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0The \u2018Metadata\u2019 can also be seen<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946da24658\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3352\" data-css=\"tve-u-1946da25eaf\" data-height=\"303\" data-id=\"3352\" data-init-height=\"694\" data-init-width=\"1160\" data-width=\"507\" decoding=\"async\" height=\"303\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-16-at-11.12.03\u202fAM.png\" style=\"aspect-ratio: auto 1160 \/ 694;\" title=\"Screenshot 2025-01-16 at 11.12.03\u202fAM\" width=\"507\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0So this is how we can make use of trace viewer in addition to the recording feature of playwright inspector.<\/p>\n<p><strong>Source code<\/strong><\/p>\n<p><strong>package<\/strong> com.rsa.playwrightjava;<\/p>\n<p><\/p>\n<p><strong>import<\/strong> java.nio.file.Paths;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Browser;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserContext;<\/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> com.microsoft.playwright.Tracing;<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog19_RecordTrace {<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/p>\n<p>Playwright pw = Playwright.<em>create<\/em>();<\/p>\n<p>Browser browser = pw.chromium().launch(<strong>new<\/strong> BrowserType<\/p>\n<p>.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/p>\n<p><\/p>\n<p>BrowserContext browserContext = browser.newContext();<\/p>\n<p>\/\/Recording the trace<\/p>\n<p>browserContext.tracing().start(<strong>new<\/strong> Tracing.StartOptions()<\/p>\n<p>\u00a0 .setScreenshots(<strong>true<\/strong>)<\/p>\n<p>\u00a0 .setSnapshots(<strong>true<\/strong>));<\/p>\n<p>Page page = browserContext.newPage();<\/p>\n<p>page.navigate(&#8220;https:\/\/rahulshettyacademy.com\/angularpractice\/&#8221;);<\/p>\n<p>page.locator(&#8220;form input[name=&#8221;name&#8221;]&#8221;).click();<\/p>\n<p>\u00a0 \u00a0 \u00a0 page.locator(&#8220;form input[name=&#8221;name&#8221;]&#8221;).fill(&#8220;Rahul Shetty Academy&#8221;);<\/p>\n<p>\u00a0 \u00a0 \u00a0 page.locator(&#8220;input[name=&#8221;email&#8221;]&#8221;).click();<\/p>\n<p>\u00a0 \u00a0 \u00a0 page.locator(&#8220;input[name=&#8221;email&#8221;]&#8221;).fill(&#8220;rahulshettyacademy.com&#8221;);<\/p>\n<p>\u00a0 \u00a0 \u00a0 page.getByPlaceholder(&#8220;Password&#8221;).click();<\/p>\n<p>\u00a0 \u00a0 \u00a0 page.getByPlaceholder(&#8220;Password&#8221;).fill(&#8220;rahulshetty&#8221;);<\/p>\n<p>\u00a0 \u00a0 \u00a0 page.getByText(&#8220;Name Email Password Check me&#8221;).click();<\/p>\n<p>\/\/page.pause();<\/p>\n<p>\u00a0 \u00a0 \u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0 \/\/For closing trace<\/p>\n<p>\u00a0 \u00a0 \u00a0 browserContext.tracing().stop(<strong>new<\/strong> Tracing.StopOptions()<\/p>\n<p>\u00a0 .setPath(Paths.<em>get<\/em>(&#8220;trace.zip&#8221;)));<\/p>\n<p><\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p><\/p>\n<p>Thanks.<\/p>\n<p>\u00a0<\/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 are going to see the &#8216;Trace Viewer&#8217; feature in Playwright-Java. Using this tool users we can capture before\/after screenshots. We will also see the usage of playwright inspector to effectively record actions.\u00a0 Topics that we will cover: Recording actions using Playwright-Java Viewing the trace (recorded actions) Source code Recording actions using [&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-3334","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\/3334","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=3334"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3334\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}