verify_translation.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from playwright.sync_api import sync_playwright, expect
  2. import time
  3. import re
  4. def run(playwright):
  5. browser = playwright.chromium.launch(headless=True)
  6. context = browser.new_context()
  7. page = context.new_page()
  8. # Go to the page and wait for it to be ready
  9. page.goto("http://localhost:5173", wait_until="networkidle")
  10. print("Page loaded")
  11. # Use a regex to find the button by its aria-label in either Chinese or English.
  12. language_button = page.get_by_role(
  13. "button",
  14. name=re.compile(r"(切换语言|Change Language)", re.IGNORECASE),
  15. )
  16. # Wait for the button to be visible
  17. expect(language_button).to_be_visible()
  18. print("Language button found")
  19. language_button.click()
  20. print("Language button clicked")
  21. # Click the "Français" option
  22. french_option = page.get_by_role("menuitem", name="Français")
  23. expect(french_option).to_be_visible()
  24. print("French option found")
  25. french_option.click()
  26. print("French option clicked")
  27. # Wait for the language switch to apply
  28. time.sleep(2) # Wait for 2 seconds
  29. # Now the aria-label should be in French
  30. expect(page.get_by_role("button", name="Changer de langue")).to_be_visible(timeout=10000)
  31. print("Language changed to French")
  32. # Take a screenshot to see the page state
  33. page.screenshot(path="jules-scratch/verification/verification.png")
  34. print("Screenshot taken")
  35. browser.close()
  36. with sync_playwright() as playwright:
  37. run(playwright)