Manuals / Playwright with Python / Chapter 37

Part 5 · CI/CD & Reporting · advanced · ~35 min · Chapter 37 of 61

28. Logging & Error Handling

Custom logging setup import logging logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) logger = logging.getLogger(__name__) def test_login(page): logger.info("Starting login test") page.goto("https://app.example.com/login") logger.info("Navigated to login page") logging.basicConfig(level=..., format=...) What it does: Configures the root logger's minimum

Path progress
59%

Step 1 of 4

Custom logging setup

level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) logger = logging.getLogger(__name__)

Custom logging setupDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →

Try it

Run / study this snippet

def test_login(page):
Was this step clear?
Chapter learning outcomes
  • Custom logging setup
  • Screenshot/video capture on failure
  • Retry logic for flaky tests

Clear these before you leave

Side quest

28. Logging & Error Handling deliverable

Apply one idea from “Custom logging setup” in a small script or note.