Skip to content

Commit

Permalink
Helper function _get_window.
Browse files Browse the repository at this point in the history
  • Loading branch information
eeromakiesko authored and eeter committed Feb 7, 2019
1 parent b55d2ca commit 14f5623
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions src/WhiteLibrary/keywords/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ def attach_window(self, window_title):
``window_title`` is the title of the window.
"""
try:
self.state.window = self.state.app.GetWindow(window_title)
except AutomationException as error_msg:
error_msg = str(error_msg)
replaced_text = "after waiting for {0} seconds".format(int(CoreAppXmlConfiguration.Instance.FindWindowTimeout/1000))
raise AutomationException(error_msg.replace("after waiting for 30 seconds", replaced_text), "")
except AttributeError as error_msg:
error_msg = str(error_msg)
if "NoneType" in error_msg:
error_msg = "No application attached."
raise AttributeError(error_msg)

self.state.window = self._get_window(window_title)

@keyword
def select_modal_window(self, window_title):
Expand All @@ -48,17 +39,21 @@ def close_window(self, window_title=None):
`Launch application` for more details.
"""
if window_title is not None:
try:
window = self.state.app.GetWindow(window_title)
except AutomationException as error_msg:
error_msg = str(error_msg)
replaced_text = "after waiting for {0} seconds".format(int(CoreAppXmlConfiguration.Instance.FindWindowTimeout/1000))
raise AutomationException(error_msg.replace("after waiting for 30 seconds", replaced_text), "")
except AttributeError as error_msg:
error_msg = str(error_msg)
if "NoneType" in error_msg:
error_msg = "No application attached."
raise AttributeError(error_msg)
window = self._get_window(window_title)
window.Close()
else:
self.state.window.Close()

def _get_window(self, window_title):
try:
return self.state.app.GetWindow(window_title)
except AutomationException as error_msg:
error_msg = str(error_msg)
replaced_text = "after waiting for {0} seconds".format(int(CoreAppXmlConfiguration.Instance.FindWindowTimeout/1000))
raise AutomationException(error_msg.replace("after waiting for 30 seconds", replaced_text), "")
except AttributeError as error_msg:
error_msg = str(error_msg)
if "NoneType" in error_msg:
error_msg = "No application attached."
raise AttributeError(error_msg)

0 comments on commit 14f5623

Please sign in to comment.