File indexing completed on 2024-04-28 05:27:10
0001 #!/usr/bin/env python3 0002 0003 # SPDX-FileCopyrightText: 2024 Fushan Wen <qydwhotmail@gmail.com> 0004 # SPDX-License-Identifier: MIT 0005 0006 import subprocess 0007 import unittest 0008 from typing import Final 0009 0010 from appium import webdriver 0011 from appium.options.common.base import AppiumOptions 0012 from appium.webdriver.common.appiumby import AppiumBy 0013 0014 WIDGET_ID: Final = "org.kde.plasma.keyboardindicator" 0015 0016 0017 class KeyboardIndicatorTest(unittest.TestCase): 0018 0019 driver: webdriver.Remote 0020 0021 @classmethod 0022 def setUpClass(cls) -> None: 0023 options = AppiumOptions() 0024 options.set_capability("app", f"plasmawindowed -p org.kde.plasma.nano {WIDGET_ID}") 0025 options.set_capability("environ", { 0026 "QT_FATAL_WARNINGS": "1", 0027 "QT_LOGGING_RULES": "qt.accessibility.atspi.warning=false;qt.dbus.integration.warning=false;kf.plasma.core.warning=false;kf.windowsystem.warning=false;kf.kirigami.platform.warning=false", 0028 }) 0029 options.set_capability("timeouts", {'implicit': 10000}) 0030 cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options) 0031 0032 @classmethod 0033 def tearDownClass(cls) -> None: 0034 # Make sure to terminate the driver again, lest it dangles. 0035 cls.driver.quit() 0036 0037 def tearDown(self) -> None: 0038 pass 0039 0040 def test_1_caps_lock(self) -> None: 0041 self.driver.find_element(AppiumBy.NAME, "No lock keys activated") 0042 subprocess.check_call(["xdotool", "key", "Caps_Lock"]) 0043 self.driver.find_element(AppiumBy.NAME, "Caps Lock activated") 0044 subprocess.check_call(["xdotool", "key", "Caps_Lock"]) 0045 self.driver.find_element(AppiumBy.NAME, "No lock keys activated") 0046 0047 def test_2_num_lock(self) -> None: 0048 """ 0049 Num lock indicator is disabled by default 0050 """ 0051 self.driver.find_element(AppiumBy.NAME, "No lock keys activated") 0052 subprocess.check_call(["xdotool", "key", "Num_Lock"]) 0053 self.driver.find_element(AppiumBy.NAME, "No lock keys activated") 0054 subprocess.check_call(["xdotool", "key", "Num_Lock"]) 0055 self.driver.find_element(AppiumBy.NAME, "No lock keys activated") 0056 0057 0058 if __name__ == '__main__': 0059 unittest.main()