You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

128 line
4.0 KiB

  1. """
  2. Selenium-based test suite for Pannellum
  3. Dependencies:
  4. Python 3, Selenium Python bindings, Firefox, geckodriver, Pillow, NumPy
  5. """
  6. import http.server
  7. import time
  8. import threading
  9. import io
  10. import subprocess
  11. import os
  12. import numpy as np
  13. from PIL import Image, ImageChops
  14. from selenium import webdriver
  15. # Set to true to create a new set of reference images
  16. CREATE_REF = False
  17. # Run web server
  18. print("Starting web server...")
  19. os.chdir(os.path.dirname(os.path.abspath(__file__))) # cd to script dir
  20. os.chdir("..")
  21. httpd = http.server.HTTPServer(
  22. ("localhost", 8000), http.server.SimpleHTTPRequestHandler
  23. )
  24. thread = threading.Thread(None, httpd.serve_forever)
  25. thread.start()
  26. # Create a new instance of the Firefox driver
  27. print("Starting web driver...")
  28. fp = webdriver.FirefoxProfile()
  29. fp.set_preference("layout.css.devPixelsPerPx", "1.0")
  30. driver = webdriver.Firefox(firefox_profile=fp)
  31. driver.set_window_size(800, 600)
  32. def run_tests():
  33. # Load page
  34. print("Loading page...")
  35. driver.get("http://localhost:8000/tests/tests.html")
  36. # Make sure viewer loaded
  37. print("Running tests...")
  38. time.sleep(5)
  39. viewer = driver.find_element_by_id("panorama")
  40. assert driver.execute_script("return viewer.isLoaded()") == True
  41. # Check equirectangular
  42. assert driver.execute_script("return viewer.getScene() == 'equirectangular'")
  43. if CREATE_REF:
  44. viewer.screenshot("tests/equirectangular.png")
  45. subprocess.call(["optipng", "-o7", "-strip", "all", "equirectangular.png"])
  46. else:
  47. reference = Image.open("tests/equirectangular.png")
  48. screenshot = Image.open(io.BytesIO(viewer.screenshot_as_png)).convert("RGB")
  49. diff = np.mean(np.array(ImageChops.difference(screenshot, reference)))
  50. print("equirectangular difference:", diff)
  51. assert diff < 3
  52. print("PASS: equirectangular")
  53. # Check movement
  54. driver.execute_script("viewer.setPitch(30).setYaw(-20).setHfov(90)")
  55. time.sleep(2)
  56. assert driver.execute_script(
  57. "return viewer.getPitch() == 30 && viewer.getYaw() == -20 && viewer.getHfov() == 90"
  58. )
  59. driver.find_element_by_class_name("pnlm-zoom-in").click()
  60. time.sleep(1)
  61. assert driver.execute_script("return viewer.getHfov() == 85")
  62. driver.find_element_by_class_name("pnlm-zoom-out").click()
  63. time.sleep(1)
  64. assert driver.execute_script("return viewer.getHfov() == 90")
  65. print("PASS: movement")
  66. # Check look at
  67. driver.execute_script("viewer.lookAt(-10, 90, 100)")
  68. time.sleep(2)
  69. assert driver.execute_script(
  70. "return viewer.getPitch() == -10 && viewer.getYaw() == 90 && viewer.getHfov() == 100"
  71. )
  72. print("PASS: look at")
  73. # Check cube
  74. driver.execute_script("viewer.loadScene('cube')")
  75. time.sleep(5)
  76. assert driver.execute_script("return viewer.getScene() == 'cube'")
  77. if CREATE_REF:
  78. viewer.screenshot("tests/cube.png")
  79. subprocess.call(["optipng", "-o7", "-strip", "all", "cube.png"])
  80. else:
  81. reference = Image.open("tests/cube.png")
  82. screenshot = Image.open(io.BytesIO(viewer.screenshot_as_png)).convert("RGB")
  83. diff = np.mean(np.array(ImageChops.difference(screenshot, reference)))
  84. print("cube difference:", diff)
  85. assert diff < 3
  86. print("PASS: cube")
  87. # Check hot spot
  88. driver.find_element_by_class_name("pnlm-scene").click()
  89. time.sleep(5)
  90. assert driver.execute_script("return viewer.getScene() == 'multires'")
  91. print("PASS: hot spot")
  92. # Check multires
  93. if CREATE_REF:
  94. viewer.screenshot("tests/multires.png")
  95. subprocess.call(["optipng", "-o7", "-strip", "all", "multires.png"])
  96. else:
  97. reference = Image.open("tests/multires.png")
  98. screenshot = Image.open(io.BytesIO(viewer.screenshot_as_png)).convert("RGB")
  99. diff = np.mean(np.array(ImageChops.difference(screenshot, reference)))
  100. print("multires difference:", diff)
  101. assert diff < 3
  102. print("PASS: multires")
  103. try:
  104. run_tests()
  105. finally:
  106. driver.quit()
  107. httpd.shutdown()
  108. thread.join()