Aaron Fuller a2544c1278 Replace repeated polling in Outbox.loop() with an asyncio event (see #2482) (#2867) hace 1 año
..
README.md 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
__init__.py 4f500e88d1 began with first selenium pytest hace 2 años
conftest.py f1a5a0e40c add ruff checks hace 1 año
requirements.txt 724d997513 add bs4 dependency hace 2 años
test_add_html.py 3e5f92b23c Make libsass optional (#2809) hace 1 año
test_aggrid.py 65942cd865 Allow passing functions to `run_method` calls (#2705) hace 1 año
test_api_router.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_audio.py 42b3b4c61f add set_source tests for ui.video and ui.audio hace 1 año
test_auto_context.py 98e00b954b add pycodestyle hace 1 año
test_awaitable_response.py bad0a87563 add documentation for NullResponse hace 1 año
test_binding.py f1a5a0e40c add ruff checks hace 1 año
test_button.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_button_dropdown.py 6e61721a3a refactor list and menu items (#2855) hace 1 año
test_button_group.py 6e61721a3a refactor list and menu items (#2855) hace 1 año
test_carousel.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_chat.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_clipboard.py 3e5f92b23c Make libsass optional (#2809) hace 1 año
test_code.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_color_input.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_colors.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_context_menu.py 6e61721a3a refactor list and menu items (#2855) hace 1 año
test_dark_mode.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_date.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_dialog.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_download.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_echart.py 294538e074 Add support for additional echart events (#2716) hace 1 año
test_editor.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_element.py 188c81b5b2 introduced delayed updates hace 1 año
test_element_delete.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_endpoint_docs.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_events.py f1a5a0e40c add ruff checks hace 1 año
test_expansion.py d641cdfdac code review hace 1 año
test_favicon.py 94cc62c831 [code-style] Introduce ruff as an isort replacement and add a pre-commit hook (#2619) hace 1 año
test_header.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_helpers.py e89b8ba410 fix more pylint issues hace 1 año
test_highchart.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_image.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_input.py a2544c1278 Replace repeated polling in Outbox.loop() with an asyncio event (see #2482) (#2867) hace 1 año
test_interactive_image.py a2ab6d8547 try to fix flaky interactive_image tests (again) hace 1 año
test_javascript.py a2544c1278 Replace repeated polling in Outbox.loop() with an asyncio event (see #2482) (#2867) hace 1 año
test_joystick.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_json.py da6932894d add pyflakes hace 1 año
test_json_editor.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_keyboard.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_knob.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_label.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_leaflet.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_lifecycle.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_link.py 98e00b954b add pycodestyle hace 1 año
test_list.py 6e61721a3a refactor list and menu items (#2855) hace 1 año
test_log.py 4a67bc95ce New `ui.log` implementation (#2686) hace 1 año
test_markdown.py 94cc62c831 [code-style] Introduce ruff as an isort replacement and add a pre-commit hook (#2619) hace 1 año
test_menu.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_mermaid.py da38b0c7cb allow handling Mermaid errors on the server hace 1 año
test_navigate.py 3e416522fa Implement ui.navigate functionality (#2593) hace 1 año
test_notification.py 0289142ad7 add test and documentation hace 1 año
test_number.py ee14497b1e update ui.number after changing its limits (#2753) hace 1 año
test_observables.py 7c3e01af16 add pylint checks hace 1 año
test_outbox.py 8eabbd9c12 add pytest hace 1 año
test_page.py da6932894d add pyflakes hace 1 año
test_page_title.py 2841869dc8 try to improve robustness of some pytests hace 1 año
test_pagination.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_plotly.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_prod_js.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_query.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_radio.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_range.py 5f8a7b9e99 Add range control (#2762) hace 1 año
test_refreshable.py 57fb4a6ac7 Merge pull request #2268 from zauberzeug/refreshable-method hace 1 año
test_restructured_text.py 5d8644743d add pytest hace 1 año
test_scene.py da6932894d add pyflakes hace 1 año
test_select.py ed8c94cab4 Enable new_value_mode="add" for dict options (#2467) hace 1 año
test_serving_files.py 94cc62c831 [code-style] Introduce ruff as an isort replacement and add a pre-commit hook (#2619) hace 1 año
test_spinner.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_splitter.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_stepper.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_storage.py f1a5a0e40c add ruff checks hace 1 año
test_table.py 1911455622 improve handling of special dtypes in from_pandas (fixes #2706) hace 1 año
test_tabs.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_tailwind.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_time.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_timeline.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_timer.py 429d67a7e6 automatically await async results in ui.timer (#2859) hace 1 año
test_toggle.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_tree.py 8d373eca7f update pytests to import Screen from nicegui.testing hace 1 año
test_upload.py f4fc51c179 Adding upload_all argument for upload element (#2765) hace 1 año
test_video.py 42b3b4c61f add set_source tests for ui.video and ui.audio hace 1 año

README.md

Automated Tests for NiceGUI

Motivation

Testing a user interface is hard work. But to ensure NiceGUI is working as expected it is of utmost importance. Even if automated testing needs a lot of infrastructure and results in long execution times, we believe that it's worth the effort when compared to manual testing.

Setup

Please be aware that the below commands install the latest version of the ChromeDriver binary, which is compatible with the version of Google Chrome installed on your system. If you have a different version of Chrome installed, you may need to install a different version of ChromeDriver or update your Chrome installation to be compatible with the installed ChromeDriver version.

Mac

cd nicegui # enter the project root dir
brew install cask chromedriver
python3 -m pip install -r tests/requirements.txt

Note: The above instructions assume that you have already installed Homebrew (a package manager for macOS) on your system. If you haven't, you can follow the instructions on https://brew.sh/ to install it.

Windows

cd nicegui # enter the project root dir
choco install chromedriver
python3 -m pip install -r tests/requirements.txt

Note: The above instructions assume that you have already installed Chocolatey (a package manager for Windows) on your system. If you haven't, you can follow the instructions on https://chocolatey.org/install to install it.

Linux

cd nicegui # enter the project root dir
sudo apt-get update
sudo apt-get install chromium-chromedriver
python3 -m pip install -r tests/requirements.txt

Note: The above instructions assume that you are using a Debian-based Linux distribution. If you are using a different distribution, the package manager and package names may differ. Please refer to the documentation for your distribution for more information.

Usage

Because Selenium queries are quite cumbersome and lengthy, we introduced a Screen class. This provides a high-level interface to work with the currently displayed state of the web browser. The workflow is as follows:

  1. Get the screen fixture by providing screen: Screen as an argument to the function.
  2. Write your NiceGUI code inside the function.
  3. Use screen.open(...) with the appropriate URL path to start querying the website.
  4. For example, use screen.should_contain(...) with some text as parameter to ensure that the text is shown.

Here is a very simple example:

from nicegui import ui
from nicegui.testing import Screen

def test_hello_world(screen: Screen):
    ui.label('Hello, world')

    screen.open('/')
    screen.should_contain('Hello, world')

Have a look at the existing tests for more examples. Internally we use selenium-fixture (see conftest.py). To access the webdriver directly you can use the screen.selenium property. Have a look at https://selenium-python.readthedocs.io/getting-started.html for documentation of the available method calls to the webdriver.