Skip to content

Commit

Permalink
added tests for find_all method
Browse files Browse the repository at this point in the history
  • Loading branch information
EOKruglov authored and vasily-v-ryabov committed Feb 27, 2022
1 parent 06dfd7b commit 5b630e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pywinauto/base_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def __find_base(self, criteria_, timeout, retry_interval):
def __find_all_base(self, criteria_, timeout, retry_interval):
time_left = timeout
start = timestamp()
criteria = self._get_updated_criteria(criteria_)

if len(criteria) == 1:
if len(criteria_) == 1:
criteria = self._get_updated_criteria(criteria_)
wrapped_dialogs = []
dialogs = findwindows.find_elements(**criteria[0])
for dialog in dialogs:
Expand All @@ -244,9 +244,9 @@ def __find_all_base(self, criteria_, timeout, retry_interval):

else:
time_left -= timestamp() - start
previous_ctrl = self.__find_base(criteria[:-1], time_left, retry_interval)
previous_ctrl = self.__find_base(criteria_[:-1], time_left, retry_interval)
previous_parent = previous_ctrl.element_info
ctrl_criteria = criteria[-1]
ctrl_criteria = criteria_[-1]
ctrl_criteria["top_level_only"] = False
if "parent" not in ctrl_criteria:
ctrl_criteria["parent"] = previous_parent
Expand Down Expand Up @@ -305,7 +305,7 @@ def find(self, timeout=None, retry_interval=None):

return ctrl

def find_all(self, timeout, retry_interval):
def find_all(self, timeout=None, retry_interval=None):
"""
Find all controls using criteria. The returned controls match conditions from criteria[-1].
Parent controls are assumed to exist in a single instance. Otherwise it will result in an AmbiguousError.
Expand Down
14 changes: 13 additions & 1 deletion pywinauto/unittests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,21 @@ def test_exists_timing(self):
# try one that should not be found
start = timestamp()
self.assertEqual(True, self.dlgspec.exists(.5))
timedif = timestamp() - start
timedif = timestamp() - start
self.assertEqual(True, .49 > timedif < .6)

def test_find_all_dlg(self):
dlg_spec_list = self.dlgspec.find_all()
self.assertEqual(1, len(dlg_spec_list))
self.assertEqual(self.dlgspec.find(), dlg_spec_list[0])

def test_find_all_notepad(self):
ctrls = self.dlgspec.by(parent=self.dlgspec).find_all()

self.assertEqual(2, len(ctrls))
self.assertEqual(ctrls[0], self.app.Notepad.Edit.find())
self.assertEqual(ctrls[1], self.app.Notepad.StatusBar.find())

def test_wait(self):
"""test the functionality and timing of the wait method"""
allowable_error = .2
Expand Down

0 comments on commit 5b630e1

Please sign in to comment.