Explorer
/tmp/p7_browser.py
← Zurück ↓ Download
import asyncio,json
from playwright.async_api import async_playwright
async def main():
 async with async_playwright() as p:
  b=await p.chromium.launch(headless=True,executable_path='/snap/bin/chromium',args=['--no-sandbox'])
  pg=await b.new_page(viewport={'width':1440,'height':1000})
  out={}
  for name,url,need in [('fb14','/cockpit?days=14&sort=facebook&tab=radar','META AD'),('li14','/cockpit?days=14&sort=linkedin&tab=radar','')]:
   r=await pg.goto('http://127.0.0.1:8652'+url,wait_until='domcontentloaded',timeout=30000); await pg.wait_for_timeout(300)
   text=await pg.locator('body').inner_text(); out[name]={'http':r.status,'cards':await pg.locator('.sig').count(),'need':need in text if need else True,'bad':any(x in text for x in ['RSS','Web','YouTube'])}
  await pg.goto('http://127.0.0.1:8652/cockpit?days=14&sort=facebook&tab=radar',wait_until='domcontentloaded'); await pg.wait_for_timeout(300); await pg.locator('.sig .thumb').first.click(); await pg.wait_for_timeout(100); out['detail']=await pg.locator('#pcontent.on').count()==1
  await pg.screenshot(path='/tmp/p7_regression_fb14.png',full_page=True)
  await b.close()
 print(json.dumps(out))
asyncio.run(main())