test_dependencies.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import pytest
  2. from nicegui import ui
  3. from selenium.common.exceptions import NoSuchElementException
  4. from .user import User
  5. def test_keyboard_before_startup(user: User):
  6. @ui.page('/')
  7. def page():
  8. ui.keyboard()
  9. user.open('/')
  10. assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  11. assert user.selenium.find_element_by_tag_name('span')
  12. def test_keyboard_after_startup(user: User):
  13. @ui.page('/')
  14. def page():
  15. def add_keyboard():
  16. with row:
  17. ui.keyboard()
  18. row = ui.row()
  19. ui.button('activate keyboard', on_click=add_keyboard)
  20. user.open('/')
  21. assert not any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  22. with pytest.raises(NoSuchElementException):
  23. user.selenium.find_element_by_tag_name('span')
  24. user.click('activate keyboard')
  25. assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  26. user.sleep(1)
  27. assert user.selenium.find_element_by_tag_name('span') # FIXME: ptw fails (which is correct) while pytest does not