"Timeouts, Codegen, Inspectors & Locators - Mastering Core Automation Features"
Duration: 1.5 Hours | Theme: Advanced Playwright Features
๐ "As testers, when we wait for a page to load, we count seconds in our head. Playwright also needs patience โ it has built-in timeouts. Similarly, just like we record steps in test case docs, Playwright can record your actions automatically. And to interact with elements, we need their addresses (locators)."
"Like telling a junior tester โ wait max 20 sec for the login button. If not visible, fail the test."
"Why not always set very high timeout (like 60 sec)?"
Answer: Because tests become slow, fail late
"Like recording test steps in Excel, but here it generates code for you."
"Like breakpoints in manual testing: you stop, check the screen, and continue."
Without correct element address โ test fails
| Locator Type | Example | Recommendation |
|---|---|---|
| CSS | #input-email |
โ Recommended |
| XPath | //input[@id='input-email'] |
โ ๏ธ Not recommended |
| Text-based | text=Login |
โ Good for buttons |
| Role-based | getByRole('button') |
โ Modern approach |
.type() is deprecated. Use .fill() instead!
| Method | Use Case | Example |
|---|---|---|
| .fill() | Input fields | await page.locator('#email').fill('test@example.com') |
| .click() | Buttons, links | await page.locator('button').click() |
| .first() | Multiple elements | await page.locator('.item').first().click() |
| .getByRole() | Accessible elements | await page.getByRole('button').click() |