"""Real local Chromium QA for the public homepage, 21 guides and seven indexes. Requires Python Playwright and Chromium; CHROMIUM_PATH can select an installed browser. Tests a fresh logged-out context, never a booking or login submission. BLOG_INDEXING_ENABLED must match the build. Output is a local QA receipt, not field Core Web Vitals or an authenticated end-to-end test. """ import json import os import re from pathlib import Path 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' all_articles = json.loads(Path('src/content/blog/articles.json').read_text()) articles = [a for a in all_articles if not indexing or a['published']] published = [a for a in all_articles if a['published']] locales = ['en', 'de', 'fr', 'es', 'it', 'pt', 'zh'] output = Path(os.environ.get('BLOG_SCREENSHOT_DIR', 'output/playwright')) output.mkdir(parents=True, exist_ok=True) rows, errors, console_errors, links = [], [], [], {} home_rows = [] titles, descriptions = set(), set() def index_path(locale): return ('' if locale == 'en' else '/' + locale) + '/blogs' def article_path(article): return index_path(article['locale']) + '/' + article['slug'] 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': 1080}, locale='zh-CN') # Saved app language and browser language must not override the blog route. context.add_init_script("localStorage.setItem('app_lang', 'zh')") page = context.new_page() page.on('pageerror', lambda e: errors.append({'url': page.url, 'error': str(e)})) page.on('console', lambda m: console_errors.append({'url': page.url, 'sourceUrl': m.location.get('url'), 'error': m.text}) if m.type == 'error' else None) def load(path): response = page.goto(base + path, wait_until='networkidle') assert response and response.status == 200, path assert page.locator('[data-blog-navigation] select:visible').count() == 1, path return response public_copy = json.loads(Path('src/lib/i18n/public-pages.json').read_text()) def localize(path, locale): return path if locale == 'en' else '/' + locale + ('' if path == '/' else path) for home_lang in locales: home_path = localize('/', home_lang) page.set_viewport_size({'width': 1440, 'height': 1080}) home_response = page.goto(base + home_path, wait_until='networkidle') assert home_response and home_response.status == 200 assert page.locator('html').get_attribute('lang') == ('zh-CN' if home_lang == 'zh' else home_lang) assert page.locator('h1').count() == 1 assert page.title() == public_copy[home_lang]['/'][0] + ' | STRATA' assert page.locator('meta[name="description"]').get_attribute('content') == public_copy[home_lang]['/'][1] robots = 'index, follow' if indexing or home_lang == 'en' else 'noindex, follow' assert page.locator('meta[name="robots"]').get_attribute('content') == robots assert page.locator('link[rel="canonical"]').count() == 1 assert page.locator('link[rel="canonical"]').get_attribute('href') == 'https://text.skin' + home_path assert page.locator('meta[property="og:url"]').get_attribute('content') == 'https://text.skin' + home_path assert page.locator('link[rel="alternate"][hreflang]').count() == 8 assert page.locator('nav select:visible').input_value() == home_lang assert page.locator('link[rel="icon"]').get_attribute('href') == '/blog-icon.svg' # The homepage hero keeps its original title and two primary actions. # The existing shared Navbar still provides the localized blog entry. assert page.locator('main a[href="' + index_path(home_lang) + '"]').count() == 0 guide = page.locator('nav a[href="' + index_path(home_lang) + '"]:visible').first assert guide.count() == 1 for width in [320, 390, 768, 1024, 1280, 1440]: page.set_viewport_size({'width': width, 'height': 844}) assert page.evaluate('document.documentElement.scrollWidth <= innerWidth'), f'Homepage overflow {home_lang}/{width}' page.set_viewport_size({'width': 1440, 'height': 1080}) page.screenshot(path=str(output / ('home-' + home_lang + '-desktop.png')), full_page=True) page.set_viewport_size({'width': 390, 'height': 844}) page.screenshot(path=str(output / ('home-' + home_lang + '-mobile.png')), full_page=True) page.set_viewport_size({'width': 1440, 'height': 1080}) guide.focus() page.keyboard.press('Enter') page.wait_for_url(base + index_path(home_lang), wait_until='networkidle') assert page.locator('html').get_attribute('lang') == home_lang page.go_back(wait_until='networkidle') assert page.url == base + home_path assert page.locator('link[rel="canonical"]').get_attribute('href') == 'https://text.skin' + home_path home_rows.append({'path': home_path, 'status': home_response.status, 'uiLanguage': home_lang, 'serverMetadataLanguage': home_lang, 'canonical': 'https://text.skin' + home_path, 'robots': robots, 'widthsWithoutOverflow': [320, 390, 768, 1024, 1280, 1440], 'keyboardGuideLink': True, 'historyCanonicalRestored': True}) for locale in locales: records = [{'locale': locale, 'path': index_path(locale)}] + [dict(a, path=article_path(a)) for a in articles if a['locale'] == locale] for a in records: path = a['path'] page.set_viewport_size({'width': 1440, 'height': 1080}) response = load(path) for desktop_width in [1280, 1440]: page.set_viewport_size({'width': desktop_width, 'height': 1080}) assert page.evaluate('document.documentElement.scrollWidth <= innerWidth'), f'Overflow {desktop_width}: {path}' assert page.locator('button[aria-controls="site-mobile-menu"]:visible').count() == 0, path assert page.locator('html').get_attribute('lang') == locale, path title = page.title() description = page.locator('meta[name="description"]').get_attribute('content') assert title and title.endswith(' | STRATA') and title not in titles, path assert description and description not in descriptions, path titles.add(title) descriptions.add(description) assert page.locator('h1').count() == 1 and page.locator('h1').text_content().strip() == title.removesuffix(' | STRATA'), path assert page.locator('link[rel="canonical"]').get_attribute('href') == 'https://text.skin' + path, path assert page.locator('meta[name="robots"]').get_attribute('content') == ('index' if indexing else 'noindex') + ', follow', path assert page.locator('meta[property="og:url"]').get_attribute('content') == 'https://text.skin' + path, path assert page.locator('meta[property="og:title"]').get_attribute('content') == title.removesuffix(' | STRATA'), path assert page.locator('meta[property="og:description"]').get_attribute('content') == description, path assert page.locator('link[rel="icon"]').get_attribute('href') == '/blog-icon.svg', path expected = {b['locale']: 'https://text.skin' + article_path(b) for b in published if b['id'] == a['id']} if 'id' in a else {l: 'https://text.skin' + index_path(l) for l in locales if any(b['locale'] == l for b in published)} if 'en' in expected: expected['x-default'] = expected['en'] alternates = page.locator('link[rel="alternate"][hreflang]').evaluate_all('(els) => Object.fromEntries(els.map(e => [e.hreflang, e.href]))') assert alternates == expected, path counterparts = [b for b in articles if b['id'] == a['id']] if 'id' in a else [{'locale': l} for l in locales] targets = [article_path(b) if 'id' in b else index_path(b['locale']) for b in counterparts] selector = page.locator('[data-blog-navigation] select:visible') assert sorted(selector.locator('option').evaluate_all('(els) => els.map(e => e.value)')) == sorted(targets), path assert selector.input_value() == path and selector.get_attribute('aria-label'), path assert 'nav.' not in page.locator('[data-blog-navigation]').inner_text(), path assert page.locator('main img').count() == 0, 'Review new images for alt/dimensions/performance' headings = page.locator('.blog-prose h2').all_inner_texts() if 'id' in a: assert headings == re.findall(r'^## (.+)$', a['body'], re.M), path assert page.locator('.blog-button').get_attribute('href') == a['officialBooking']['url'], path schema = json.loads(page.locator('script[type="application/ld+json"]').inner_text()) assert schema[0]['@type'] == 'Article' and schema[0]['headline'] == a['title'], path assert schema[0]['description'] == description and schema[0]['inLanguage'] == locale, path assert schema[0]['dateModified'] == a['reviewedAt'] and 'datePublished' not in schema[0], path assert 'STRATA' in page.locator('.blog-reviewed').inner_text(), path assert schema[0]['citation'] == page.locator('.blog-sources li a').evaluate_all('(els) => els.map(e => e.href)'), path assert schema[1]['@type'] == 'BreadcrumbList' and schema[1]['itemListElement'][1]['name'] == a['title'], path assert schema[1]['itemListElement'][0]['item'] == 'https://text.skin' + index_path(locale), path assert page.locator('main a[href="' + localize('/services', locale) + '"]').count() == 1, path service_id = {'netherlands-appointment-booking': 35, 'greece-appointment-booking': 34, 'denmark-appointment-booking': 36}[a['id']] cta = page.locator('.blog-service-button') assert cta.count() == 1 and cta.get_attribute('href') == localize('/create-order/' + str(service_id), locale), path assert cta.evaluate('(el) => getComputedStyle(el).backgroundColor') == 'rgb(21, 128, 61)', path assert cta.evaluate('(el) => getComputedStyle(el).color') == 'rgb(255, 255, 255)', path cta.focus() assert cta.evaluate('(el) => el === document.activeElement && getComputedStyle(el).outlineStyle === \"solid\"'), path cta_info = {'id': service_id, 'href': cta.get_attribute('href'), 'background': 'rgb(21, 128, 61)', 'text': 'rgb(255, 255, 255)', 'keyboardFocus': True} toc = page.locator('.blog-toc a') assert toc.count() == len(headings), path for i in range(toc.count()): target = toc.nth(i).get_attribute('href') assert page.locator(target).count() == 1 and toc.nth(i).inner_text() == page.locator(target).inner_text(), path + target toc.first.focus() page.keyboard.press('Enter') target = toc.first.get_attribute('href') assert page.locator(target).evaluate('(el) => el === document.activeElement'), path assert page.locator(target).bounding_box()['y'] >= 64, path page.evaluate('window.scrollTo(0, 0)') else: assert page.locator('.blog-card').count() == len([b for b in articles if b['locale'] == locale]), path assert page.locator('.blog-routes tbody tr').count() == 3, path for b in [b for b in articles if b['locale'] == locale]: assert page.locator('.blog-routes a[href="' + article_path(b) + '"]').count() == 1, path assert page.locator('.blog-routes a[href="' + b['officialBooking']['url'] + '"]').count() == 1, path assert page.locator('footer a[href="mailto:support@text.skin"]').count() == 1, path table = page.locator('.blog-table-scroll') assert table.count() == 1 and table.get_attribute('role') == 'region', path assert table.get_attribute('tabindex') == '0' and (table.get_attribute('aria-label') or table.get_attribute('aria-labelledby')), path assert table.locator('thead th[scope="col"]').count() == 3, path assert table.locator('tbody tr').count() == (4 if 'id' in a else 3), path for href in page.locator('a[href]').evaluate_all('(els) => els.map(e => e.getAttribute("href"))'): if href.startswith('#'): assert page.locator(href).count() == 1, path + href elif href.startswith('/') and not href.startswith('//'): target = href.split('#')[0].split('?')[0] if target not in links: links[target] = context.request.get(base + target).status assert links[target] == 200, path + ' → ' + target shot = locale + '-' + (a.get('slug') or 'index') page.screenshot(path=str(output / (shot + '-desktop.png')), full_page=True) answer_y = None for width in [320, 390, 768, 1024]: page.set_viewport_size({'width': width, 'height': 844}) assert page.evaluate('document.documentElement.scrollWidth <= innerWidth'), f'Overflow {width}: {path}' if width == 390: page.evaluate('window.scrollTo(0, 0)') if 'id' in a: answer_y = page.locator('.blog-prose > p').first.bounding_box()['y'] assert answer_y < 620, f'Answer delayed: {path}: {answer_y}' page.screenshot(path=str(output / (shot + '-mobile.png')), full_page=True) page.screenshot(path=str(output / (shot + '-viewport.png'))) toggle = page.locator('button[aria-controls="site-mobile-menu"]:visible') toggle.focus() page.keyboard.press('Enter') assert toggle.get_attribute('aria-expanded') == 'true', path page.locator('#site-mobile-menu a[href="' + index_path(locale) + '"]').focus() page.keyboard.press('Escape') assert toggle.get_attribute('aria-expanded') == 'false' and toggle.evaluate('(el) => el === document.activeElement'), path page.set_viewport_size({'width': 390, 'height': 844}) table.evaluate('(el) => { el.scrollLeft = 0; }') table.focus() assert table.evaluate('(el) => el === document.activeElement && el.scrollWidth > el.clientWidth'), path page.keyboard.press('ArrowRight') page.wait_for_function('document.querySelector(".blog-table-scroll").scrollLeft > 0') table.evaluate('(el) => { el.scrollLeft = 0; }') if 'id' in a: byline = page.locator('.blog-reviewed a[href="#blog-sources"]') byline.focus() page.keyboard.press('Enter') assert page.locator('#blog-sources').evaluate('(el) => el === document.activeElement'), path assert page.locator('#blog-sources').bounding_box()['y'] >= 64, path correction = page.locator('.blog-sources a[href^="mailto:support@text.skin?"]') assert correction.count() == 1 and 'subject=' in correction.get_attribute('href'), path for b in counterparts: target = article_path(b) if 'id' in b else index_path(b['locale']) if page.locator('[data-blog-navigation] select:visible').input_value() != target: page.locator('[data-blog-navigation] select:visible').select_option(target) page.wait_for_url(base + target, wait_until='networkidle') assert page.locator('html').get_attribute('lang') == b['locale'], target if 'id' in b: assert page.locator('h1').text_content().strip() == b['title'], target assert page.locator('[data-blog-navigation] select:visible').input_value() == target, target load(path) page.reload(wait_until='networkidle') assert page.locator('html').get_attribute('lang') == locale, path page.locator('.blog-breadcrumb a' if 'id' in a else '.blog-card h2 a').first.click() page.wait_for_load_state('networkidle') assert page.locator('html').get_attribute('lang') == locale, path page.go_back(wait_until='networkidle') assert page.url == base + path and page.locator('h1').text_content().strip() == title.removesuffix(' | STRATA'), path load(path) page.keyboard.press('Tab') assert page.locator('.blog-skip').evaluate('(el) => el === document.activeElement'), path page.keyboard.press('Enter') assert page.locator('#blog-main').evaluate('(el) => el === document.activeElement'), path rows.append({'path': path, 'status': response.status, 'locale': locale, 'title': title, 'titleCharacters': len(title), 'descriptionCharacters': len(description), 'h2': len(headings), 'renderedH2': page.locator('main h2').count(), 'tableKeyboardScrolling': True, 'correctionLinksValidated': True, 'firstAnswerY390': answer_y, 'canonical': 'https://text.skin' + path, 'robots': ('index' if indexing else 'noindex') + ', follow', 'hreflang': alternates, 'counterpartsTested': targets, 'widthsWithoutOverflow': [320, 390, 768, 1024, 1280, 1440], 'serviceCTA': cta_info if 'id' in a else None, 'screenshots': [shot + '-desktop.png', shot + '-mobile.png', shot + '-viewport.png']}) load('/fr/blogs') page.locator('button[aria-controls="site-mobile-menu"]:visible').click() page.locator('#site-mobile-menu a[href="/fr/services"]').click() page.wait_for_url(base + '/fr/services', wait_until='networkidle') page.go_back(wait_until='networkidle') assert page.url == base + '/fr/blogs' and page.locator('html').get_attribute('lang') == 'fr' assert page.locator('button[aria-controls="site-mobile-menu"]:visible').get_attribute('aria-expanded') == 'false' # Keep the specific isolated-API error and pre-existing app favicon failure in # the receipt. Both occur on /services, outside the blog implementation. # Do not suppress blog errors or any other resource/network failure. expected_preview_errors = [e for e in console_errors if re.fullmatch(re.escape(base) + r'/(?:[a-z]{2}/)?services', e['url']) and e['sourceUrl'] == 'http://127.0.0.1:9/api/vas/product/list-enable?size=1000' and e['error'] == 'Failed to load resource: net::ERR_UNSAFE_PORT'] known_app_errors = [e for e in console_errors if re.fullmatch(re.escape(base) + r'/(?:[a-z]{2}/)?services', e['url']) and e['sourceUrl'] == base + '/favicon.ico' and e['error'] == 'Failed to load resource: the server responded with a status of 404 (Not Found)'] unexpected_errors = [e for e in console_errors if e not in expected_preview_errors + known_app_errors] receipt = {'base': base, 'indexing': indexing, 'browser': browser.version, 'homepage': home_rows, 'pages': rows, 'internalLinkStatuses': links, 'pageErrors': errors, 'consoleErrors': console_errors, 'expectedPreviewErrors': expected_preview_errors, 'knownNonBlogErrors': known_app_errors, 'unexpectedConsoleErrors': unexpected_errors, 'authentication': 'Fresh logged-out context; no real login or booking availability checked'} (output / 'browser-results.json').write_text(json.dumps(receipt, ensure_ascii=False, indent=2)) assert not errors, errors assert not unexpected_errors, unexpected_errors browser.close() print(f'PASS: seven route-localized homepages and {len(rows)} real browser blog pages; all locale counterparts, metadata/schema/visible content, 320/390/768/1024/1280/1440px overflow, desktop navigation, contents/skip/menu/table/source keyboard controls, correction links, internal links, history/reload and no unexpected page/console errors. Expected offline API errors on services: {len(expected_preview_errors)}; known app favicon errors: {len(known_app_errors)}. Screenshots: {output}')