{"id":3054,"date":"2025-01-14T14:11:11","date_gmt":"2025-01-14T14:11:11","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/?p=3054"},"modified":"2025-01-17T10:27:38","modified_gmt":"2025-01-17T10:27:38","slug":"inspector-feature-and-initiate-the-opening-of-numerous-browser-tabs-with-playwright-java","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/14\/inspector-feature-and-initiate-the-opening-of-numerous-browser-tabs-with-playwright-java\/","title":{"rendered":"Inspector feature and initiate the opening of numerous browser tabs with Playwright-Java"},"content":{"rendered":"<p><em>In this blog, we will explore the utilization of the &#8216;Pause&#8217; feature and the Playwright Inspector. Additionally, we will look into the concept of managing multiple browser pages or tabs using a single browser instance.<\/em><\/p>\n<p><strong>Topics that we will cover:<\/strong><\/p>\n<ul>\n<li>\u2018Pause\u2019 feature alongwith Playwright Inspector<\/li>\n<li>Utilizing a single instance of a browser to open and manage multiple browser pages\/tabs<\/li>\n<li>Source code<\/li>\n<\/ul>\n<p><strong>\u2018Pause\u2019 feature alongwith Playwright Inspector&nbsp;<\/strong><\/p>\n<p>There are instances when we may feel the need to temporarily suspend (pause) our test in order to either debug or wait for a particular event to take place.&nbsp;<\/p>\n<p>The <em>.pause()<\/em> method is useful in this situation, please refer to the method description provided below&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3057\" width=\"637\" data-init-width=\"1208\" height=\"748\" data-init-height=\"1418\" title=\"Screenshot 2025-01-14 at 7.44.22\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.44.22\u202fPM.png\" data-width=\"637\" data-height=\"748\" style=\"aspect-ratio: auto 1208 \/ 1418;\"><\/span><\/p>\n<p>&nbsp;Upon execution of the script, observe below that the &#8216;Playwright Inspector&#8217; opens, causing the script to pause and the browser no longer closes automatically as it did before<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3058\" width=\"532\" data-init-width=\"1208\" height=\"318\" data-init-height=\"722\" title=\"Screenshot 2025-01-14 at 7.49.03\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.49.03\u202fPM.png\" data-width=\"532\" data-height=\"318\" style=\"aspect-ratio: auto 1208 \/ 722;\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"3059\" width=\"493\" data-init-width=\"1208\" height=\"277\" data-init-height=\"678\" title=\"Screenshot 2025-01-14 at 7.50.24\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.50.24\u202fPM.png\" data-width=\"493\" data-height=\"277\" style=\"aspect-ratio: auto 1208 \/ 678;\"><\/span><\/p>\n<p><strong>Utilizing a single instance of a browser to open and manage multiple browser pages\/tabs<\/strong><\/p>\n<p>Multiple browser pages can be launched using a single browser instance. Let&#8217;s explore the process.&nbsp;<\/p>\n<p>By utilizing the &#8216;<em>newContext()<\/em>&#8216; method as illustrated below, it is possible to generate a brand new browser context.<\/p>\n<p>The browser context, as mentioned in the description, does not share its cache with other browser contexts&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3060\" width=\"457\" data-init-width=\"1208\" height=\"426\" data-init-height=\"1126\" title=\"Screenshot 2025-01-14 at 7.52.18\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.52.18\u202fPM.png\" data-width=\"457\" data-height=\"426\" style=\"aspect-ratio: auto 1208 \/ 1126;\"><\/span><\/p>\n<p>Based on this context, we have the ability to construct a brand new browse page.<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3061\" width=\"421\" data-init-width=\"1208\" height=\"502\" data-init-height=\"1440\" title=\"Screenshot 2025-01-14 at 7.53.43\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.53.43\u202fPM.png\" data-width=\"421\" data-height=\"502\" style=\"aspect-ratio: auto 1208 \/ 1440;\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"3062\" width=\"604\" data-init-width=\"1208\" height=\"73\" data-init-height=\"146\" title=\"Screenshot 2025-01-14 at 7.54.42\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.54.42\u202fPM.png\" data-width=\"604\" data-height=\"73\" style=\"aspect-ratio: auto 1208 \/ 146;\"><\/span><\/p>\n<p>In a similar manner, we can generate two additional pages using the same browser context<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3063\" width=\"557\" data-init-width=\"1208\" height=\"446\" data-init-height=\"968\" title=\"Screenshot 2025-01-14 at 7.55.33\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.55.33\u202fPM.png\" data-width=\"557\" data-height=\"446\" style=\"aspect-ratio: auto 1208 \/ 968;\"><\/span><\/p>\n<p>&nbsp;Execute the code.<\/p>\n<p>Observe that there are three open tabs below<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3064\" width=\"474\" data-init-width=\"1208\" height=\"550\" data-init-height=\"1402\" title=\"Screenshot 2025-01-14 at 7.56.32\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.56.32\u202fPM.png\" data-width=\"474\" data-height=\"550\" style=\"aspect-ratio: auto 1208 \/ 1402;\"><\/span><\/p>\n<p>&nbsp;Execute.<\/p>\n<p>Notice that 4 window tabs open this time<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"3065\" width=\"580\" data-init-width=\"1208\" height=\"420\" data-init-height=\"874\" title=\"Screenshot 2025-01-14 at 7.57.43\u202fPM\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.57.43\u202fPM.png\" data-width=\"580\" data-height=\"420\" style=\"aspect-ratio: auto 1208 \/ 874;\"><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>So this is how we work with \u2018pause\u2019, inspector and multiple browser pages.<\/p>\n<p><strong>Source code (pause method)<\/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.Browser;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserType.LaunchOptions;<\/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> Blog4_Pause {<\/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>LaunchOptions lo = <strong>new<\/strong> LaunchOptions();<\/p>\n<p>\/\/lo.setChannel(&#8220;chrome&#8221;);<\/p>\n<p>lo.setChannel(&#8220;msedge&#8221;);<\/p>\n<p>lo.setHeadless(<strong>false<\/strong>);<\/p>\n<p>BrowserType btype = pt.chromium();<\/p>\n<p>\/\/BrowserType btype = pt.firefox();<\/p>\n<p>\/\/BrowserType btype = pt.webkit();<\/p>\n<p>Browser b = btype.launch((<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>)));<\/p>\n<p>\/\/Page pg = pt.chromium().launch().newPage();<\/p>\n<p>Page pg = b.newPage();<\/p>\n<p>pg.navigate(&#8220;https:\/\/rahulshettyacademy.com\/&#8221;);<\/p>\n<p>pg.pause();<\/p>\n<p>System.<strong><em>out<\/em><\/strong>.println(pg.title());<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<\/p>\n<p><strong>Source code (multiple browser pages)<\/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>\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.BrowserType.LaunchOptions;<\/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> Blog4_Pause {<\/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>LaunchOptions lo = <strong>new<\/strong> LaunchOptions();<\/p>\n<p>\/\/lo.setChannel(&#8220;chrome&#8221;);<\/p>\n<p>lo.setChannel(&#8220;msedge&#8221;);<\/p>\n<p>lo.setHeadless(<strong>false<\/strong>);<\/p>\n<p>BrowserType btype = pt.chromium();<\/p>\n<p>\/\/BrowserType btype = pt.firefox();<\/p>\n<p>\/\/BrowserType btype = pt.webkit();<\/p>\n<p>Browser b = btype.launch((<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>)));<\/p>\n<p>BrowserContext bcontext = b.newContext();<\/p>\n<p>Page pg1 = bcontext.newPage();<\/p>\n<p>Page pg2 = bcontext.newPage();<\/p>\n<p>Page pg3 = bcontext.newPage();<\/p>\n<p>Page pg4 = bcontext.newPage();<\/p>\n<p>\/\/Page pg = b.newPage();<\/p>\n<p>pg1.navigate(&#8220;https:\/\/courses.rahulshettyacademy.com\/courses\/&#8221;);<\/p>\n<p>pg2.navigate(&#8220;https:\/\/rahulshettyacademy.com\/mentorship&#8221;);<\/p>\n<p>pg3.navigate(&#8220;https:\/\/rahulshettyacademy.com\/learning-path&#8221;);<\/p>\n<p>pg4.navigate(&#8220;https:\/\/rahulshettyacademy.com&#8221;);<\/p>\n<p>pg4.pause();<\/p>\n<p>\/\/System.out.println(pg1.title());<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<\/p>\n<p>Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will explore the utilization of the &#8216;Pause&#8217; feature and the Playwright Inspector. Additionally, we will look into the concept of managing multiple browser pages or tabs using a single browser instance. Topics that we will cover: \u2018Pause\u2019 feature alongwith Playwright Inspector Utilizing a single instance of a browser to open and [&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-3054","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\/3054","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=3054"}],"version-history":[{"count":6,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3054\/revisions"}],"predecessor-version":[{"id":3693,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3054\/revisions\/3693"}],"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=3054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}