arrow-left Back to topicQuizPagesCheck yourself1.A button click opens a new browser tab. How do you get a reference to that new tab?await page.newPage() — creates a new page handleSet up context.waitForEvent('page') BEFORE clicking, then await after the clickcontext.pages()[1] — get the second page from the context pages list2.Why must you set up context.waitForEvent('page') BEFORE clicking the link, not after?Because waitForEvent creates the new tab; the click alone can't open a new tabBecause the 'page' event fires as soon as the tab opens — if you register the listener after clicking, the event may have already fired and the promise never resolvesBecause Playwright requires all event listeners to be registered in a specific orderBecause the click needs to know where to send the new page object before it fires3.What is the difference between page.waitForEvent('popup') and context.waitForEvent('page')?They are identical — 'popup' and 'page' events are synonymspage.waitForEvent('popup') listens for windows opened by window.open() from the current page; context.waitForEvent('page') listens for any new page or tab opened in the contextcontext.waitForEvent('page') only works for tabs with target='_blank' linkspage.waitForEvent('popup') is deprecated and should not be used in new tests4.What does page.waitForURL('/dashboard') do?Navigates the page to /dashboardWaits until the page's current URL matches '/dashboard', then resolvesAsserts that the URL is '/dashboard' and fails immediately if it isn'tBlocks navigation away from '/dashboard'5.What does context.pages() return?A promise that resolves to the list of all open pages in the contextA synchronous array of all currently open Page objects in the browser contextThe total number of pages that have been opened since the context was createdAn array of page URLs as strings6.You need to test real-time sync between two browser tabs (same session). What is the correct approach?Create two separate browser contexts — each with its own pageCreate two pages from the same context using context.newPage()Open both tabs using page.goto() with the tab= query parameterUse page.evaluate() to programmatically open a second tab from the browser7.After your test opens a new tab and finishes, does Playwright automatically close it?No — you must call page.close() on every tab you open, or they will leak between testsYes — Playwright tears down the entire browser context at the end of each test, closing all pages in itOnly if you return the page object from the test functionOnly tabs opened via context.waitForEvent('page') are auto-closed; others are not8.A page navigation triggers a redirect. How do you correctly wait for the final URL to be /dashboard?await page.waitForTimeout(2000) then check the URL manuallyawait expect(page).toHaveURL('/dashboard') — the assertion retries until the URL matchesawait page.goto('/dashboard') to force navigation therepage.on('load', () => { assert page.url() === '/dashboard' })Submit answersarrow-left PreviousScreenshots