arrow-left Back to topicQuizEventsCheck yourself1.You want to capture a new tab that opens when a button is clicked. Why must you set up context.waitForEvent('page') BEFORE clicking?It's just a convention — the order doesn't actually matterThe 'page' event fires when the tab opens. If you set up the listener after clicking, the event may have already fired and you'll miss itYou need to set up the listener before clicking because Playwright blocks navigation until a listener is registered2.What's the difference between page.on('dialog') and page.once('dialog')?page.on fires for every dialog; page.once fires only for the next one and then removes itselfpage.once is faster than page.onThey're identical — 'once' is just an alias3.You want to log all console errors that occur during a test run. Which pattern is correct?Use page.waitForEvent('console') to capture each error one by one.Use page.on('console', msg => { if (msg.type() === 'error') errors.push(msg.text()) }) before navigating.Use browser.on('console', handler) — console events fire on the browser, not the page.Enable devtools: true in the launch options — errors are auto-saved.4.What is the key difference between context.waitForEvent('page') and page.waitForEvent('popup')?They are identical — use either one interchangeably.context.waitForEvent('page') captures any new page/tab in the context; page.waitForEvent('popup') captures popups opened specifically by that page (e.g., via window.open()).page.waitForEvent('popup') works for new tabs; context.waitForEvent('page') works only for modal dialogs.context.waitForEvent('page') is deprecated — use page.waitForEvent('popup') instead.5.How do you wait for a specific API request to be made, then verify its query parameters?Use page.on('request', req => ...) and check the URL after the action.Use page.route() to intercept the request and inspect it.Create const reqPromise = page.waitForRequest(predicate) before the action, trigger the action, then const req = await reqPromise and inspect req.url().Use page.waitForNavigation() — it waits for all requests to complete.6.When should you use page.off('request', handler) after using page.on('request', handler)?Always — Playwright leaks memory if you don't call off.When you want to stop collecting events after a specific action and avoid picking up unrelated subsequent requests.Never — Playwright automatically removes listeners when the test ends.Only when testing multiple pages in the same test.7.You want to verify the API response status after a form submission. Which is the correct approach?After clicking submit, call page.waitForResponse('/api/orders') and check .status().Before clicking submit, create const resPromise = page.waitForResponse('/api/orders'), click submit, then const res = await resPromise and check res.status().Use page.on('response', res => ...) and store the status in a variable.Use page.evaluate(() => fetch('/api/orders').then(r => r.status)).8.A popup window opens when a payment button is clicked. Which event and object should you wait for?context.waitForEvent('page') — popups are new pages in the context.page.waitForEvent('popup') — the popup was opened by this page.browser.waitForEvent('window') — windows are tracked on the browser object.page.waitForEvent('newpage') — this event fires for all new windows.Submit answersarrow-left PreviousHandlesAccessibility testingNext arrow-right