File indexing completed on 2024-05-12 05:36:59
0001 #!/usr/bin/env python3 0002 0003 # SPDX-License-Identifier: MIT 0004 # SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org> 0005 # SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org> 0006 0007 import subprocess 0008 import sys 0009 import unittest 0010 import os 0011 0012 from appium import webdriver 0013 from appium.options.common.base import AppiumOptions 0014 from appium.webdriver.common.appiumby import AppiumBy 0015 0016 KDE_INSTALL_FULL_LIBEXECDIR = os.environ.get("KDE_INSTALL_FULL_LIBEXECDIR", "/usr/libexec") 0017 0018 class LogoutGreeterTests(unittest.TestCase): 0019 0020 def setUp(self): 0021 self.proc = subprocess.Popen(["{}/ksmserver-logout-greeter".format(KDE_INSTALL_FULL_LIBEXECDIR), "--windowed"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 0022 options = AppiumOptions() 0023 options.set_capability("app", str(self.proc.pid)) 0024 options.set_capability("timeouts", {'implicit': 10000}) 0025 self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options) 0026 0027 def tearDown(self): 0028 self.driver.quit() 0029 self.assertEqual(self.proc.returncode != None, True) 0030 try: 0031 self.proc.terminate() 0032 except subprocess.TimeoutExpired: 0033 self.proc.kill() 0034 if not self._outcome.result.wasSuccessful(): 0035 self.driver.get_screenshot_as_file(f"failed_test_shot_logoutgreetertest_{self.id()}.png") 0036 0037 def assertStdOutLine(self, expected): 0038 out, err = self.proc.communicate() 0039 outLines = out.splitlines() 0040 self.assertEqual(expected, outLines[(len(outLines) - 1)].decode('UTF-8')) 0041 0042 def test_sleep(self): 0043 self.driver.find_element(by=AppiumBy.NAME, value="Sleep").click() 0044 self.assertStdOutLine("suspend") 0045 0046 def test_hibernate(self): 0047 self.driver.find_element(by=AppiumBy.NAME, value="Hibernate").click() 0048 self.assertStdOutLine("hibernate") 0049 0050 def test_restart(self): 0051 self.driver.find_element(by=AppiumBy.NAME, value="Restart").click() 0052 self.assertStdOutLine("reboot") 0053 0054 def test_restart(self): 0055 self.driver.find_element(by=AppiumBy.NAME, value="Shut Down").click() 0056 self.assertStdOutLine("shutdown") 0057 0058 0059 if __name__ == '__main__': 0060 unittest.main()