Falko Schindler 1eea655544 #906 add pytest пре 2 година
..
README.md a77e3c6121 review пре 2 година
__init__.py 4f500e88d1 began with first selenium pytest пре 2 година
conftest.py 81d1eb3a0e implement persistence using observable dicts пре 2 година
requirements.txt 724d997513 add bs4 dependency пре 2 година
screen.py 384f36b34f providing default favicon route only once пре 2 година
test_aggrid.py 9feaa17532 try to fix flaky aggrid test пре 2 година
test_api_router.py 240ddfa801 adding tests for APIRouter пре 2 година
test_audio.py bf007e09b4 #600 add pytests for replacing custom elements пре 2 година
test_auto_context.py 93bcb8490c trying alternative implementation of test пре 2 година
test_binding.py 3670653ec6 splitting screen.find and screen.should_contain_input пре 2 година
test_button.py 38d6c5c2f8 #560 add pytest пре 2 година
test_chart.py d5121a56d4 #948 add pytest пре 2 година
test_chat.py 16465fdc68 chat: translate newlines for non-HTML text only пре 2 година
test_color_input.py 6f254ff59d #603 make pytest more flexible пре 2 година
test_colors.py 8f2adf8253 #600 add unique key prop as a workaround пре 2 година
test_dark_mode.py 90453d7349 #783 add dark_mode pytest пре 2 година
test_date.py afe5023641 add pytest with dynamic props пре 2 година
test_dialog.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container пре 2 година
test_download.py d18347bb6b #656 introduce ui.download пре 2 година
test_element.py 927cd3e73f introduce element.move() пре 2 година
test_events.py 050767966d #751 introduce throttle options "leading_events" and "trailing_events" пре 2 година
test_expansion.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container пре 2 година
test_favicon.py a0a8a823ae add support for data urls пре 2 година
test_helpers.py 4a4d75da73 helpers.is_port_open must return False on bad ip пре 2 година
test_image.py 79a5a91b8d re-organize tests пре 2 година
test_input.py d6b8d0479c #300 add pytests пре 2 година
test_interactive_image.py bf007e09b4 #600 add pytests for replacing custom elements пре 2 година
test_javascript.py 95364b7003 clean up test, remove some waits, introduce alias wait_for пре 2 година
test_joystick.py d5d65ff5f7 introduce screen.find_by_id пре 2 година
test_json.py 79ffcad490 #669 review пре 2 година
test_keyboard.py bd0dd2971f fix keyboard test (after removing the invisible element in a previous commit) пре 2 година
test_knob.py aad853b067 #424 add pytest пре 2 година
test_label.py cbd4a53031 #791 add pytest пре 2 година
test_lifecycle.py f854074b48 add test for startup and shutdown lifecycle hook пре 2 година
test_link.py f2eb6bb10b add pytest for linking to elements пре 2 година
test_log.py 1eea655544 #906 add pytest пре 2 година
test_markdown.py bf007e09b4 #600 add pytests for replacing custom elements пре 2 година
test_mermaid.py bf007e09b4 #600 add pytests for replacing custom elements пре 2 година
test_number.py d6b8d0479c #300 add pytests пре 2 година
test_observables.py 8fdb504673 try to fix pytests пре 2 година
test_page.py 040f43b984 review пре 2 година
test_plotly.py bf007e09b4 #600 add pytests for replacing custom elements пре 2 година
test_query.py 34291fc849 #411 add pytests пре 2 година
test_refreshable.py eef48de6c8 #938 add pytest пре 2 година
test_scene.py 8f2adf8253 #600 add unique key prop as a workaround пре 2 година
test_select.py 55555a749f let ui.select support "multiple" prop пре 2 година
test_spinner.py 1355cc1465 #368 introduce ui.spinner пре 2 година
test_splitter.py b03f70e027 #676 review, additional splitter example пре 2 година
test_storage.py 81d1eb3a0e implement persistence using observable dicts пре 2 година
test_table.py 9f955f90c5 #609 fix table tests пре 2 година
test_tabs.py 438b1f1fb1 #251 add pytest пре 2 година
test_tailwind.py f533a8bd57 #362 add pytests пре 2 година
test_time.py 17230d2523 add waits to reduce flakyness пре 2 година
test_timer.py 7bf214ef7d code review пре 2 година
test_toggle.py 79a5a91b8d re-organize tests пре 2 година
test_upload.py a22717ee7f #787 fix ui.upload behind reverse proxy with subpath пре 2 година
test_video.py bf007e09b4 #600 add pytests for replacing custom elements пре 2 година

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 .screen 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.