From 14f562336cc590dcac766c9584b77a38cb6b6328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eero=20M=C3=A4ki-Esko?= Date: Thu, 7 Feb 2019 09:48:15 +0200 Subject: [PATCH] Helper function _get_window. --- src/WhiteLibrary/keywords/window.py | 39 +++++++++++++---------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/WhiteLibrary/keywords/window.py b/src/WhiteLibrary/keywords/window.py index 01eb339..3b5c5d2 100644 --- a/src/WhiteLibrary/keywords/window.py +++ b/src/WhiteLibrary/keywords/window.py @@ -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): @@ -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) +