test_scene.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from selenium.common.exceptions import JavascriptException
  2. from nicegui import ui
  3. from .screen import Screen
  4. def test_moving_sphere_with_timer(screen: Screen):
  5. with ui.scene() as scene:
  6. sphere = scene.sphere().with_name('sphere')
  7. ui.timer(0.1, lambda: sphere.move(0, 0, sphere.z + 0.01))
  8. screen.open('/')
  9. def position() -> None:
  10. for _ in range(3):
  11. try:
  12. pos = screen.selenium.execute_script('return scene_3.getObjectByName("sphere").position.z')
  13. if pos is not None:
  14. return pos
  15. except JavascriptException as e:
  16. print(e.msg, flush=True)
  17. screen.wait(1.0)
  18. raise Exception('Could not get position')
  19. screen.wait(0.2)
  20. assert position() > 0
  21. def test_no_object_duplication_on_index_client(screen: Screen):
  22. with ui.scene() as scene:
  23. sphere = scene.sphere().move(0, -4, 0)
  24. ui.timer(0.1, lambda: sphere.move(0, sphere.y + 0.5, 0))
  25. screen.open('/')
  26. screen.wait(0.4)
  27. screen.switch_to(1)
  28. screen.open('/')
  29. screen.switch_to(0)
  30. screen.wait(0.2)
  31. assert screen.selenium.execute_script('return scene_3.children.length') == 5