-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #398 from MerginMaps/check-translation-banner
Script for translation banner
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Checking translated subpages for migration banner is visible | ||
# Before run, install playwright python package for e2e testing and html page parsing: | ||
# https://playwright.dev/python/docs/intro | ||
|
||
import os | ||
import sys | ||
from playwright.sync_api import sync_playwright | ||
|
||
CURRENT_PATH = os.path.abspath(__file__) | ||
DIR = os.path.join(os.path.dirname(os.path.dirname(CURRENT_PATH)), 'src') | ||
subpages = [] | ||
|
||
def test_translation_banner(): | ||
for root, subfolders, files in os.walk(DIR): | ||
if os.path.isdir(os.path.join(DIR, root)) and '.vuepress' not in os.path.normpath(os.path.join(DIR, root)): | ||
subpages.append(os.path.relpath(root, DIR).replace('.', '')) | ||
|
||
languages = ['de', 'es', 'fr', 'it', 'pt'] | ||
base_urls = ["https://{}.merginmaps.com/docs".format(lang) for lang in languages] | ||
|
||
problem_pages = [] | ||
with sync_playwright() as p: | ||
browser = p.chromium.launch() | ||
for base_url in base_urls: | ||
for subpage in subpages: | ||
url = base_url + '/' + subpage | ||
page = browser.new_page() | ||
page.goto(url) | ||
h1_element = page.locator('h1') | ||
h1_text = h1_element.inner_text() | ||
print('Testing {}'.format(url)) | ||
if h1_text!='404' and page.locator('.page-header').is_hidden(): | ||
problem_pages.append(url) | ||
|
||
if (len(problem_pages) > 0): | ||
print('Problem pages:') | ||
print(problem_pages) | ||
sys.exit(1) | ||
|
||
def main(): | ||
test_translation_banner() | ||
|
||
main() |