Save comprehensive error snapshot with all debugging artifacts. Directory structure: errors_py/YYYY-MM-DD/HH-MM-SS_reqid_errorname/ ├── screenshot.png ├── dom_dump.html ├── dom_structure.txt ├── console_logs.txt ├── networ
(
page: AsyncPage,
error_name: str,
req_id: str,
error_stage: str = "",
additional_context: Optional[Dict[str, Any]] = None,
locators: Optional[Dict[str, Locator]] = None,
error_exception: Optional[Exception] = None,
)
| 409 | |
| 410 | |
| 411 | async def save_comprehensive_snapshot( |
| 412 | page: AsyncPage, |
| 413 | error_name: str, |
| 414 | req_id: str, |
| 415 | error_stage: str = "", |
| 416 | additional_context: Optional[Dict[str, Any]] = None, |
| 417 | locators: Optional[Dict[str, Locator]] = None, |
| 418 | error_exception: Optional[Exception] = None, |
| 419 | ) -> str: |
| 420 | """ |
| 421 | Save comprehensive error snapshot with all debugging artifacts. |
| 422 | |
| 423 | Directory structure: |
| 424 | errors_py/YYYY-MM-DD/HH-MM-SS_reqid_errorname/ |
| 425 | ├── screenshot.png |
| 426 | ├── dom_dump.html |
| 427 | ├── dom_structure.txt |
| 428 | ├── console_logs.txt |
| 429 | ├── network_requests.json |
| 430 | ├── playwright_state.json |
| 431 | └── metadata.json |
| 432 | |
| 433 | Args: |
| 434 | page: Playwright page instance |
| 435 | error_name: Base error name (e.g., "stream_post_button_check_disconnect") |
| 436 | req_id: Request ID |
| 437 | error_stage: Description of error stage (e.g., "Post-stream response button state check") |
| 438 | additional_context: Extra context to include in metadata |
| 439 | locators: Dict of named locators to capture states for |
| 440 | error_exception: Exception object (if available) |
| 441 | |
| 442 | Returns: |
| 443 | str: Path to snapshot directory |
| 444 | """ |
| 445 | # Set request context for grid logging |
| 446 | from logging_utils import set_request_id |
| 447 | |
| 448 | set_request_id(req_id if req_id else "DEBUG") |
| 449 | |
| 450 | # Check page availability |
| 451 | if not page or page.is_closed(): |
| 452 | logger.warning(f"Cannot save snapshot ({error_name}), page is unavailable.") |
| 453 | return "" |
| 454 | |
| 455 | logger.info(f"Saving comprehensive error snapshot ({error_name})...") |
| 456 | |
| 457 | # Get timestamps |
| 458 | iso_timestamp, human_timestamp = get_texas_timestamp() |
| 459 | time_component = iso_timestamp.split("T")[1].replace(":", "-").replace(".", "-") |
| 460 | |
| 461 | # Create date-based directory structure |
| 462 | date_str = iso_timestamp.split("T")[0] # YYYY-MM-DD |
| 463 | base_error_dir = Path(__file__).parent.parent / "errors_py" |
| 464 | date_dir = base_error_dir / date_str |
| 465 | snapshot_dir_name = f"{time_component}_{req_id}_{error_name}" |
| 466 | snapshot_dir = date_dir / snapshot_dir_name |
| 467 | |
| 468 | try: |