{"id":3054,"date":"2025-01-14T14:11:11","date_gmt":"2025-01-14T14:11:11","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/14\/inspector-feature-and-initiate-the-opening-of-numerous-browser-tabs-with-playwright-java\/"},"modified":"2025-01-14T14:11:11","modified_gmt":"2025-01-14T14:11:11","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><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=\"3054\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<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<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>\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\u00a0<\/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.\u00a0<\/p>\n<p>The <em>.pause()<\/em> method is useful in this situation, please refer to the method description provided below\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194652b54c7\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3057 tcb-moved-image\" data-css=\"tve-u-194652b5a46\" data-height=\"748\" data-id=\"3057\" data-init-height=\"1418\" data-init-width=\"1208\" data-width=\"637\" decoding=\"async\" height=\"748\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.44.22\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1418;\" title=\"Screenshot 2025-01-14 at 7.44.22\u202fPM\" width=\"637\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Upon 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<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194652faf95\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3058 tcb-moved-image\" data-css=\"tve-u-194652fb473\" data-height=\"318\" data-id=\"3058\" data-init-height=\"722\" data-init-width=\"1208\" data-width=\"532\" decoding=\"async\" height=\"318\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.49.03\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 722;\" title=\"Screenshot 2025-01-14 at 7.49.03\u202fPM\" width=\"532\"\/><\/span><\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946530c56b\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3059\" data-css=\"tve-u-1946530dd15\" data-height=\"277\" data-id=\"3059\" data-init-height=\"678\" data-init-width=\"1208\" data-width=\"493\" decoding=\"async\" height=\"277\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.50.24\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 678;\" title=\"Screenshot 2025-01-14 at 7.50.24\u202fPM\" width=\"493\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\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.\u00a0<\/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\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19465328e6c\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3060 tcb-moved-image\" data-css=\"tve-u-194653292b2\" data-height=\"426\" data-id=\"3060\" data-init-height=\"1126\" data-init-width=\"1208\" data-width=\"457\" decoding=\"async\" height=\"426\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.52.18\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1126;\" title=\"Screenshot 2025-01-14 at 7.52.18\u202fPM\" width=\"457\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Based on this context, we have the ability to construct a brand new browse page.<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946533dd0b\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3061 tcb-moved-image\" data-css=\"tve-u-1946533e1ce\" data-height=\"502\" data-id=\"3061\" data-init-height=\"1440\" data-init-width=\"1208\" data-width=\"421\" decoding=\"async\" height=\"502\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.53.43\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1440;\" title=\"Screenshot 2025-01-14 at 7.53.43\u202fPM\" width=\"421\"\/><\/span><\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1946534a362\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3062\" data-css=\"tve-u-1946534b376\" data-height=\"73\" data-id=\"3062\" data-init-height=\"146\" data-init-width=\"1208\" data-width=\"604\" decoding=\"async\" height=\"73\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.54.42\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 146;\" title=\"Screenshot 2025-01-14 at 7.54.42\u202fPM\" width=\"604\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>In a similar manner, we can generate two additional pages using the same browser context<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19465356ece\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3063 tcb-moved-image\" data-css=\"tve-u-19465357833\" data-height=\"446\" data-id=\"3063\" data-init-height=\"968\" data-init-width=\"1208\" data-width=\"557\" decoding=\"async\" height=\"446\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.55.33\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 968;\" title=\"Screenshot 2025-01-14 at 7.55.33\u202fPM\" width=\"557\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Execute the code.<\/p>\n<p>Observe that there are three open tabs below<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19465369b96\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3064\" data-css=\"tve-u-1946536b59a\" data-height=\"550\" data-id=\"3064\" data-init-height=\"1402\" data-init-width=\"1208\" data-width=\"474\" decoding=\"async\" height=\"550\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.56.32\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 1402;\" title=\"Screenshot 2025-01-14 at 7.56.32\u202fPM\" width=\"474\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Execute.<\/p>\n<p>Notice that 4 window tabs open this time<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19465377f38\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3065\" data-css=\"tve-u-1946537a61b\" data-height=\"420\" data-id=\"3065\" data-init-height=\"874\" data-init-width=\"1208\" data-width=\"580\" decoding=\"async\" height=\"420\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-14-at-7.57.43\u202fPM.png\" style=\"aspect-ratio: auto 1208 \/ 874;\" title=\"Screenshot 2025-01-14 at 7.57.43\u202fPM\" width=\"580\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0<\/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><\/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><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog4_Pause {<\/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>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><\/p>\n<p><strong>Source code (multiple browser pages)<\/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><\/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><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog4_Pause {<\/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>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><\/p>\n<p>Thanks!<\/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 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":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-3054","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\/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":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3054\/revisions"}],"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}]}}