"""Read-only browser check of real service responses on the deployed US portal.""" import json from pathlib import Path import sys from playwright.sync_api import sync_playwright sys.stdout.reconfigure(encoding='utf-8', line_buffering=True) OUT = Path(__file__).resolve().parents[1] / 'artifacts/uiux-upgrade' report = {'checks': [], 'pageErrors': [], 'apiErrors': []} with sync_playwright() as playwright: browser = playwright.chromium.launch() context = browser.new_context(viewport={'width': 390, 'height': 844}, locale='en-US') page = context.new_page() page.on('pageerror', lambda error: report['pageErrors'].append(str(error))) page.on('response', lambda response: report['apiErrors'].append({'path': response.url.split('?')[0], 'status': response.status}) if response.status >= 500 and '/api/' in response.url else None) for path, selector in [ ('/notifications', '.ntf-empty'), ('/notifications/settings', '.ntf-quiet-fields input'), ('/social/coffeechat', '.cf-empty'), ('/social/coffeechat/manage', '.cf-form input'), ]: try: response = page.goto('https://nomadro.com' + path, wait_until='domcontentloaded', timeout=45000) page.locator(selector).first.wait_for(timeout=30000) errors = page.locator('.ntf-error,.cf-error').all_text_contents() report['checks'].append({'path': path, 'status': response.status, 'errors': errors, 'overflow': page.evaluate('document.documentElement.scrollWidth > innerWidth + 1')}) except Exception as error: report['checks'].append({'path': path, 'errors': [str(error)]}) page.evaluate('window.scrollTo(0, 0)') page.screenshot(path=str(OUT / ('live' + path.replace('/', '-') + '.png')), full_page=True) browser.close() (OUT / 'live-services-browser.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8') print(json.dumps(report, ensure_ascii=False)) assert not report['pageErrors'] and not report['apiErrors'] and all( item.get('status') == 200 and not item['errors'] and not item.get('overflow') for item in report['checks'] )