Skip to content

Commit

Permalink
add better info about how to write a complete test
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Oct 23, 2024
1 parent 43e73f2 commit db0ca00
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions website/documentation/content/user_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def user_fixture():
ui.markdown('''
We recommend utilizing the `user` fixture instead of the [`screen` fixture](/documentation/screen) wherever possible
because execution is as fast as unit tests and it does not need Selenium as a dependency
when loaded via `pytest_plugins = ['nicegui.testing.user_plugin']`
(see [project structure](/documentation/project_structure)).
when loaded via `pytest_plugins = ['nicegui.testing.user_plugin']`.
The `user` fixture cuts away the browser and replaces it by a lightweight simulation entirely in Python.
See [project structure](/documentation/project_structure) for a description of the setup.
You can assert to "see" specific elements or content, click buttons, type into inputs and trigger events.
We aimed for a nice API to write acceptance tests which read like a story and are easy to understand.
Expand All @@ -23,12 +23,13 @@ def user_fixture():
with python_window(classes='w-[600px]', title='example'):
ui.markdown('''
```python
await user.open('/')
user.find('Username').type('user1')
user.find('Password').type('pass1').trigger('keydown.enter')
await user.should_see('Hello user1!')
user.find('logout').click()
await user.should_see('Log in')
async def test_login(user: User) -> None:
await user.open('/')
user.find('Username').type('user1')
user.find('Password').type('pass1').trigger('keydown.enter')
await user.should_see('Hello user1!')
user.find('logout').click()
await user.should_see('Log in')
```
''')

Expand Down

0 comments on commit db0ca00

Please sign in to comment.