tree_navigation_regression.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from playwright.sync_api import sync_playwright
  2. URL = "http://localhost:8765/view/全局分类树-需求热度与关系分析.html"
  3. def wait_until_ready(page):
  4. page.goto(URL)
  5. page.locator("#demand-count").wait_for(state="visible")
  6. page.wait_for_function(
  7. "document.querySelector('#demand-count').textContent.trim() !== '—'"
  8. )
  9. def test_level_scroll(page):
  10. wait_until_ready(page)
  11. page.locator('[data-start-depth="3"]').click()
  12. viewport = page.locator("#icicle-viewport")
  13. dimensions = viewport.evaluate(
  14. "(element) => ({clientHeight: element.clientHeight, scrollHeight: element.scrollHeight})"
  15. )
  16. assert dimensions["scrollHeight"] > dimensions["clientHeight"], dimensions
  17. assert page.locator("#map-context").text_content().startswith("从第 3 级开始")
  18. assert page.locator("body").get_attribute("data-start-depth") == "3"
  19. page.screenshot(path="/tmp/supplyagent-level-tree.png")
  20. page.locator("#icicle-canvas").hover(position={"x": 120, "y": 220})
  21. page.mouse.wheel(0, 900)
  22. page.wait_for_timeout(300)
  23. scroll_top = viewport.evaluate("(element) => element.scrollTop")
  24. assert scroll_top > 0, f"ordinary wheel did not scroll the long tree: {scroll_top}"
  25. before_scale = float(page.locator("body").get_attribute("data-view-scale"))
  26. page.keyboard.down("Control")
  27. page.mouse.wheel(0, -120)
  28. page.keyboard.up("Control")
  29. page.wait_for_timeout(100)
  30. after_scale = float(page.locator("body").get_attribute("data-view-scale"))
  31. assert after_scale > before_scale, (before_scale, after_scale)
  32. def test_demand_path_navigation(page):
  33. wait_until_ready(page)
  34. page.locator("#global-search").fill("节日")
  35. page.locator(".demand-card", has_text="节日").first.click()
  36. page.locator(".attachment-button").first.click()
  37. path_buttons = page.locator("[data-path-info-node]")
  38. count = path_buttons.count()
  39. assert count > 1, f"expected an ancestor path, got {count} nodes"
  40. parent_button = path_buttons.nth(count - 2)
  41. parent_name = parent_button.locator("strong").text_content().strip()
  42. parent_button.click()
  43. assert "visible" in page.locator(".demand-attachments").get_attribute("class")
  44. assert "节日" in page.locator(".demand-card.selected").text_content()
  45. current_name = page.locator("#breadcrumb-bar button.current").text_content().strip()
  46. assert current_name == parent_name, (current_name, parent_name)
  47. page.locator("#parent-view").click()
  48. higher_parent_name = (
  49. page.locator("#breadcrumb-bar button.current").text_content().strip()
  50. )
  51. assert higher_parent_name != parent_name
  52. assert "节日" in page.locator(".demand-card.selected").text_content()
  53. assert (
  54. page.locator("[data-path-info-node].active strong").text_content().strip()
  55. == higher_parent_name
  56. )
  57. page.screenshot(path="/tmp/supplyagent-demand-path.png", full_page=True)
  58. with sync_playwright() as playwright:
  59. browser = playwright.chromium.launch(
  60. headless=True,
  61. executable_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
  62. )
  63. page = browser.new_page(viewport={"width": 1600, "height": 1000})
  64. console_errors = []
  65. page.on(
  66. "console",
  67. lambda message: console_errors.append(message.text)
  68. if message.type == "error"
  69. else None,
  70. )
  71. test_level_scroll(page)
  72. test_demand_path_navigation(page)
  73. assert not console_errors, console_errors
  74. browser.close()