瀏覽代碼

extended keyboard test

Rodja Trappe 2 年之前
父節點
當前提交
9aa9eca4d0
共有 2 個文件被更改,包括 10 次插入3 次删除
  1. 8 2
      tests/test_element.py
  2. 2 1
      tests/user.py

+ 8 - 2
tests/test_element.py

@@ -1,14 +1,20 @@
+
 from nicegui import ui
+from selenium.webdriver.common.action_chains import ActionChains
+from selenium.webdriver.common.keys import Keys
 
 from .user import User
 
 
 def test_keyboard(user: User):
-    ui.keyboard()
+    result = ui.label('')
+    ui.keyboard(on_key=lambda e: result.set_text(f'{e.key, e.action}'))
 
     user.open('/')
     assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
-    assert user.selenium.find_element_by_tag_name('span')
+    assert user.selenium.find_element_by_tag_name('span')  # NOTE keyboard dom element is a span
+    ActionChains(user.selenium).send_keys('t').perform()
+    user.should_see('t, KeyboardAction(keydown=False, keyup=True, repeat=False)')
 
 
 def test_classes(user: User):

+ 2 - 1
tests/user.py

@@ -44,7 +44,8 @@ class User():
                     raise RuntimeError('The NiceGUI server has stopped running')
 
     def should_see(self, text: str) -> None:
-        assert self.selenium.title == text or self.find(text).text == text
+        assert self.selenium.title == text or self.find(text), \
+            f'could not find "{text}" on:\n{self.page()}'
 
     def should_not_see(self, text: str) -> None:
         assert self.selenium.title != text