Testing / Playwright Interview questions
How do you use the page.goto() method?
page.goto(url, options) navigates the current page to a given address and returns the main resource's response object once navigation completes.
await page.goto('https://example.com', { waitUntil: 'domcontentloaded', timeout: 30000 });
The waitUntil option controls when navigation is considered finished: 'load' waits for the full load event, 'domcontentloaded' waits only for the DOM to be parsed, 'networkidle' waits until there are no network connections for 500ms, and 'commit' resolves as soon as navigation is committed, before any content loads.
Choosing a lighter wait condition like domcontentloaded for pages with long-polling or analytics scripts avoids tests hanging while waiting for network activity that never truly settles.
More Related questions...