File indexing completed on 2024-05-19 09:30:06
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 KDE_VERSION: Final = 6 0014 KCM_ID: Final = "kcm_nightcolor" 0015 0016 0017 class KCMNightColorTest(unittest.TestCase): 0018 """ 0019 Tests for kcm_nightcolor 0020 """ 0021 0022 driver: webdriver.Remote 0023 0024 @classmethod 0025 def setUpClass(cls) -> None: 0026 """ 0027 Opens the KCM and initialize the webdriver 0028 """ 0029 options = AppiumOptions() 0030 options.set_capability("app", f"kcmshell{KDE_VERSION} {KCM_ID}") 0031 options.set_capability("timeouts", {'implicit': 10000}) 0032 cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options) 0033 0034 def tearDown(self) -> None: 0035 """ 0036 Take screenshot when the current test fails 0037 """ 0038 if not self._outcome.result.wasSuccessful(): 0039 self.driver.get_screenshot_as_file(f"failed_test_shot_{KCM_ID}_#{self.id()}.png") 0040 0041 @classmethod 0042 def tearDownClass(cls) -> None: 0043 """ 0044 Make sure to terminate the driver again, lest it dangles. 0045 """ 0046 cls.driver.quit() 0047 0048 def test_0_open(self) -> None: 0049 """ 0050 Tests the KCM can be opened 0051 """ 0052 self.driver.find_element(AppiumBy.NAME, "The blue light filter makes the colors on the screen warmer.") 0053 self.driver.find_element(AppiumBy.NAME, "Day light temperature:") 0054 self.driver.find_element(AppiumBy.NAME, "Night light temperature:") 0055 0056 0057 if __name__ == '__main__': 0058 unittest.main()