playwright-behavelisted
Install: claude install-skill petermcalister/shared-skills
# Playwright + Behave Testing
## Overview
Test UI behavior through user-visible interactions, not DOM structure. Playwright's auto-waiting and role-based selectors make tests resilient to implementation changes.
**Core principle:** If your test breaks when CSS classes change, you're testing the wrong thing.
## When to Use
- Writing browser automation tests with Python Behave
- Creating page objects for UI components
- Debugging "element not found" or flaky test failures
- Setting up browser lifecycle in `environment.py`
- Converting manual UI tests to automated BDD tests
## When NOT to Use
| Situation | Use Instead |
|-----------|-------------|
| API endpoint testing | `requests` + pytest |
| Unit testing Python code | pytest directly |
| Static HTML validation | BeautifulSoup/lxml |
| Load/performance testing | Locust or k6 |
## Quick Reference
| Task | Pattern |
|------|---------|
| Find button | `page.get_by_role("button", name="Submit")` |
| Find form field | `page.get_by_label("Email")` |
| Find by text | `page.get_by_text("Welcome")` |
| Find by test ID | `page.get_by_test_id("submit-btn")` |
| Wait for load | `page.wait_for_load_state("networkidle")` |
| Assert visible | `expect(element).to_be_visible()` |
| Assert URL | `expect(page).to_have_url_matching(r".*/dashboard")` |
| Debug selectors | `playwright codegen http://localhost:8502` |
| View trace | `playwright show-trace traces/scenario.zip` |
## Selector Priority (Most to Least Preferred)
1. **Role** -