Skip to content

Commit

Permalink
Add Selenium test with different resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Jan 4, 2025
1 parent 3ad94bc commit e4bc144
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def glances_webserver():


@pytest.fixture(scope="session")
def firefox_browser():
def web_browser():
"""Init Firefox browser."""
opt = ChromeOptions()
opt.add_argument("--headless")
Expand Down
41 changes: 37 additions & 4 deletions tests/test_webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,49 @@

import os
import tempfile
import time

import pytest
from selenium.webdriver.common.by import By

SCREENSHOT_RESOLUTIONS = [
# PC
(640, 480),
(800, 600),
(1024, 768),
(1600, 900),
(1280, 1024),
(1600, 1200),
(1920, 1200),
# IPHONE
(750, 1334), # 8
(1080, 1920), # 8 Plus
(1242, 2208), # XS
(1125, 2436), # 11 Pro
(1179, 2556), # 15
(1320, 2868), # 16 Pro Max
# PIXEL Phone
(1080, 2400), # Pixel 7
]


@pytest.fixture(scope="module")
def glances_homepage(firefox_browser):
firefox_browser.get("http://localhost:61234")
firefox_browser.save_screenshot(os.path.join(tempfile.gettempdir(), "glances.png"))
return firefox_browser
def glances_homepage(web_browser):
time.sleep(3)
web_browser.get("http://localhost:61234")
return web_browser


def test_screenshot(glances_webserver, glances_homepage):
"""
Test Glances home page screenshot.
"""
glances_webserver is not None
for resolution in SCREENSHOT_RESOLUTIONS:
glances_homepage.set_window_size(*resolution)
glances_homepage.save_screenshot(
os.path.join(tempfile.gettempdir(), f"glances-{'-'.join(map(str, list(resolution)))}.png")
)


def test_loading_time(glances_webserver, glances_homepage):
Expand Down

0 comments on commit e4bc144

Please sign in to comment.