Drill 1: User-Facing Locators & Auto-Waiting Mechanics
Scenario: Automate a user login flow targeting accessible roles instead of brittle CSS selectors or absolute XPaths.
import { test, expect } from '@playwright/test';
test('automate login using accessible role locators', async ({ page }) => {
await page.goto('https://www.testerrank.com/banking/login');
// Playwright automatically waits for elements to be visible and enabled
await page.getByLabel('Username or Account ID').fill('demo_user_88');
await page.getByLabel('Password').fill('SecurePassword123!');
// Target the button by its accessible role and text
await page.getByRole('button', { name: 'Sign In' }).click();
// Assert expected post-login dashboard state
await expect(page.getByRole('heading', { name: 'Account Overview' })).toBeVisible();
await expect(page).toHaveURL(/.*dashboard/);
});Playwright eliminates explicit waits for standard actions. Methods like `.click()` and `.fill()` perform actionability checks (visible, stable, enabled, editable) before executing. Preferring `getByRole` and `getByLabel` ensures your automation mirrors assistive technology and real user behavior.