From 42c92f3fc950f0251df66b7949f388c6c53ab506 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 25 Mar 2026 14:51:29 +0100 Subject: [PATCH] Create new dedicated tests/test_screenshot.py --- tests/test_screenshot.py | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/test_screenshot.py diff --git a/tests/test_screenshot.py b/tests/test_screenshot.py new file mode 100644 index 00000000..bcff9538 --- /dev/null +++ b/tests/test_screenshot.py @@ -0,0 +1,69 @@ +""" +Graphical test for screenshot capture. + +This test focuses on screenshot capture for visual regression testing. + +Usage: + Desktop: ./tests/unittest.sh tests/test_screenshot.py + Device: ./tests/unittest.sh tests/test_screenshot.py --ondevice +""" + +import os +import sys +import unittest +import mpos.ui +from mpos import AppManager, DeviceInfo, capture_screenshot, wait_for_render + + +class TestScreenshotCapture(unittest.TestCase): + """Test suite for screenshot capture.""" + + def setUp(self): + """Set up test fixtures before each test method.""" + if sys.platform == "esp32": + self.screenshot_dir = "tests/screenshots" + else: + self.screenshot_dir = "../tests/screenshots" + + try: + os.mkdir(self.screenshot_dir) + except OSError: + pass + + self.hardware_id = DeviceInfo.hardware_id + print(f"Testing with hardware ID: {self.hardware_id}") + + def tearDown(self): + """Clean up after each test method.""" + try: + mpos.ui.back_screen() + wait_for_render(5) + except Exception: + pass + + def test_capture_about_app_screenshot(self): + """Capture screenshot of the About app for regression testing.""" + print("\n=== Starting About app screenshot test ===") + + result = AppManager.start_app("com.micropythonos.about") + self.assertTrue(result, "Failed to start About app") + + wait_for_render(iterations=15) + + screenshot_path = f"{self.screenshot_dir}/about_app_{self.hardware_id}.raw" + print(f"\nCapturing screenshot to: {screenshot_path}") + + try: + buffer = capture_screenshot(screenshot_path, width=320, height=240) + print(f"Screenshot captured: {len(buffer)} bytes") + + stat = os.stat(screenshot_path) + self.assertTrue( + stat[6] > 0, + "Screenshot file is empty", + ) + print(f"Screenshot file size: {stat[6]} bytes") + except Exception as exc: + self.fail(f"Failed to capture screenshot: {exc}") + + print("\n=== About app screenshot test completed successfully ===")