"""Real Chromium UI verification for seven-language visitor and user routes. Public service/schema fixtures are dated read-only catalogue snapshots. Account, order, ticket and payment responses are synthetic UI fixtures. ALL API requests are intercepted; this is not real login, payment, booking or refund verification. """ import json, os, re from pathlib import Path from urllib.parse import urlparse, parse_qs from playwright.sync_api import sync_playwright base = os.environ.get('BLOG_TEST_URL', 'http://127.0.0.1:3108').rstrip('/') indexing = os.environ.get('BLOG_INDEXING_ENABLED') == 'true' output = Path(os.environ.get('APP_SCREENSHOT_DIR', 'output/playwright/multilingual-user-cta/app-browser')) output.mkdir(parents=True, exist_ok=True) locales = ['en', 'de', 'fr', 'es', 'it', 'pt', 'zh'] public_paths = ['/', '/services', '/slots', '/terms', '/refund-policy', '/privacy', '/cookie-policy', '/contact'] copy = json.loads(Path('src/lib/i18n/public-pages.json').read_text()) base_en = json.loads(Path('src/lib/i18n/messages.json').read_text()) catalog = json.loads(Path('src/lib/i18n/catalog-messages.json').read_text()) fixtures = Path('scripts/fixtures') products_response = json.loads((fixtures / 'public-products.json').read_text()) products = products_response['data'] if isinstance(products_response['data'], list) else products_response['data']['items'] products_by_id = {p['id']: p for p in products} schemas = {i: json.loads((fixtures / f'schema-{i}.json').read_text()) for i in [13, 14, 15]} user = {'id': 90001, 'email': 'qa@example.invalid', 'nickname': 'QA fixture', 'phone': '', 'role': 'user', 'avatar': '', 'created_at': '2026-10-01T12:00:00Z'} order = {'id': 90002, 'product_id': 35, 'product_title': 'Ireland Netherlands Visa Slot', 'base_amount': 7000, 'base_currency': 'EUR', 'final_amount': 7000, 'final_currency': 'EUR', 'amount': 7000, 'currency': 'EUR', 'status': 'pending', 'created_at': '2026-10-01T12:00:00Z', 'user_inputs': {'first_name': 'QA', 'last_name': 'EXAMPLE'}, 'user_id': user['id']} ticket = {'id': 90003, 'order_id': order['id'], 'type': 'refund', 'status': 'pending', 'reason': 'QA fixture request', 'created_at': '2026-10-01T12:00:00Z'} rows, api_calls, page_errors, console_errors, actions, layout_errors, control_errors, states = [], [], [], [], [], [], [], [] def localize(path, locale): return path if locale == 'en' else '/' + locale + ('' if path == '/' else path) def attach_fixtures(context, authenticated=False): # Move the isolated API placeholder to a local intercepted URL; no unsafe-port # exception or external server is enabled. Axios request/response code still runs. context.add_init_script(r""" const open = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url, ...args) { const fixtureUrl = String(url).replace(/^http:\/\/127\.0\.0\.1:9(?=\/api\/)/, location.origin); return open.call(this, method, fixtureUrl, ...args); }; localStorage.setItem('app_lang', 'zh'); """) if authenticated: context.add_init_script("""if (!localStorage.getItem('qa-fixture-initialized')) { localStorage.setItem('rsid', 'INVALID-QA-FIXTURE-NOT-A-REAL-SESSION'); localStorage.setItem('user_info', %s); localStorage.setItem('qa-fixture-initialized', 'true'); }""" % json.dumps(json.dumps(user))) def intercept(route): req = route.request u = urlparse(req.url); q = parse_qs(u.query) api_calls.append({'method': req.method, 'path': u.path, 'intercepted': True, 'synthetic': u.path not in ['/api/vas/product/list-enable', '/api/vas/product/detail', '/api/vas/schema/detail']}) if req.method != 'GET' and not (req.method == 'POST' and u.path == '/api/vas/payment/create'): route.fulfill(status=400, content_type='application/json', body=json.dumps({'code': 400, 'message': 'Blocked fixture mutation'})); return if u.path.endswith('/product/list-enable'): response = products_response elif u.path.endswith('/product/detail'): response = {'code': 0, 'data': products_by_id.get(int(q.get('product_id', ['0'])[0]))} elif u.path.endswith('/schema/detail'): response = schemas[int(q['schema_id'][0])] elif u.path.endswith('/order/list_by_user'): response = {'code': 0, 'data': {'items': [order], 'total': 1}} elif u.path.endswith('/ticket/list_by_user'): response = {'code': 0, 'data': {'items': [ticket], 'total': 1}} elif u.path.endswith('/order/detail'): response = {'code': 0, 'data': order} elif u.path.endswith('/payment_provider/list_enabled'): response = {'code': 0, 'data': [{'id': 90004, 'name': 'stripe', 'title': 'Stripe QA fixture', 'currency': 'EUR', 'provider_type': 'stripe', 'enabled': 1}]} elif u.path.endswith('/payment/create'): # Invoice rendering only. No request leaves Playwright, and the link # uses the reserved .invalid domain. It is never opened or confirmed. response = {'code': 0, 'data': {'id': 90005, 'payment_id': 90005, 'order_id': order['id'], 'base_amount': 7000, 'base_currency': 'EUR', 'amount': 7000, 'currency': 'EUR', 'fee_amount': 0, 'random_offset': 0, 'channel': 'online_link', 'payment_url': 'https://example.invalid/qa-payment', 'provider_type': 'stripe', 'status': 'pending'}} elif u.path.endswith('/payment/confirm'): response = {'code': 0, 'data': {'status': 'succeeded'}} elif 'message' in u.path: response = {'code': 0, 'data': {'items': [], 'total': 0}} elif 'snapshot' in u.path or 'slots' in u.path: response = {'code': 0, 'data': []} elif u.path.endswith('/list_by_order') or 'events' in u.path: response = {'code': 0, 'data': []} else: response = {'code': 0, 'data': {'items': [], 'total': 0}} route.fulfill(status=200, content_type='application/json', body=json.dumps(response)) context.route('**/api/**', intercept) # The fixture catalogue has remote marketing images. Their network performance # is not measured here; stop those remote assets from leaving the test context. context.route('https://api.text.skin/**', lambda route: route.abort()) def observe(page): page.on('pageerror', lambda error: page_errors.append({'url': page.url, 'message': str(error)})) page.on('console', lambda msg: console_errors.append({'url': page.url, 'message': msg.text, 'source': msg.location.get('url')}) if msg.type == 'error' else None) def inspect_view(page, label, locale, widths=(320, 390, 1440)): for width in widths: page.set_viewport_size({'width': width, 'height': 900}) if not page.evaluate('document.documentElement.scrollWidth <= innerWidth'): layout_errors.append({'path': localize(label, locale), 'width': width, 'scrollWidth': page.evaluate('document.documentElement.scrollWidth')}) controls = page.locator('input:not([type="hidden"]), textarea, select, button').evaluate_all("""els => els.filter(el => el.getClientRects().length).map(el => ({tag: el.tagName, type: el.type, name: el.getAttribute('aria-label') || el.getAttribute('aria-labelledby') || [...(el.labels || [])].map(l => l.innerText).join(' ').trim() || (el.tagName === 'BUTTON' ? el.innerText.trim() || el.title || [...el.querySelectorAll('img')].map(i => i.alt).join(' ').trim() : '')}))""") if not all(c['name'] for c in controls): control_errors.append({'url': page.url, 'state': label, 'controls': [c for c in controls if not c['name']]}) states.append({'path': localize(label, locale), 'checkedWidths': list(widths), 'layoutPass': not any(e['path'] == localize(label, locale) for e in layout_errors), 'namedControls': sum(bool(c['name']) for c in controls)}) return len(controls) def verify_page(page, path, locale, public=False): response = page.goto(base + localize(path, locale), wait_until='networkidle') assert response and response.status == 200, page.url assert page.locator('html').get_attribute('lang') == ('zh-CN' if locale == 'zh' else locale), page.url assert page.locator('nav select:visible').first.input_value() == locale, page.url assert page.locator('link[rel="canonical"]').get_attribute('href') == 'https://text.skin' + localize(path, locale), page.url if public: assert page.title() == copy[locale][path][0] + ' | STRATA', page.url assert page.locator('h1').count() == 1, page.url assert page.locator('link[rel="alternate"][hreflang]').count() == 8, page.url else: assert page.locator('meta[name="robots"]').get_attribute('content') == 'noindex, nofollow', page.url assert response.headers.get('x-robots-tag') == 'noindex, nofollow', page.url widths = [320, 390, 768, 1024, 1440] count = inspect_view(page, path, locale, widths) rows.append({'path': localize(path, locale), 'language': locale, 'status': response.status, 'title': page.title(), 'public': public, 'checkedWidths': widths, 'layoutPass': not any(e['path'] == localize(path, locale) for e in layout_errors), 'namedControls': count, 'api': 'Isolated UI fixtures; no live account or transaction'}) (output / 'progress.json').write_text(json.dumps({'completedPages': rows, 'layoutErrors': layout_errors, 'unnamedControlErrors': control_errors, 'pageErrors': page_errors}, ensure_ascii=False, indent=2)) print('Checked', localize(path, locale), flush=True) return response with sync_playwright() as p: options = {'headless': True} if os.environ.get('CHROMIUM_PATH'): options['executable_path'] = os.environ['CHROMIUM_PATH'] browser = p.chromium.launch(**options) context = browser.new_context(viewport={'width': 1440, 'height': 900}, locale='en-IE') attach_fixtures(context) page = context.new_page(); observe(page) for locale in locales: for path in public_paths: verify_page(page, path, locale, public=True) if path == '/slots': assert page.locator('#slot-country').input_value() == 'IE' assert page.locator('#slot-city').input_value() == 'Dublin' page.locator('#slot-country').select_option('GB') assert page.locator('#slot-city').input_value() == 'London' assert page.locator('#slot-city option').evaluate_all('(els) => els.map(el => el.value)') == ['London', 'Manchester'] if path == '/services': for product in products: heading = page.get_by_role('heading', name=catalog[product['title']][locales.index(locale)], exact=True) assert heading.count() == 1 heading.click() modal = page.locator('main .fixed.inset-0.z-50').first assert modal.is_visible() inspect_view(page, '/services#detail-' + str(product['id']), locale) modal.locator('button[aria-label]').first.click() if locale in ['de', 'fr', 'zh']: page.set_viewport_size({'width': 390, 'height': 900}) page.screenshot(path=str(output / f'{locale}-services-mobile.png'), full_page=True) # Client navigation updates metadata for the newly selected page. page.goto(base + localize('/', locale), wait_until='networkidle') page.locator('main a[href="' + localize('/services', locale) + '"]').focus(); page.keyboard.press('Enter') page.wait_for_url(base + localize('/services', locale), wait_until='networkidle') assert page.title() == copy[locale]['/services'][0] + ' | STRATA' assert page.locator('link[rel="canonical"]').get_attribute('href').endswith(localize('/services', locale)) # The URL owns the language even with a contradictory saved preference. page.goto(base + localize('/services', locale) + '?source=qa#details', wait_until='networkidle') target_locale = 'fr' if locale != 'fr' else 'de' page.locator('nav select:visible').select_option(target_locale) page.wait_for_url(base + localize('/services', target_locale) + '?source=qa#details', wait_until='networkidle') assert page.locator('html').get_attribute('lang') == target_locale assert page.title() == copy[target_locale]['/services'][0] + ' | STRATA' actions.append({'locale': locale, 'clientNavigationMetadata': True, 'languagePreservesQueryAndFragment': True, 'slotValuesPreserved': True}) context.close() for locale in locales: context = browser.new_context(viewport={'width': 1440, 'height': 900}, locale='en-IE') attach_fixtures(context, authenticated=True) page = context.new_page(); observe(page) for path in ['/login', '/dashboard', '/dashboard/settings', '/create-order/34', '/create-order/35', '/create-order/36', '/payment/90002', '/payment/confirm']: verify_page(page, path, locale) if path == '/login': page.locator('main form button[type="button"]').click() inspect_view(page, '/login#forgot-password', locale) page.locator('main .fixed.inset-0.z-50 button[aria-label]').first.click() page.locator('main > div > div > div.flex.border-b-2 button').nth(1).click() inspect_view(page, '/login#register-info', locale) if path == '/dashboard': page.locator('main button').filter(has=page.locator('svg.lucide-eye')).first.click() inspect_view(page, '/dashboard#order-detail', locale) page.locator('main .fixed.inset-0.z-50 button[aria-label]').first.click() page.set_viewport_size({'width': 390, 'height': 900}) tabs = page.locator('main > div > div.md\\:hidden button') tabs.nth(1).click() inspect_view(page, '/dashboard#tickets', locale) page.locator('main button').filter(has=page.locator('svg.lucide-eye')).first.click() inspect_view(page, '/dashboard#ticket-detail', locale) page.locator('main .fixed.inset-0.z-50 button[aria-label]').first.click() page.locator('main button').filter(has=page.locator('svg.lucide-plus')).first.click() inspect_view(page, '/dashboard#new-ticket', locale) page.locator('main .fixed.inset-0.z-50 button[aria-label]').first.click() if path.startswith('/create-order/'): product = products_by_id[int(path.rsplit('/', 1)[1])] assert page.locator('h1').inner_text() == catalog[product['title']][locales.index(locale)] nationality = page.locator('#field-nationality') if nationality.count(): schema_record = schemas[product['schema_id']]['data'] schema = schema_record['schema_json'] if isinstance(schema, str): schema = json.loads(schema) expected_default = schema['properties']['nationality'].get('default', '') assert nationality.input_value() == expected_default, (page.url, expected_default) if nationality.evaluate('(el) => el.tagName') == 'SELECT': assert nationality.locator('option').evaluate_all('(els) => els.slice(1).map(el => el.value)') == schema['properties']['nationality']['enum'] if nationality.evaluate('(el) => el.tagName') == 'SELECT': nationality.select_option('China'); assert nationality.input_value() == 'China' else: nationality.fill('Chinese'); assert nationality.input_value() == 'Chinese' gender = page.locator('#field-gender') if gender.count(): gender.select_option('female'); assert gender.input_value() == 'female' if product['id'] == 35 and locale in ['de', 'zh']: page.set_viewport_size({'width': 390, 'height': 900}) page.screenshot(path=str(output / f'{locale}-netherlands-order-mobile.png'), full_page=True) if path == '/dashboard/settings': page.locator('main button').filter(has=page.locator('svg.lucide-pen')).click() inspect_view(page, '/dashboard/settings#edit-profile', locale) page.locator('main form button[type="button"]').click() page.locator('main button').filter(has_text=re.compile(r'^\[')).last.click() assert page.locator('#changepasswordmodal-field-1').is_visible() inspect_view(page, '/dashboard/settings#password-form', locale) page.locator('main .fixed.inset-0.z-50 button[aria-label]').first.click() page.set_viewport_size({'width': 390, 'height': 900}) if locale == 'zh': page.screenshot(path=str(output / 'zh-settings-mobile.png'), full_page=True) if path == '/payment/90002': page.locator('main button').filter(has_text='Stripe QA fixture').click() page.locator('main a[href="https://example.invalid/qa-payment"]').wait_for(state='visible') inspect_view(page, '/payment/90002#invoice-fixture', locale) if locale == 'fr': page.set_viewport_size({'width': 390, 'height': 900}) page.screenshot(path=str(output / 'fr-invoice-fixture-mobile.png'), full_page=True) # Follow each visible article conversion button to its correct localized # service using the same fully intercepted UI context. No order is submitted. for service_id, slug in [(35, 'netherlands'), (34, 'greece'), (36, 'denmark')]: page.goto(base + localize('/blogs/' + slug + '-visa-appointments-dublin', locale), wait_until='networkidle') cta = page.locator('.blog-service-button'); cta.focus(); page.keyboard.press('Enter') page.wait_for_url(base + localize('/create-order/' + str(service_id), locale), wait_until='networkidle') assert page.locator('h1').inner_text() == catalog[products_by_id[service_id]['title']][locales.index(locale)] assert page.locator('html').get_attribute('lang') == ('zh-CN' if locale == 'zh' else locale) actions.append({'locale': locale, 'articleServiceCTA': service_id, 'destination': localize('/create-order/' + str(service_id), locale), 'keyboard': True, 'api': 'Public catalogue snapshot; no order submission'}) # Real DOM/native-control language change, with service ID and parameters kept. page.goto(base + localize('/create-order/35', locale) + '?routing_key=qa_route&slot_country=Netherlands&slot_city=Dublin&slot_visa_type=Tourist#details', wait_until='networkidle') target_locale = 'pt' if locale != 'pt' else 'it' page.locator('nav select:visible').select_option(target_locale) page.wait_for_url(re.compile(re.escape(base + localize('/create-order/35', target_locale)) + r'\?'), wait_until='networkidle') assert page.locator('input[name="slot_country"]').input_value() == 'Netherlands' assert page.locator('input[name="slot_city"]').input_value() == 'Dublin' assert page.locator('input[name="slot_visa_type"]').input_value() == 'Tourist' assert 'routing_key=qa_route' in page.url and page.url.endswith('#details') # Keyboard menu operation and same-locale user navigation. page.set_viewport_size({'width': 390, 'height': 900}) toggle = page.locator('button[aria-controls="site-mobile-menu"]:visible') toggle.focus(); page.keyboard.press('Enter'); assert toggle.get_attribute('aria-expanded') == 'true' page.keyboard.press('Escape'); assert toggle.get_attribute('aria-expanded') == 'false' assert toggle.evaluate('(el) => el === document.activeElement') page.goto(base + localize('/dashboard', locale), wait_until='networkidle') toggle = page.locator('button[aria-controls="site-mobile-menu"]:visible') toggle.click(); page.locator('#site-mobile-menu a[href="' + localize('/dashboard', locale) + '"]').click() page.wait_for_url(base + localize('/dashboard', locale), wait_until='networkidle') actions.append({'locale': locale, 'serviceIdAndRawQueryValuesPreserved': True, 'keyboardMenuAndEscape': True, 'userSession': 'Synthetic local marker only'}) context.close() browser_version = browser.version browser.close() # Remote fixture images are intentionally not fetched. Record each blocked image # separately; every JS/hydration error or other console error still fails the run. image_errors = [e for e in console_errors if 'api.text.skin/api/r2/file' in (e['source'] or '') and 'ERR_FAILED' in e['message']] unexpected = [e for e in console_errors if e not in image_errors] receipt = {'base': base, 'indexing': indexing, 'browser': browser_version, 'pages': rows, 'uiStates': states, 'actions': actions, 'apiRequests': api_calls, 'pageErrors': page_errors, 'unexpectedConsoleErrors': unexpected, 'fixtureImageErrors': image_errors, 'layoutErrors': layout_errors, 'unnamedControlErrors': control_errors, 'scope': 'Real Chromium rendering/navigation with intercepted API fixtures. Invoice creation POST is handled entirely by Playwright; no payment link is opened or confirmed. NOT real authentication, payment, booking, email, refund or image performance verification'} (output / 'app-browser-results.json').write_text(json.dumps(receipt, ensure_ascii=False, indent=2) + '\n') assert not layout_errors, layout_errors assert not control_errors, control_errors assert not page_errors, page_errors assert not unexpected, unexpected assert all(call['method'] == 'GET' or (call['method'] == 'POST' and call['path'] == '/api/vas/payment/create' and call['intercepted'] and call['synthetic']) for call in api_calls), 'Unexpected business mutation' assert sum(call['method'] == 'POST' for call in api_calls) == 7, 'Only seven intercepted invoice fixture requests are expected' print(f'PASS: {len(rows)} seven-language visitor/user pages in real Chromium; localized metadata, named controls, phone/tablet/desktop overflow, service and enum values, query-preserving language changes, client navigation and keyboard menu. API responses are isolated UI fixtures. Receipt: {output}')