1
0

test_joystick.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from selenium.webdriver.common.action_chains import ActionChains
  2. from nicegui import ui
  3. from nicegui.testing import Screen
  4. def test_joystick(screen: Screen):
  5. j = ui.joystick(on_move=lambda e: coordinates.set_text(f'move {e.x:.3f}, {e.y:.3f}'),
  6. on_end=lambda _: coordinates.set_text('end 0, 0'))
  7. coordinates = ui.label('start 0, 0')
  8. screen.open('/')
  9. joystick = screen.find_element(j)
  10. assert joystick
  11. screen.should_contain('start 0, 0')
  12. ActionChains(screen.selenium) \
  13. .move_to_element_with_offset(joystick, 25, 25) \
  14. .click_and_hold() \
  15. .pause(1) \
  16. .move_by_offset(20, 20) \
  17. .pause(1) \
  18. .perform()
  19. screen.should_contain('move 0.400, -0.400')
  20. ActionChains(screen.selenium) \
  21. .move_to_element_with_offset(joystick, 25, 25) \
  22. .click() \
  23. .perform()
  24. screen.should_contain('end 0, 0')
  25. def test_styling_joystick(screen: Screen):
  26. j = ui.joystick().style('background-color: gray;').classes('shadow-lg')
  27. screen.open('/')
  28. joystick = screen.find_element(j)
  29. assert 'background-color: gray;' in joystick.get_attribute('style')
  30. assert 'shadow-lg' in joystick.get_attribute('class')