File indexing completed on 2024-05-12 09:39:30

0001 #!/usr/bin/env python3
0002 
0003 # SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0004 # SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0005 # SPDX-License-Identifier: MIT
0006 
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 KDE_VERSION: Final = 6
0015 KCM_ID: Final = "kcm_users"
0016 
0017 
0018 class KCMUsersTest(unittest.TestCase):
0019     """
0020     Tests for kcm_users
0021     """
0022 
0023     driver: webdriver.Remote
0024 
0025     @classmethod
0026     def setUpClass(cls) -> None:
0027         """
0028         Opens the KCM and initialize the webdriver
0029         """
0030         options = AppiumOptions()
0031         options.set_capability("app", f"kcmshell{KDE_VERSION} {KCM_ID}")
0032         options.set_capability("timeouts", {'implicit': 10000})
0033         cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options)
0034 
0035     def tearDown(self) -> None:
0036         """
0037         Take screenshot when the current test fails
0038         """
0039         if not self._outcome.result.wasSuccessful():
0040             self.driver.get_screenshot_as_file(f"failed_test_shot_{KCM_ID}_#{self.id()}.png")
0041 
0042     @classmethod
0043     def tearDownClass(cls) -> None:
0044         """
0045         Make sure to terminate the driver again, lest it dangles.
0046         """
0047         cls.driver.quit()
0048 
0049     def test_0_open(self) -> None:
0050         """
0051         Tests the KCM can be opened
0052         """
0053         self.driver.find_element(AppiumBy.NAME, "Add New")
0054         self.driver.find_element(AppiumBy.NAME, "Name:")
0055         self.driver.find_element(AppiumBy.NAME, "Change Password")
0056         self.driver.find_element(AppiumBy.NAME, "Delete User…")
0057 
0058     def test_1_pictures_sheet_1_open(self) -> None:
0059         """
0060         Opens the avatar sheet
0061         """
0062         self.driver.find_element(AppiumBy.NAME, "Change avatar").click()
0063         self.driver.find_element(AppiumBy.NAME, "Choose File…")
0064         #  Doesn't work without account service
0065         # self.driver.find_element(AppiumBy.NAME, "Initials")
0066         # self.driver.find_element(AppiumBy.NAME, "Placeholder Icon")
0067 
0068 
0069 if __name__ == '__main__':
0070     unittest.main()