test_scene.py 1.1 KB

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