Why page.goto() is slowing down your tests
AI Summary
This video discusses the common Playwright page.goto function and why it can slow down end-to-end tests. The presenter demonstrates a login test script and shows that the default behavior of page.goto waits for all page resources—including images and scripts—to fully load, which can cause delays (e.g., a 10-second delay due to a slow-loading image). Various page.goto waitUntil options are explained: “commit” (wait only for first byte), “domcontentloaded” (wait for HTML and deferred scripts), “load” (default, waits for all resources), and “networkidle” (waits for network to be idle for 500 ms, discouraged due to unpredictability). Testing these options revealed that using “commit” or “domcontentloaded” can speed up tests significantly without breaking them, thanks to Playwright’s auto-waiting features that ensure interactions wait for necessary UI elements rather than network idle. The video explains how this approach matches user experience better, as users interact with UI as soon as it’s functional, not after all background resources load. However, for synthetic monitoring or production checks, waiting for full load is still useful to catch slow third-party resources. The video concludes that choosing the waitUntil option depends on your use case and environment, balancing faster tests against completeness of testing real load conditions.