Falko Schindler 871f643375 code review hai 1 ano
..
README.md a77e3c6121 review %!s(int64=2) %!d(string=hai) anos
__init__.py 4f500e88d1 began with first selenium pytest %!s(int64=2) %!d(string=hai) anos
conftest.py 6ffe77f670 Merge pull request #1118 from zauberzeug/download_local_file hai 1 ano
requirements.txt 724d997513 add bs4 dependency %!s(int64=2) %!d(string=hai) anos
screen.py a58f056f25 add test for ui.select set_options hai 1 ano
test_aggrid.py 871f643375 code review hai 1 ano
test_api_router.py 240ddfa801 adding tests for APIRouter %!s(int64=2) %!d(string=hai) anos
test_audio.py bf007e09b4 #600 add pytests for replacing custom elements %!s(int64=2) %!d(string=hai) anos
test_auto_context.py 2ca3f765b7 another code review hai 1 ano
test_binding.py 3670653ec6 splitting screen.find and screen.should_contain_input %!s(int64=2) %!d(string=hai) anos
test_button.py 2ca3f765b7 another code review hai 1 ano
test_carousel.py 9c3ea230f5 add pytest hai 1 ano
test_chart.py 873999e08a test dynamic creation of elements with dependencies hai 1 ano
test_chat.py 16465fdc68 chat: translate newlines for non-HTML text only %!s(int64=2) %!d(string=hai) anos
test_color_input.py 595955a3ca fix pytests hai 1 ano
test_colors.py 8f2adf8253 #600 add unique key prop as a workaround %!s(int64=2) %!d(string=hai) anos
test_dark_mode.py 90453d7349 #783 add dark_mode pytest %!s(int64=2) %!d(string=hai) anos
test_date.py afe5023641 add pytest with dynamic props %!s(int64=2) %!d(string=hai) anos
test_dialog.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container %!s(int64=2) %!d(string=hai) anos
test_download.py da356b8c18 introduce single-use routes for ui.download hai 1 ano
test_element.py 0d9a8cee23 encode only what is necessary: &, <, >, ` hai 1 ano
test_endpoint_docs.py 6502de7d27 improve criterion for page route hai 1 ano
test_events.py 5383de7102 use Literal, Protocol, SupportsIndex and get_args from built-in typing package hai 1 ano
test_expansion.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container %!s(int64=2) %!d(string=hai) anos
test_favicon.py a74a9b5348 cleanup constants in Screen class hai 1 ano
test_header.py 6f62d2a777 add pytest for scroll padding hai 1 ano
test_helpers.py bde46be867 #1039 fix helpers.is_file for invalid file paths hai 1 ano
test_image.py bebc8f9e24 cleanup hai 1 ano
test_input.py 57b97e7a47 #1092 add test to reproduce the bug hai 1 ano
test_interactive_image.py bf007e09b4 #600 add pytests for replacing custom elements %!s(int64=2) %!d(string=hai) anos
test_javascript.py 95364b7003 clean up test, remove some waits, introduce alias wait_for %!s(int64=2) %!d(string=hai) anos
test_joystick.py 2ca3f765b7 another code review hai 1 ano
test_json.py 79ffcad490 #669 review %!s(int64=2) %!d(string=hai) anos
test_keyboard.py bd0dd2971f fix keyboard test (after removing the invisible element in a previous commit) %!s(int64=2) %!d(string=hai) anos
test_knob.py aad853b067 #424 add pytest %!s(int64=2) %!d(string=hai) anos
test_label.py cbd4a53031 #791 add pytest %!s(int64=2) %!d(string=hai) anos
test_lifecycle.py f854074b48 add test for startup and shutdown lifecycle hook %!s(int64=2) %!d(string=hai) anos
test_link.py f2eb6bb10b add pytest for linking to elements %!s(int64=2) %!d(string=hai) anos
test_log.py baf59020d2 fix another line duplication bug with ui.log hai 1 ano
test_markdown.py d06585905a try to fix flaky test hai 1 ano
test_mermaid.py 873999e08a test dynamic creation of elements with dependencies hai 1 ano
test_number.py 11013fbf7b fix pytest hai 1 ano
test_observables.py cdad18da6b add pytest for observable with async handler hai 1 ano
test_open.py a55a452a1c fix some more mypy issues hai 1 ano
test_page.py fc04d66a1d allow awaiting disconnect without connected hai 1 ano
test_plotly.py 3b81379878 remove numpy dependency where possible hai 1 ano
test_prod_js.py e696a48e88 rename prod_js parameter hai 1 ano
test_query.py 8df7d2546b #1293 fix ui.query with CSS variables hai 1 ano
test_radio.py 50bec3a1d3 fix value of ChoiceElements after changing options hai 1 ano
test_refreshable.py a4d4de8a32 try to fix pytests hai 1 ano
test_scene.py 34b3328cbe implement clear method for ui.scene hai 1 ano
test_select.py 919b606102 code review hai 1 ano
test_serving_files.py a74a9b5348 cleanup constants in Screen class hai 1 ano
test_spinner.py 1355cc1465 #368 introduce ui.spinner %!s(int64=2) %!d(string=hai) anos
test_splitter.py b03f70e027 #676 review, additional splitter example %!s(int64=2) %!d(string=hai) anos
test_stepper.py 72b6976a6b add pytest hai 1 ano
test_storage.py a74a9b5348 cleanup constants in Screen class hai 1 ano
test_table.py e05a3f3af2 update table selection when removing rows hai 1 ano
test_tabs.py 95de7d8330 code review hai 1 ano
test_tailwind.py f533a8bd57 #362 add pytests %!s(int64=2) %!d(string=hai) anos
test_time.py 17230d2523 add waits to reduce flakyness %!s(int64=2) %!d(string=hai) anos
test_timer.py 2fc1b29454 extend pytest hai 1 ano
test_toggle.py 50bec3a1d3 fix value of ChoiceElements after changing options hai 1 ano
test_upload.py bebc8f9e24 cleanup hai 1 ano
test_video.py bf007e09b4 #600 add pytests for replacing custom elements %!s(int64=2) %!d(string=hai) anos

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.