Source: apps/search_console_tools/core/engine.py.
🎯 Purpose
GoogleSearchConsoleEngine is the main entry point for GSC UI automation:
- starts Playwright Chromium (persistent context)
- performs Google authentication
- executes registered commands
- captures a screenshot on teardown (best-effort)
🗂️ Persistent context and browser-data
The engine launches Chromium with launch_persistent_context(...) using:
user_data_dir = BASE_DIR/browser-data/<account_username>
Where account_username is the part of email before @.
Benefits:
- session reuse (cookies/localStorage)
- fewer logins
- easier debugging of profile state
⚙️ Playwright configuration
The engine sets:
locale = "en-US"- a list of Chromium
args(e.g. window sizing, sandbox flags, etc.)
If a command breaks:
- first check selectors and timeouts
- then re-check the UI texts used by commands
🔐 Google authentication
Algorithm:
page.goto("https://accounts.google.com/")- If
page.urlcontainshttps://myaccount.google.com/→ already authenticated - Otherwise:
- wait for email input, fill email, click “Next”
- wait for password input, fill password, click “Next”
If the expected inputs are missing (e.g. Google security interstitial like “Verify it’s you”),
GoogleAuthenticationException is raised.
🔁 Retry logic
run_command(...) tries at most 2 times:
- attempt #1: normal run
- if auth fails: clear
browser-data/<username> - attempt #2: retry login and command execution
Goal: recover from a broken/bad session while avoiding infinite loops.
🧹 Safe deletion of browser-data
Before deleting a profile directory, the engine verifies it is inside BASE_DIR/browser-data.
This prevents accidental deletion of unrelated directories.
📸 Screenshot
During teardown the engine calls page.screenshot() and stores bytes in engine.screenshot_data.
CommandRequestExecutor attaches it to CommandRequest.screenshot if available.