You have read through 10 lessons. Now write actual code. These exercises cover every scenario from this chapter. Do them in order. Each one builds your muscle memory for a specific complex scenario.
Exercise 1: Iframe Interactions
- Go to /topics/iframes and locate the iframe using frameLocator()
- Fill in a form inside the iframe and submit it
- Verify the success message appears inside the iframe
- Locate a nested iframe and interact with elements inside it
- Run with npx playwright test --headed and observe the iframe interactions
Exercise 2: Multi-Tab Flow
- Go to /topics/windows and click a link that opens in a new tab
- Use context.waitForEvent('page') to capture the new tab
- Fill a form in the new tab and submit it
- Close the new tab and verify results on the original page
- Create two tabs with context.newPage() and navigate each to different URLs
Exercise 3: Dialog Handling
- Handle an alert dialog -- verify the message text and accept it
- Handle a confirm dialog -- test both accept and dismiss outcomes
- Handle a prompt dialog -- enter text and verify the page uses it
- Use page.on('dialog') to handle multiple sequential dialogs
- Verify what happens when you do NOT register a handler (auto-dismiss behavior)
Exercise 4: File Operations
- Upload a single file using setInputFiles() and verify the filename appears
- Upload multiple files and verify the count
- Clear a file selection with setInputFiles([])
- Download a file, check suggestedFilename(), and save it with saveAs()
- Verify the downloaded file exists and has content using fs module
Exercise 5: Drag, Hover, and Keyboard
- Drag an item to a drop zone using dragTo()
- Implement manual mouse drag with mouse.down(), mouse.move(), mouse.up()
- Hover over an element and verify the tooltip text
- Use keyboard.press() to test Ctrl+A, Ctrl+C, Ctrl+V flow
- Right-click an element and interact with the context menu
Exercise 6: Dropdowns and Date Pickers
- Select an option from a native <select> dropdown using selectOption()
- Open a custom dropdown, filter by typing, and select an option
- Fill a native date input with fill('YYYY-MM-DD')
- Navigate a calendar widget to a future month and select a date
- Combine: select a dropdown value, pick a date, and submit the form
Key Point: Six exercises covering all 10 topics. Type the code yourself. Run each test in headed mode with --headed so you can see what is happening. Debug failures with --debug for step-by-step execution.
Key Point: Six exercises, one per topic group. Type the code, run in headed mode, debug step-by-step. Reading is not doing.