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 unittest
0007 
0008 from appium import webdriver
0009 from appium.options.common.base import AppiumOptions
0010 from appium.webdriver.common.appiumby import AppiumBy
0011 
0012 
0013 class EmojierTest(unittest.TestCase):
0014     """
0015     Tests for plasma-emojier
0016     """
0017 
0018     driver: webdriver.Remote
0019 
0020     @classmethod
0021     def setUpClass(cls) -> None:
0022         options = AppiumOptions()
0023         options.set_capability("app", f"plasma-emojier")
0024         options.set_capability("timeouts", {'implicit': 10000})
0025         cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', options=options)
0026 
0027     def tearDown(self) -> None:
0028         """
0029         Take screenshot when the current test fails
0030         """
0031         if not self._outcome.result.wasSuccessful():
0032             self.driver.get_screenshot_as_file(f"failed_test_shot_emojier_#{self.id()}.png")
0033 
0034     @classmethod
0035     def tearDownClass(cls) -> None:
0036         """
0037         Make sure to terminate the driver again, lest it dangles.
0038         """
0039         cls.driver.quit()
0040 
0041     def test_0_open(self) -> None:
0042         """
0043         Tests the app does not crash on opening
0044         @see https://bugs.kde.org/show_bug.cgi?id=478458
0045         """
0046         self.driver.find_element(AppiumBy.NAME, "Recent")
0047         self.driver.find_element(AppiumBy.NAME, "Clear History")
0048 
0049     def test_1_open_category(self) -> None:
0050         self.driver.find_element(AppiumBy.NAME, "All").click()
0051         self.driver.find_element(AppiumBy.NAME, "grinning face").click()
0052         self.assertEqual(self.driver.get_clipboard_text(), "😀")
0053 
0054     def test_2_recent_usage(self) -> None:
0055         self.driver.find_element(AppiumBy.NAME, "Recent").click()
0056         self.driver.find_element(AppiumBy.NAME, "grinning face")
0057 
0058 
0059 if __name__ == '__main__':
0060     unittest.main()