test_3d_scene.py 787 B

123456789101112131415161718192021222324252627
  1. from nicegui import ui
  2. from selenium.common.exceptions import JavascriptException
  3. from .screen import Screen
  4. def test_moving_sphere_with_timer(screen: Screen):
  5. with ui.scene() as scene:
  6. sphere = scene.sphere().move(0, -5, 2)
  7. ui.timer(0.03, lambda: sphere.move(sphere.x, sphere.y + 0.05, sphere.z))
  8. screen.open('/')
  9. def position() -> None:
  10. for _ in range(20):
  11. try:
  12. pos = screen.selenium.execute_script('return scene.children[4].position.y')
  13. if pos is not None:
  14. return pos
  15. except JavascriptException:
  16. pass
  17. screen.wait(0.1)
  18. raise Exception('Could not get position')
  19. pos = position()
  20. screen.wait(0.2)
  21. assert position() > pos