forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_scene.py
60 lines (47 loc) · 1.81 KB
/
test_scene.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from selenium.common.exceptions import JavascriptException
from nicegui import ui
from .screen import Screen
def test_moving_sphere_with_timer(screen: Screen):
with ui.scene() as scene:
sphere = scene.sphere().with_name('sphere')
ui.timer(0.1, lambda: sphere.move(0, 0, sphere.z + 0.01))
screen.open('/')
def position() -> None:
for _ in range(3):
try:
pos = screen.selenium.execute_script(f'return scene_{scene.id}.getObjectByName("sphere").position.z')
if pos is not None:
return pos
except JavascriptException as e:
print(e.msg, flush=True)
screen.wait(1.0)
raise Exception('Could not get position')
screen.wait(0.2)
assert position() > 0
def test_no_object_duplication_on_index_client(screen: Screen):
with ui.scene() as scene:
sphere = scene.sphere().move(0, -4, 0)
ui.timer(0.1, lambda: sphere.move(0, sphere.y + 0.5, 0))
screen.open('/')
screen.wait(0.4)
screen.switch_to(1)
screen.open('/')
screen.switch_to(0)
screen.wait(0.2)
assert screen.selenium.execute_script(f'return scene_{scene.id}.children.length') == 5
def test_no_object_duplication_with_page_builder(screen: Screen):
@ui.page('/')
def page():
global scene
with ui.scene() as scene:
sphere = scene.sphere().move(0, -4, 0)
ui.timer(0.1, lambda: sphere.move(0, sphere.y + 0.5, 0))
screen.open('/')
screen.wait(0.4)
screen.switch_to(1)
screen.open('/')
screen.switch_to(0)
screen.wait(0.2)
assert screen.selenium.execute_script(f'return scene_{scene.id}.children.length') == 5
screen.switch_to(1)
assert screen.selenium.execute_script(f'return scene_{scene.id}.children.length') == 5