Falko Schindler 369ee5d9f1 Merge branch 'main' into dependencies 2 years ago
..
README.md a77e3c6121 review 2 years ago
__init__.py 4f500e88d1 began with first selenium pytest 2 years ago
conftest.py 947873a316 #287 disabling implicit wait for input query 2 years ago
input.py 79a5a91b8d re-organize tests 2 years ago
requirements.txt 2befacffb4 #432 some clarifications 2 years ago
screen.py e155c80da5 code review 2 years ago
test_aggrid.py 98d23c3352 #370 deprecate ui.table, rename it into ui.aggrid 2 years ago
test_auto_context.py d769250b0a #524 try make auto-context test more reliable 2 years ago
test_binding.py 3670653ec6 splitting screen.find and screen.should_contain_input 2 years ago
test_chart.py d41b923825 #284 add test for stock chart 2 years ago
test_color_input.py b4b3ea5b23 adding color picker tests 2 years ago
test_date.py ab78da0ff6 fix date tests by setting a default year and month 2 years ago
test_dialog.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container 2 years ago
test_element.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container 2 years ago
test_events.py 95364b7003 clean up test, remove some waits, introduce alias wait_for 2 years ago
test_expansion.py 3c00a8619b #338 introduce outbox; update elements during initialization, not when leaving container 2 years ago
test_image.py 79a5a91b8d re-organize tests 2 years ago
test_input.py 880bfe5ad2 #336 add test 2 years ago
test_interactive_image.py 6d97db659c #488 fix lost source after tab change 2 years ago
test_javascript.py 95364b7003 clean up test, remove some waits, introduce alias wait_for 2 years ago
test_joystick.py 79a5a91b8d re-organize tests 2 years ago
test_json.py dde5cf25b1 fixed quotes and improved except-clause 2 years ago
test_keyboard.py bd0dd2971f fix keyboard test (after removing the invisible element in a previous commit) 2 years ago
test_knob.py aad853b067 #424 add pytest 2 years ago
test_label.py e567329c8c fix some page tests 2 years ago
test_lifecycle.py f854074b48 add test for startup and shutdown lifecycle hook 2 years ago
test_link.py 908899e30c #273 adding test for opening link in new tab 2 years ago
test_log.py de84175caa #414 let ui.log.clear() remove all lines 2 years ago
test_markdown.py e3ac541aed make "Markdown" uppercase 2 years ago
test_mermaid.py ed05443b2a #228 add markdown and mermaid tests 2 years ago
test_page.py 08c6eaf62a #445 provide global exception handler 2 years ago
test_plotly.py e1b3bac74f Support fallback to Python's json module if orjson not available 2 years ago
test_scene.py 855c8fc6d9 apply some sourcery.ai-inspired refactorings 2 years ago
test_spinner.py 1355cc1465 #368 introduce ui.spinner 2 years ago
test_table.py 7c7bda4c95 #500 wait for the row to disappear 2 years ago
test_tabs.py 438b1f1fb1 #251 add pytest 2 years ago
test_time.py 95364b7003 clean up test, remove some waits, introduce alias wait_for 2 years ago
test_timer.py 7bf214ef7d code review 2 years ago
test_toggle.py 79a5a91b8d re-organize tests 2 years ago
test_upload.py 95364b7003 clean up test, remove some waits, introduce alias wait_for 2 years ago

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.