Test Failed
Push — develop ( c8a592...8fb49d )
by Nicolas
02:36 queued 14s
created

conftest.glances_webserver()   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nop 0
dl 0
loc 13
rs 9.8
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 os
19
import shlex
20
import subprocess
21
import time
22
23
import pytest
24
from selenium import webdriver
25
from selenium.webdriver import ChromeOptions
26
from selenium.webdriver.chrome.service import Service as ChromeService
27
28
from glances.main import GlancesMain
29
from glances.stats import GlancesStats
30
31
SERVER_PORT = 61234
32
URL = f"http://localhost:{SERVER_PORT}"
33
34
35
@pytest.fixture(scope="session")
36
def glances_stats():
37
    core = GlancesMain(args_begin_at=2)
38
    stats = GlancesStats(config=core.get_config(), args=core.get_args())
39
    yield stats
40
    stats.end()
41
42
43
@pytest.fixture(scope="session")
44
def glances_webserver():
45
    if os.path.isfile('./venv/bin/python'):
46
        cmdline = "./venv/bin/python"
47
    else:
48
        cmdline = "python"
49
    cmdline += f" -m glances -B 0.0.0.0 -w --browser -p {SERVER_PORT} -C ./conf/glances.conf"
50
    args = shlex.split(cmdline)
51
    pid = subprocess.Popen(args)
52
    time.sleep(3)
53
    yield pid
54
    pid.terminate()
55
    time.sleep(1)
56
57
58
@pytest.fixture(scope="session")
59
def firefox_browser():
60
    """Init Firefox browser."""
61
    opt = ChromeOptions()
62
    opt.add_argument("--headless")
63
    opt.add_argument("--start-maximized")
64
    srv = ChromeService()
65
    driver = webdriver.Chrome(options=opt, service=srv)
66
67
    # Yield the WebDriver instance
68
    driver.implicitly_wait(10)
69
    yield driver
70
71
    # Close the WebDriver instance
72
    driver.quit()
73