1
0

test_audio.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. SONG1 = 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3'
  4. SONG2 = 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3'
  5. def test_replace_audio(screen: Screen):
  6. with ui.row() as container:
  7. ui.audio(SONG1)
  8. def replace():
  9. container.clear()
  10. with container:
  11. ui.audio(SONG2)
  12. ui.button('Replace', on_click=replace)
  13. screen.open('/')
  14. assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-1.mp3')
  15. screen.click('Replace')
  16. screen.wait(0.5)
  17. assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-2.mp3')
  18. def test_change_source(screen: Screen):
  19. audio = ui.audio(SONG1)
  20. ui.button('Change source', on_click=lambda: audio.set_source(SONG2))
  21. screen.open('/')
  22. assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-1.mp3')
  23. screen.click('Change source')
  24. screen.wait(0.5)
  25. assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-2.mp3')