Falko Schindler 7b4a8d3f6a remove auto-close prop from `ui.context_menu` (fixes #3539) hai 9 meses
..
media 061242c2b2 use local files for testing `ui.interactive_image` (#3118) hai 1 ano
README.md 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
__init__.py 4f500e88d1 began with first selenium pytest %!s(int64=2) %!d(string=hai) anos
conftest.py b77d9d95da Integration test framework (#3121) hai 9 meses
requirements.txt 3a4d7637dc remove icecream dependency (#3439) hai 9 meses
test_add_html.py 3e5f92b23c Make libsass optional (#2809) hai 1 ano
test_aggrid.py 5c444ff538 Raise Exception when awaiting JavaScript on auto-index page (#2983) hai 1 ano
test_api_router.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_audio.py 42b3b4c61f add set_source tests for ui.video and ui.audio hai 1 ano
test_auto_context.py f7c08cfd97 UI context properties (#2905) hai 1 ano
test_awaitable_response.py bad0a87563 add documentation for NullResponse hai 1 ano
test_binding.py f1a5a0e40c add ruff checks hai 1 ano
test_button.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_button_dropdown.py 6e61721a3a refactor list and menu items (#2855) hai 1 ano
test_button_group.py 6e61721a3a refactor list and menu items (#2855) hai 1 ano
test_carousel.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_chat.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_chip.py 54c644f393 Add chip element (#2942) hai 1 ano
test_clipboard.py 5c444ff538 Raise Exception when awaiting JavaScript on auto-index page (#2983) hai 1 ano
test_code.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_codemirror.py 5c444ff538 Raise Exception when awaiting JavaScript on auto-index page (#2983) hai 1 ano
test_color_input.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_colors.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_context_menu.py 7b4a8d3f6a remove auto-close prop from `ui.context_menu` (fixes #3539) hai 9 meses
test_dark_mode.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_date.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_dialog.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_download.py 48e832ccb1 Provide two additional pytest plugins to make user and screen able to load independently (#3511) hai 9 meses
test_echart.py 614ea49b4b Initialization animation failure in ECharts (#3056) hai 1 ano
test_editor.py 63deabfd84 Fix value updates in ui.editor after client-side changes (#3346) hai 10 meses
test_element.py b77d9d95da Integration test framework (#3121) hai 9 meses
test_element_delete.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_element_filter.py b77d9d95da Integration test framework (#3121) hai 9 meses
test_endpoint_docs.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_events.py cd9e5472ad fix events on hidden and disabled elements (#3524) hai 9 meses
test_expansion.py d641cdfdac code review hai 1 ano
test_favicon.py 8c84ad412c fix favicon tests after removing bs4 hai 10 meses
test_header.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_helpers.py 5d25e54914 replace some HTTP links with HTTPS equivalents hai 1 ano
test_highchart.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_image.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_input.py a2544c1278 Replace repeated polling in Outbox.loop() with an asyncio event (see #2482) (#2867) hai 1 ano
test_interactive_image.py c83b95cbdd don't rely on flaky initial loaded event hai 1 ano
test_javascript.py 5c444ff538 Raise Exception when awaiting JavaScript on auto-index page (#2983) hai 1 ano
test_joystick.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_json.py da6932894d add pyflakes hai 1 ano
test_json_editor.py 5c444ff538 Raise Exception when awaiting JavaScript on auto-index page (#2983) hai 1 ano
test_keyboard.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_knob.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_label.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_leaflet.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_lifecycle.py 5c444ff538 Raise Exception when awaiting JavaScript on auto-index page (#2983) hai 1 ano
test_link.py 98e00b954b add pycodestyle hai 1 ano
test_list.py 6e61721a3a refactor list and menu items (#2855) hai 1 ano
test_log.py 4a67bc95ce New `ui.log` implementation (#2686) hai 1 ano
test_markdown.py 94cc62c831 [code-style] Introduce ruff as an isort replacement and add a pre-commit hook (#2619) hai 1 ano
test_menu.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_mermaid.py 5fc7c4478e Add optional config dictionary to mermaid component to be passed initialize() on mount (#3164) hai 11 meses
test_navigate.py 3e416522fa Implement ui.navigate functionality (#2593) hai 1 ano
test_notification.py 6139c65e81 try to fix flaky notification test hai 1 ano
test_number.py 3e9da97302 update `ui.number` after sanitization (#3389) hai 10 meses
test_observables.py 28253947f5 Implement __copy__ for observable collections (fixes #3023) (#3046) hai 1 ano
test_outbox.py 8eabbd9c12 add pytest hai 1 ano
test_page.py f7c08cfd97 UI context properties (#2905) hai 1 ano
test_page_title.py 2841869dc8 try to improve robustness of some pytests hai 1 ano
test_pagination.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_plotly.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_prod_js.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_query.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_radio.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_range.py 5f8a7b9e99 Add range control (#2762) hai 1 ano
test_refreshable.py 57fb4a6ac7 Merge pull request #2268 from zauberzeug/refreshable-method hai 1 ano
test_restructured_text.py 5d8644743d add pytest hai 1 ano
test_run.py d979476d87 Provide tests for run.io_bound and run.cpu_bound (#2234) hai 9 meses
test_scene.py da6932894d add pyflakes hai 1 ano
test_scene_view.py 48b6f769b7 Scene view component (#2947) hai 1 ano
test_select.py ed8c94cab4 Enable new_value_mode="add" for dict options (#2467) hai 1 ano
test_serving_files.py 94cc62c831 [code-style] Introduce ruff as an isort replacement and add a pre-commit hook (#2619) hai 1 ano
test_spinner.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_splitter.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_stepper.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_storage.py b77d9d95da Integration test framework (#3121) hai 9 meses
test_table.py 04649ebfd6 Adding methods to get computed props (#3395) hai 10 meses
test_tabs.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_tailwind.py b77d9d95da Integration test framework (#3121) hai 9 meses
test_teleport.py c30752af79 Introduce `ui.teleport` element (#3159) hai 11 meses
test_time.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_timeline.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_timer.py b77d9d95da Integration test framework (#3121) hai 9 meses
test_toggle.py 8d373eca7f update pytests to import Screen from nicegui.testing hai 1 ano
test_tree.py 167e1f885b allow filtering nodes (#3482) hai 9 meses
test_upload.py f4fc51c179 Adding upload_all argument for upload element (#2765) hai 1 ano
test_user_simulation.py 5e76d590e8 Support ui.select elements for user simulation tests (#3487) hai 9 meses
test_video.py 42b3b4c61f add set_source tests for ui.video and ui.audio hai 1 ano

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.