screen_documentation.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. from ..windows import python_window
  4. from . import doc
  5. @doc.part('Screen Fixture')
  6. def screen_fixture():
  7. ui.markdown('''
  8. The `screen` fixture starts a real (headless) browser to interact with your application.
  9. This is only necessary if you have browser-specific behavior to test.
  10. NiceGUI itself is thoroughly tested with this fixture to ensure each component works as expected.
  11. So only use it if you have to.
  12. ''').classes('bold-links arrow-links')
  13. with python_window(classes='w-[600px]', title='example'):
  14. ui.markdown('''
  15. ```python
  16. from selenium.webdriver.common.keys import Keys
  17. screen.open('/')
  18. screen.type(Keys.TAB) # to focus on the first input
  19. screen.type('user1')
  20. screen.type(Keys.TAB) # to focus the second input
  21. screen.type('pass1')
  22. screen.click('Log in')
  23. screen.should_contain('Hello user1!')
  24. screen.click('logout')
  25. screen.should_contain('Log in')
  26. ```
  27. ''')
  28. @doc.part('Web driver')
  29. def web_driver():
  30. ui.markdown('''
  31. The `screen` fixture uses Selenium under the hood.
  32. Currently it is only tested with the Chrome driver.
  33. To automatically use it for the tests we suggest to add the option `--driver Chrome` to your `pytest.ini`:
  34. ''').classes('bold-links arrow-links')
  35. with python_window(classes='w-[600px] h-42', title='pytest.ini'):
  36. ui.markdown('''
  37. ```ini
  38. [pytest]
  39. asyncio_mode = auto
  40. addopts = "--driver Chrome"
  41. ```
  42. ''')
  43. doc.reference(Screen)