"""Minimal Playwright test — открывает Chrome окно с Avito на 30 sec."""
import asyncio
from playwright.async_api import async_playwright


async def go():
    async with async_playwright() as p:
        print("launching browser...", flush=True)
        browser = await p.chromium.launch(headless=False)
        print("browser launched, opening page...", flush=True)
        page = await browser.new_page()
        try:
            await page.goto(
                "https://www.avito.ru/ekaterinburg/kvartiry/prodam-ASgBAgICAUSSA8YQ?s=104&p=1",
                timeout=30000,
            )
        except Exception as e:
            print(f"goto FAIL: {type(e).__name__}: {e}", flush=True)
            await asyncio.sleep(15)
            await browser.close()
            return
        print("page loaded", flush=True)
        try:
            title = await page.title()
            print(f"title: {title}", flush=True)
        except Exception as e:
            print(f"title FAIL: {e}", flush=True)
        print("окно должно быть видно ~30 сек", flush=True)
        await asyncio.sleep(30)
        await browser.close()


if __name__ == "__main__":
    asyncio.run(go())
