test_joystick.py 1.3 KB

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