diff --git a/Makefile b/Makefile index 95dae853..f01e820f 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,9 @@ test-core: ## Run Core unit tests test-restful: ## Run Restful API unit tests $(PYTEST) tests/test_restful.py +test-webui: ## Run WebUI unit tests + $(PYTEST) tests/test_webui.py + test-xmlrpc: ## Run XMLRPC API unit tests $(PYTEST) tests/test_xmlrpc.py diff --git a/dev-requirements.txt b/dev-requirements.txt index df0ee950..fee1ee83 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -11,5 +11,7 @@ pyright pytest requirements-parser ruff +selenium semgrep setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability +webdriver-manager diff --git a/pyproject.toml b/pyproject.toml index 6b739447..7ebd2fc4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,10 +35,36 @@ urls.Homepage = "https://github.com/nicolargo/glances" [project.optional-dependencies] action = ["chevron"] +# all but not dev all = ["glances[action,browser,cloud,containers,export,gpu,graph,ip,raid,sensors,smart,snmp,sparklines,web,wifi]"] browser = ["zeroconf"] cloud = ["requests"] -containers = ["docker>=6.1.1", "packaging", "podman", "python-dateutil", "six"] +containers = [ + "docker>=6.1.1", + "packaging", + "podman", + "python-dateutil", + "six", +] +dev = [ + "codespell", + "fonttools>=4.43.0", + "gprof2dot", + "matplotlib", + "memory-profiler", + "numpy>=1.22.2", + "pillow>=10.0.1", + "pre-commit", + "py-spy", + "pyright", + "pytest", + "requirements-parser", + "ruff", + "selenium", + "semgrep", + "setuptools>=65.5.1", + "webdriver-manager", +] export = [ "bernhard", "cassandra-driver", @@ -64,7 +90,12 @@ sensors = ["batinfo; platform_system == 'Linux'"] smart = ["pySMART.smartx"] snmp = ["pysnmp-lextudio<6.2.0"] sparklines = ["sparklines"] -web = ["fastapi>=0.82.0", "jinja2", "requests", "uvicorn"] +web = [ + "fastapi>=0.82.0", + "jinja2", + "requests", + "uvicorn", +] wifi = ["wifi"] [project.scripts] diff --git a/requirements.txt b/requirements.txt index b45ab96c..5c443e38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ defusedxml packaging psutil>=5.6.7 +windows-curses; platform_system == 'Windows' diff --git a/tests/test_webui.py b/tests/test_webui.py new file mode 100755 index 00000000..e5a451fd --- /dev/null +++ b/tests/test_webui.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# +# Glances - An eye on your system +# +# SPDX-FileCopyrightText: 2024 Nicolas Hennion +# +# SPDX-License-Identifier: LGPL-3.0-only +# + +"""Glances unitary tests suite for the WebUI.""" + +import pytest +from selenium import webdriver +from selenium.webdriver import FirefoxOptions +from selenium.webdriver.firefox.service import Service as FirefoxService + + +@pytest.fixture() +def firefox_browser(): + """Init Firefox browser.""" + opts = FirefoxOptions() + opts.add_argument("--headless") + srv = FirefoxService(executable_path="/snap/bin/geckodriver") + driver = webdriver.Firefox(options=opts, service=srv) + + # Yield the WebDriver instance + driver.implicitly_wait(10) + yield driver + + # Close the WebDriver instance + driver.quit() + + +def test_title(firefox_browser): + """ + Test the title of the Python.org website + """ + firefox_browser.get("https://www.python.org") + assert firefox_browser.title == "Welcome to Python.org"