From db0ca00de4690b2dc3a96e5a6efb7c2c5980ce0f Mon Sep 17 00:00:00 2001 From: Rodja Trappe Date: Wed, 23 Oct 2024 15:48:38 +0200 Subject: [PATCH] add better info about how to write a complete test --- .../documentation/content/user_documentation.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/website/documentation/content/user_documentation.py b/website/documentation/content/user_documentation.py index 245f4a50c..e3c3543d2 100644 --- a/website/documentation/content/user_documentation.py +++ b/website/documentation/content/user_documentation.py @@ -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. @@ -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') ``` ''')