]>
cloud.milkyroute.net Git - dolphin.git/blob - appiumtests/dolphintest.py
3 # SPDX-License-Identifier: MIT
4 # SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
5 # SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org>
8 from appium
import webdriver
9 from appium
.webdriver
.common
.appiumby
import AppiumBy
10 from appium
.options
.common
.base
import AppiumOptions
11 from selenium
.webdriver
.support
.ui
import WebDriverWait
12 from selenium
.webdriver
.common
.keys
import Keys
13 from selenium
.webdriver
.common
.by
import By
14 from selenium
.webdriver
.common
.action_chains
import ActionChains
15 from selenium
.webdriver
.support
import expected_conditions
as EC
22 class DolphinTests(unittest
.TestCase
):
25 options
= AppiumOptions()
26 options
.set_capability("timeouts", {'implicit': 10000}
)
27 options
.set_capability("app", "org.kde.dolphin.desktop")
28 options
.set_capability("environ", {
29 "LC_ALL": "en_US.UTF-8",
32 self
.driver
= webdriver
.Remote(
33 command_executor
='http://127.0.0.1:4723',
35 self
.driver
.implicitly_wait
= 10
36 filename
= "{}/testDir/test1.txt".format(os
.environ
["HOME"])
37 os
.makedirs(os
.path
.dirname(filename
), exist_ok
=True)
38 with open(filename
, "w") as f
:
39 f
.write("Test File 1")
40 filename
= "{}/testDir/test2.txt".format(os
.environ
["HOME"])
41 with open(filename
, "w") as f
:
42 f
.write("Test File 2")
45 if not self
._outcome
.result
.wasSuccessful():
46 self
.driver
.get_screenshot_as_file("failed_test_shot_{}.png".format(self
.id()))
49 def tearDownClass(self
):
50 os
.remove("{}/testDir/test1.txt".format(os
.environ
["HOME"]))
51 os
.remove("{}/testDir/test2.txt".format(os
.environ
["HOME"]))
52 os
.rmdir("{}/testDir".format(os
.environ
["HOME"]))
55 def assertResult(self
, actual
, expected
):
56 wait
= WebDriverWait(self
.driver
, 20)
57 wait
.until(lambda x
: self
.getresults() == expected
)
58 self
.assertEqual(self
.getresults(), expected
)
60 def test_1_location(self
):
61 editButton
= self
.driver
.find_element(by
=AppiumBy
.ACCESSIBILITY_ID
, value
="KUrlNavigatorToggleButton")
65 self
.driver
.find_element(by
=AppiumBy
.ACCESSIBILITY_ID
, value
="DolphinUrlNavigator.KUrlComboBox.KLineEdit.QLineEditIconButton").click()
67 locationBar
= self
.driver
.find_element(by
=AppiumBy
.ACCESSIBILITY_ID
, value
="DolphinUrlNavigator.KUrlComboBox.KLineEdit")
68 locationBar
.send_keys("{}/testDir".format(os
.environ
["HOME"]))
71 elements
= self
.driver
.find_elements(by
=AppiumBy
.XPATH
, value
="//table_cell")
72 self
.assertEqual(len(elements
), 2)
73 self
.assertEqual(elements
[0].text
, "test1.txt")
74 self
.assertEqual(elements
[1].text
, "test2.txt")
76 def test_2_filter_bar(self
):
77 ActionChains(self
.driver
).send_keys(Keys
.DIVIDE
).perform()
79 searchField
= self
.driver
.find_element(by
=AppiumBy
.ACCESSIBILITY_ID
, value
="Filter.QScrollArea.qt_scrollarea_viewport.QWidget.FilterLineEdit")
80 searchField
.send_keys("test2.txt")
81 self
.assertEqual(searchField
.text
, "test2.txt")
82 elements
= self
.driver
.find_elements(by
=AppiumBy
.XPATH
, value
="//table_cell")
83 self
.assertEqual(len(elements
), 1)
84 self
.assertEqual(elements
[0].text
, "test2.txt")
86 # should see both files now
87 buttons
= self
.driver
.find_elements(by
=AppiumBy
.ACCESSIBILITY_ID
, value
="Filter.QScrollArea.qt_scrollarea_viewport.QWidget.QToolButton")
88 self
.assertEqual(len(buttons
), 2)
89 # close buttion is the second QToolButton
90 close_button
=buttons
[1]
91 self
.assertIsNotNone(close_button
)
94 elements
= self
.driver
.find_elements(by
=AppiumBy
.XPATH
, value
="//table_cell")
95 self
.assertEqual(len(elements
), 2)
96 self
.assertEqual(elements
[0].text
, "test1.txt")
97 self
.assertEqual(elements
[1].text
, "test2.txt")
101 def test_search_bar(self):
102 ActionChains(self.driver).key_down(Keys.CONTROL).send_keys("f").key_up(Keys.CONTROL).perform()
104 #self.driver.pause(0.1)
105 searchField = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="DolphinSearchBox.QScrollArea.qt_scrollarea_viewport.QWidget.searchField")
106 searchField.send_keys("test1.txt")
107 self.assertEqual(searchField.text, "test1.txt")
110 # TODO the search does not work, filenamesearch:/ does not return any result
112 elements = self.driver.find_elements(by=AppiumBy.XPATH, value="//table_cell")
113 self.assertEqual(len(elements), 1)
114 self.assertEqual(elements[0].text, "test1.txt")
116 # click on leave search
117 self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="DolphinSearchBox.QScrollArea.qt_scrollarea_viewport.QWidget.QToolButton").click()
118 # should see both files now
119 elements = self.driver.find_elements(by=AppiumBy.XPATH, value="//table_cell")
120 self.assertEqual(len(elements), 2)
121 self.assertEqual(elements[0].text, "test2.txt")
122 self.assertEqual(elements[1].text, "test1.txt")
125 if __name__
== '__main__':
126 suite
= unittest
.TestLoader().loadTestsFromTestCase(DolphinTests
)
127 unittest
.TextTestRunner(verbosity
=2).run(suite
)