Test Failed
Push — master ( 372380...7cfc0c )
by Nicolas
03:32
created

conftest.web_browser()   A

Complexity

Conditions 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nop 0
dl 0
loc 15
rs 9.9
c 0
b 0
f 0
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
Need chromedriver command line (example on Ubuntu system):
13
$ sudo apt install chromium-chromedriver
14
15
The chromedriver command line should be in your path (/usr/bin)
16
"""
17
18
import logging
19
import os
20
import shlex
21
import subprocess
22
import time
23
24
import pytest
25
from selenium import webdriver
26
from selenium.webdriver import ChromeOptions
27
from selenium.webdriver.chrome.service import Service as ChromeService
28
29
from glances.main import GlancesMain
30
from glances.stats import GlancesStats
31
32
SERVER_PORT = 61234
33
URL = f"http://localhost:{SERVER_PORT}"
34
35
36
@pytest.fixture(scope="session")
37
def logger():
38
    return logging.getLogger(__name__)
39
40
41
@pytest.fixture(scope="session")
42
def glances_stats():
43
    core = GlancesMain(args_begin_at=2)
44
    stats = GlancesStats(config=core.get_config(), args=core.get_args())
45
    yield stats
46
    stats.end()
47
48
49
@pytest.fixture(scope="module")
50
def glances_stats_no_history():
51
    core = GlancesMain(args_begin_at=2)
52
    args = core.get_args()
53
    args.time = 1
54
    args.cached_time = 1
55
    args.disable_history = True
56
    stats = GlancesStats(config=core.get_config(), args=args)
57
    yield stats
58
    stats.end()
59
60
61
@pytest.fixture(scope="session")
62
def glances_webserver():
63
    if os.path.isfile('./venv/bin/python'):
64
        cmdline = "./venv/bin/python"
65
    else:
66
        cmdline = "python"
67
    cmdline += f" -m glances -B 0.0.0.0 -w --browser -p {SERVER_PORT} -C ./conf/glances.conf"
68
    args = shlex.split(cmdline)
69
    pid = subprocess.Popen(args)
70
    time.sleep(3)
71
    yield pid
72
    pid.terminate()
73
    time.sleep(1)
74
75
76
@pytest.fixture(scope="session")
77
def web_browser():
78
    """Init Firefox browser."""
79
    opt = ChromeOptions()
80
    opt.add_argument("--headless")
81
    opt.add_argument("--start-maximized")
82
    srv = ChromeService()
83
    driver = webdriver.Chrome(options=opt, service=srv)
84
85
    # Yield the WebDriver instance
86
    driver.implicitly_wait(10)
87
    yield driver
88
89
    # Close the WebDriver instance
90
    driver.quit()
91