File indexing completed on 2024-05-12 09:39:30
0001 #!/usr/bin/env python3 0002 0003 # SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com> 0004 # SPDX-License-Identifier: MIT 0005 0006 import unittest 0007 from typing import Final 0008 0009 from appium import webdriver 0010 from appium.options.common.base import AppiumOptions 0011 from appium.webdriver.common.appiumby import AppiumBy 0012 0013 WIDGET_ID: Final = "org.kde.plasma.lock_logout" 0014 0015 0016 class LockLogoutTest(unittest.TestCase): 0017 """ 0018 Tests for the lock/logout widget 0019 """ 0020 0021 driver: webdriver.Remote 0022 0023 @classmethod 0024 def setUpClass(cls) -> None: 0025 """ 0026 Opens the widget and initialize the webdriver 0027 """ 0028 options = AppiumOptions() 0029 options.set_capability("app", f"plasmawindowed -p org.kde.plasma.nano {WIDGET_ID}") 0030 options.set_capability("environ", { 0031 "QT_FATAL_WARNINGS": "1", 0032 "QT_LOGGING_RULES": "qt.accessibility.atspi.warning=false;kf.plasma.core.warning=false;kf.windowsystem.warning=false;kf.kirigami.platform.warning=false", 0033 }) 0034 options.set_capability("timeouts", {'implicit': 10000}) 0035 cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options) 0036 0037 def tearDown(self) -> None: 0038 """ 0039 Take screenshot when the current test fails 0040 """ 0041 if not self._outcome.result.wasSuccessful(): 0042 self.driver.get_screenshot_as_file(f"failed_test_shot_{WIDGET_ID}_#{self.id()}.png") 0043 0044 @classmethod 0045 def tearDownClass(cls) -> None: 0046 """ 0047 Make sure to terminate the driver again, lest it dangles. 0048 """ 0049 cls.driver.quit() 0050 0051 def test_0_open(self) -> None: 0052 """ 0053 Tests the widget can be opened 0054 """ 0055 self.driver.find_element(AppiumBy.NAME, "Lock") 0056 self.driver.find_element(AppiumBy.NAME, "Shutdown…") 0057 0058 0059 if __name__ == '__main__': 0060 unittest.main()