1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# |
3
|
|
|
# Glances - An eye on your system |
4
|
|
|
# |
5
|
|
|
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <[email protected]> |
6
|
|
|
# |
7
|
|
|
# SPDX-License-Identifier: LGPL-3.0-only |
8
|
|
|
# |
9
|
|
|
|
10
|
|
|
"""Glances unitary tests suite for the WebUI.""" |
11
|
|
|
|
12
|
|
|
import os |
13
|
|
|
import tempfile |
14
|
|
|
import time |
15
|
|
|
|
16
|
|
|
import pytest |
17
|
|
|
from selenium.webdriver.common.by import By |
18
|
|
|
|
19
|
|
|
SCREENSHOT_RESOLUTIONS = [ |
20
|
|
|
# PC |
21
|
|
|
(640, 480), |
22
|
|
|
(800, 600), |
23
|
|
|
(1024, 768), |
24
|
|
|
(1600, 900), |
25
|
|
|
(1280, 1024), |
26
|
|
|
(1600, 1200), |
27
|
|
|
(1920, 1200), |
28
|
|
|
# IPHONE |
29
|
|
|
(750, 1334), # 8 |
30
|
|
|
(1080, 1920), # 8 Plus |
31
|
|
|
(1242, 2208), # XS |
32
|
|
|
(1125, 2436), # 11 Pro |
33
|
|
|
(1179, 2556), # 15 |
34
|
|
|
(1320, 2868), # 16 Pro Max |
35
|
|
|
# PIXEL Phone |
36
|
|
|
(1080, 2400), # Pixel 7 |
37
|
|
|
] |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
@pytest.fixture(scope="module") |
41
|
|
|
def glances_homepage(web_browser): |
42
|
|
|
time.sleep(3) |
43
|
|
|
web_browser.get("http://localhost:61234") |
44
|
|
|
return web_browser |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
def test_screenshot(glances_webserver, glances_homepage): |
48
|
|
|
""" |
49
|
|
|
Test Glances home page screenshot. |
50
|
|
|
""" |
51
|
|
|
glances_webserver is not None |
52
|
|
|
for resolution in SCREENSHOT_RESOLUTIONS: |
53
|
|
|
glances_homepage.set_window_size(*resolution) |
54
|
|
|
glances_homepage.save_screenshot( |
55
|
|
|
os.path.join(tempfile.gettempdir(), f"glances-{'-'.join(map(str, list(resolution)))}.png") |
56
|
|
|
) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
def test_loading_time(glances_webserver, glances_homepage): |
60
|
|
|
""" |
61
|
|
|
Test Glances home page loading time. |
62
|
|
|
""" |
63
|
|
|
assert glances_webserver is not None |
64
|
|
|
navigation_start = glances_homepage.execute_script("return window.performance.timing.navigationStart") |
65
|
|
|
response_start = glances_homepage.execute_script("return window.performance.timing.responseStart") |
66
|
|
|
dom_complete = glances_homepage.execute_script("return window.performance.timing.domComplete") |
67
|
|
|
backend_perf = response_start - navigation_start |
68
|
|
|
frontend_perf = dom_complete - response_start |
69
|
|
|
assert backend_perf < 1000 # ms |
70
|
|
|
assert frontend_perf < 1000 # ms |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
def test_title(glances_webserver, glances_homepage): |
74
|
|
|
""" |
75
|
|
|
Test Glances home page title. |
76
|
|
|
""" |
77
|
|
|
assert glances_webserver is not None |
78
|
|
|
assert "Glances" in glances_homepage.title |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
def test_plugins(glances_webserver, glances_homepage): |
82
|
|
|
""" |
83
|
|
|
Test Glances defaults plugins. |
84
|
|
|
""" |
85
|
|
|
assert glances_webserver is not None |
86
|
|
|
for plugin in [ |
87
|
|
|
"system", |
88
|
|
|
"now", |
89
|
|
|
"uptime", |
90
|
|
|
"quicklook", |
91
|
|
|
"cpu", |
92
|
|
|
"mem", |
93
|
|
|
"memswap", |
94
|
|
|
"load", |
95
|
|
|
"network", |
96
|
|
|
"diskio", |
97
|
|
|
"fs", |
98
|
|
|
"sensors", |
99
|
|
|
"processcount", |
100
|
|
|
"processlist", |
101
|
|
|
]: |
102
|
|
|
assert glances_homepage.find_element(By.ID, plugin) is not None |
103
|
|
|
|