File indexing completed on 2024-05-12 05:35:22

0001 #!/usr/bin/env python3
0002 
0003 # SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0004 # SPDX-License-Identifier: MIT
0005 
0006 import subprocess
0007 import sys
0008 import unittest
0009 
0010 from appium import webdriver
0011 from appium.options.common.base import AppiumOptions
0012 from appium.webdriver.common.appiumby import AppiumBy
0013 from desktoptest import start_kactivitymanagerd, start_kded
0014 from selenium.webdriver.support import expected_conditions as EC
0015 from selenium.webdriver.support.ui import WebDriverWait
0016 
0017 
0018 class Bug476968Test(unittest.TestCase):
0019     """
0020     plasmashell crashes when clicking configure button in System Tray settings window for applets without an overridden configure action
0021     """
0022 
0023     driver: webdriver.Remote
0024     kactivitymanagerd: subprocess.Popen | None = None
0025     kded: subprocess.Popen | None = None
0026 
0027     @classmethod
0028     def setUpClass(cls) -> None:
0029         """
0030         Initializes the webdriver and the desktop folder
0031         """
0032         cls.kactivitymanagerd = start_kactivitymanagerd()
0033         cls.kded = start_kded()
0034 
0035         options = AppiumOptions()
0036         options.set_capability("app", "plasmashell -p org.kde.plasma.desktop --no-respawn")
0037         options.set_capability("timeouts", {'implicit': 30000})
0038         cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options)
0039 
0040     def tearDown(self) -> None:
0041         """
0042         Take screenshot when the current test fails
0043         """
0044         if not self._outcome.result.wasSuccessful():
0045             self.driver.get_screenshot_as_file(f"failed_test_shot_bug476968_#{self.id()}.png")
0046 
0047     @classmethod
0048     def tearDownClass(cls) -> None:
0049         """
0050         Make sure to terminate the driver again, lest it dangles.
0051         """
0052         subprocess.check_output(["kquitapp6", "plasmashell"], stderr=sys.stderr)
0053         if cls.kded:
0054             cls.kded.kill()
0055         if cls.kactivitymanagerd:
0056             cls.kactivitymanagerd.kill()
0057         cls.driver.quit()
0058 
0059     def test_bug476968(self) -> None:
0060         wait = WebDriverWait(self.driver, 30)
0061         wait.until(EC.presence_of_element_located((AppiumBy.NAME, "Expand System Tray"))).click()  # plasma-workspace/applets/systemtray/package/contents/ui/ExpanderArrow.qml
0062         wait.until(EC.presence_of_element_located((AppiumBy.NAME, "Configure System Tray..."))).click()
0063         entries = wait.until(EC.presence_of_element_located((AppiumBy.NAME, "Entries")))
0064         entries.click()
0065         wait.until(EC.presence_of_element_located((AppiumBy.NAME, "Configure Camera Indicator..."))).click()
0066         wait.until_not(lambda _: entries.is_displayed())  # Wait until the old window closes
0067         wait.until(EC.presence_of_element_located((AppiumBy.NAME, "Camera Indicator Settings")))  # Window title
0068 
0069 
0070 if __name__ == '__main__':
0071     unittest.main()