File indexing completed on 2024-06-23 05:23:01

0001 #!/usr/bin/env python3
0002 
0003 # SPDX-License-Identifier: BSD-3-Clause
0004 # SPDX-FileCopyrightText: 2023 Harald Sitter <sitter@kde.org>
0005 
0006 import subprocess
0007 import time
0008 import unittest
0009 from appium import webdriver
0010 from appium.options.common.base import AppiumOptions
0011 from appium.webdriver.common.appiumby import AppiumBy
0012 from selenium.webdriver.support.ui import WebDriverWait
0013 from appium.options.common.app_option import AppOption
0014 from selenium.webdriver.common.options import ArgOptions
0015 from selenium.webdriver.common.keys import Keys
0016 from selenium.webdriver.support import expected_conditions as EC
0017 
0018 
0019 class ATSPIOptions(AppiumOptions, AppOption):
0020     pass
0021 
0022 
0023 class FlatpakTest(unittest.TestCase):
0024 
0025     def setUp(self):
0026         subprocess.run(['flatpak', 'remote-add', '--user', '--if-not-exists', 'flathub', 'https://flathub.org/repo/flathub.flatpakrepo'])
0027         subprocess.run(['flatpak', 'uninstall', '--noninteractive', 'org.kde.kalzium'])
0028 
0029         options = ATSPIOptions()
0030         options.app = "plasma-discover --backends flatpak-backend"
0031         self.driver = webdriver.Remote(
0032             command_executor='http://127.0.0.1:4723',
0033             options=options)
0034 
0035 
0036     def tearDown(self):
0037         self.driver.get_screenshot_as_file("failed_test_shot_{}.png".format(self.id()))
0038         self.driver.quit()
0039 
0040 
0041     def test_search_install_uninstall(self):
0042         WebDriverWait(self.driver, 30).until(
0043             EC.invisibility_of_element_located((AppiumBy.CLASS_NAME, "[label | Loading…]"))
0044         )
0045 
0046         searchElement = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="searchField")
0047         searchFocused = searchElement.get_attribute('focused')
0048         self.assertTrue(searchFocused)
0049 
0050         searchElement.send_keys("Kalzium")
0051         searchElement.send_keys(Keys.ENTER)
0052 
0053         listItem = WebDriverWait(self.driver, 30).until(
0054             EC.element_to_be_clickable((AppiumBy.CLASS_NAME, "[list item | Kalzium]"))
0055         )
0056         listItem.click()
0057 
0058         description = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="applicationDescription").text
0059         self.assertTrue(len(description) > 64) # arbitrary large number
0060 
0061         self.driver.find_element(by=AppiumBy.CLASS_NAME, value="[push button | Install from Flathub (user)]").click()
0062 
0063         removeButton = WebDriverWait(self.driver, 120).until(
0064             EC.element_to_be_clickable((AppiumBy.CLASS_NAME, "[push button | Remove]"))
0065         )
0066         removeButton.click()
0067 
0068         # should find install button again after removal
0069         WebDriverWait(self.driver, 30).until(
0070             EC.element_to_be_clickable((AppiumBy.CLASS_NAME, "[push button | Install from Flathub (user)]"))
0071         )
0072 
0073 if __name__ == '__main__':
0074     unittest.main()