From 96ea2e81c78aedceb66319c41ad292a0bce3014e Mon Sep 17 00:00:00 2001 From: Florian Scherf Date: Sat, 6 Jul 2024 16:15:05 +0200 Subject: [PATCH] rename timeout to retry_interval and timeout_max to timeout Previously, we had the terms `timeout` which described the interval in which the frontend would try to find a selector, and `timeout_max` which described the total time the frontend should try to find at least one matching element. This was very confusing. Most users (including me sometimes) thought that `timeout` describes the total amount of time the frontend should wait for a selector to match. This patch renames `timeout` to `retry_interval` and `timeout_max` to `timeout`. Signed-off-by: Florian Scherf --- milan/browser.py | 198 +++++++++++++++--------------- milan/frontend/commands.py | 74 +++++------ milan/frontend/static/cursor.js | 90 +++++++------- milan/frontend/static/frontend.js | 56 ++++----- 4 files changed, 211 insertions(+), 207 deletions(-) diff --git a/milan/browser.py b/milan/browser.py index 07a5dbb..96bfb92 100644 --- a/milan/browser.py +++ b/milan/browser.py @@ -123,17 +123,17 @@ def start(cls, *args, **kwargs): def __init__( self, animations=True, - short_selector_timeout=0.2, - short_selector_timeout_max=1, - selector_timeout=0.2, - selector_timeout_max=3, + short_selector_retry_interval=0.2, + short_selector_timeout=1, + selector_retry_interval=0.2, + selector_timeout=3, ): self.animations = animations + self.short_selector_retry_interval = short_selector_retry_interval self.short_selector_timeout = short_selector_timeout - self.short_selector_timeout_max = short_selector_timeout_max + self.selector_retry_interval = selector_retry_interval self.selector_timeout = selector_timeout - self.selector_timeout_max = selector_timeout_max self.id = unique_id() @@ -156,29 +156,29 @@ def _get_animations(self, local_override): return self.animations - def _get_short_selector_timeout(self, local_override): + def _get_short_selector_retry_interval(self, local_override): if local_override is not None: return local_override - return self.short_selector_timeout + return self.short_selector_retry_interval - def _get_short_selector_timeout_max(self, local_override): + def _get_short_selector_timeout(self, local_override): if local_override is not None: return local_override - return self.short_selector_timeout_max + return self.short_selector_timeout - def _get_selector_timeout(self, local_override): + def _get_selector_retry_interval(self, local_override): if local_override is not None: return local_override - return self.selector_timeout + return self.selector_retry_interval - def _get_selector_timeout_max(self, local_override): + def _get_selector_timeout(self, local_override): if local_override is not None: return local_override - return self.selector_timeout_max + return self.selector_timeout # events ################################################################## @browser_function @@ -501,20 +501,23 @@ def element_exists( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_short_selector_retry_interval( + retry_interval, + ) + timeout = self._get_short_selector_timeout(timeout) - timeout_max = self._get_short_selector_timeout_max(timeout_max) self.logger.info( "checking if element with selector '%s' #%s in window %s exists with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) _element_exists = self._browser_evaluate( @@ -522,8 +525,8 @@ def element_exists( window_index=window, selector=selector, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -543,20 +546,20 @@ def await_element( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "waiting for element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -564,8 +567,8 @@ def await_element( window_index=window, selector=selector, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -579,13 +582,13 @@ def await_elements( match_all=True, count=None, index=None, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) if not isinstance(selectors, (list, tuple)): selectors = [selectors] @@ -598,7 +601,7 @@ def await_elements( window, 'present' if present else 'not present', match_all, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -610,8 +613,8 @@ def await_elements( match_all=match_all, count=count, index=index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -622,13 +625,13 @@ def await_text( selector, text, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "waiting for element with selector '%s' #%s to contain '%s' in window %s with a timeout of %ss", # NOQA @@ -636,7 +639,7 @@ def await_text( element_index, text, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -645,8 +648,8 @@ def await_text( selector=selector, element_index=element_index, text=text, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -679,20 +682,20 @@ def get_html( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "getting HTML from element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -700,8 +703,8 @@ def get_html( window_index=window, selector=selector, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -712,20 +715,20 @@ def set_html( selector, html, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "setting HTML in element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -734,8 +737,8 @@ def set_html( selector=selector, element_index=element_index, html=html, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -745,20 +748,20 @@ def get_text( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "getting text from element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -766,8 +769,8 @@ def get_text( window_index=window, selector=selector, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -776,8 +779,8 @@ def set_text( selector, text, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): @@ -785,8 +788,8 @@ def set_text( selector=selector, html=text, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, window=window, ) @@ -797,13 +800,13 @@ def get_attribute( selector, name, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "getting attribute '%s' from element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA @@ -811,7 +814,7 @@ def get_attribute( selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -820,8 +823,8 @@ def get_attribute( selector=selector, element_index=element_index, name=name, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -831,20 +834,20 @@ def get_attributes( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "getting attributes of element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -852,8 +855,8 @@ def get_attributes( window_index=window, selector=selector, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -864,20 +867,20 @@ def set_attributes( selector, attributes, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "setting attributes of element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -886,8 +889,8 @@ def set_attributes( selector=selector, element_index=element_index, attributes=attributes, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -897,8 +900,8 @@ def set_attribute( name, value, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): @@ -906,8 +909,8 @@ def set_attribute( selector=selector, element_index=element_index, attributes={name: value}, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, window=window, ) @@ -918,13 +921,13 @@ def remove_attributes( selector, names, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "removing attributes '%s' of element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA @@ -932,7 +935,7 @@ def remove_attributes( selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -941,8 +944,8 @@ def remove_attributes( selector=selector, element_index=element_index, names=names, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -951,8 +954,8 @@ def remove_attribute( selector, name, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): @@ -960,8 +963,8 @@ def remove_attribute( selector=selector, names=[name], element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, window=window, ) @@ -969,8 +972,8 @@ def get_class_list( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): @@ -978,8 +981,8 @@ def get_class_list( selector=selector, element_index=element_index, name='class', + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, window=window, ).split(' ') @@ -990,8 +993,8 @@ def set_class_list( selector, names, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): @@ -1000,8 +1003,8 @@ def set_class_list( name='class', value=' '.join(names), element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, window=window, ) @@ -1009,8 +1012,8 @@ def clear_class_list( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): @@ -1019,8 +1022,8 @@ def clear_class_list( name='class', value='', element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, window=window, ) @@ -1031,13 +1034,13 @@ def class_list_add( selector, names, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) if not isinstance(names, (list, tuple)): names = [names] @@ -1048,7 +1051,7 @@ def class_list_add( selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -1057,8 +1060,8 @@ def class_list_add( selector=selector, element_index=element_index, names=names, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -1069,13 +1072,13 @@ def class_list_remove( selector, names, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) if not isinstance(names, (list, tuple)): names = [names] @@ -1086,7 +1089,7 @@ def class_list_remove( selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -1095,8 +1098,8 @@ def class_list_remove( selector=selector, element_index=element_index, names=names, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, ), ) @@ -1107,21 +1110,21 @@ def click( self, selector, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, animation=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "clicking on element with selector '%s' #%s in window %s with a timeout of %ss", # NOQA selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -1129,8 +1132,8 @@ def click( window_index=window, selector=selector, element_index=element_index, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, animation=self._get_animations(animation), ), ) @@ -1142,14 +1145,14 @@ def fill( selector, value, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, animation=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "filling value '%s' #%s into an element with selector '%s' in window %s with a timeout of %ss", # NOQA @@ -1157,7 +1160,7 @@ def fill( selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -1166,8 +1169,8 @@ def fill( selector=selector, element_index=element_index, value=value, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, animation=self._get_animations(animation), ), ) @@ -1179,14 +1182,14 @@ def check( selector, value=True, element_index=0, + retry_interval=None, timeout=None, - timeout_max=None, animation=None, window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) self.logger.info( "%s checkbox with selector '%s' #%s in window %s with a timeout of %ss", # NOQA @@ -1194,7 +1197,7 @@ def check( selector, element_index, window, - timeout_max, + timeout, ) return self._browser_evaluate( @@ -1203,8 +1206,8 @@ def check( selector=selector, element_index=element_index, value=value, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, animation=self._get_animations(animation), ), ) @@ -1218,14 +1221,15 @@ def select( value=None, index=None, label=None, + retry_interval=None, timeout=None, - timeout_max=None, window=0, animation=None, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) + identifier = '' if value: @@ -1243,7 +1247,7 @@ def select( selector, element_index, window, - timeout_max + timeout, ) return self._browser_evaluate( @@ -1254,8 +1258,8 @@ def select( value=value, index=index, label=label, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, animation=self._get_animations(animation), ), ) @@ -1304,8 +1308,8 @@ def highlight_elements( selectors, index=None, count=None, + retry_interval=None, timeout=None, - timeout_max=None, border_width=2, border_style='solid', border_color='#FF0000', @@ -1315,8 +1319,8 @@ def highlight_elements( window=0, ): + retry_interval = self._get_selector_retry_interval(retry_interval) timeout = self._get_selector_timeout(timeout) - timeout_max = self._get_selector_timeout_max(timeout_max) if not isinstance(selectors, (list, tuple)): selectors = [selectors] @@ -1327,8 +1331,8 @@ def highlight_elements( selectors=selectors, index=index, count=count, + retry_interval=retry_interval, timeout=timeout, - timeout_max=timeout_max, border_width=border_width, border_style=border_style, border_color=border_color, diff --git a/milan/frontend/commands.py b/milan/frontend/commands.py index a949043..a3ddc2b 100644 --- a/milan/frontend/commands.py +++ b/milan/frontend/commands.py @@ -352,8 +352,8 @@ def gen_window_element_exists_command( window_index, selector, element_index, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -364,8 +364,8 @@ def gen_window_element_exists_command( args={ 'elementOrSelector': selector, 'elementIndex': element_index, - 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, + 'retryInterval': retry_interval * 1000, + 'timeot': timeout * 1000, }, ) @@ -374,8 +374,8 @@ def gen_window_await_element_command( window_index, selector, element_index, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -387,8 +387,8 @@ def gen_window_await_element_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'returnElement': False, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -401,8 +401,8 @@ def gen_window_await_elements_command( match_all, count, index, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -418,8 +418,8 @@ def gen_window_await_elements_command( 'count': count, 'index': index, 'returnElements': False, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -429,8 +429,8 @@ def gen_window_await_text_command( selector, element_index, text, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -442,8 +442,8 @@ def gen_window_await_text_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'text': text, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -452,8 +452,8 @@ def gen_window_get_text_command( window_index, selector, element_index, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -464,8 +464,8 @@ def gen_window_get_text_command( args={ 'elementOrSelector': selector, 'elementIndex': element_index, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -474,8 +474,8 @@ def gen_window_get_html_command( window_index, selector, element_index, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -486,8 +486,8 @@ def gen_window_get_html_command( args={ 'elementOrSelector': selector, 'elementIndex': element_index, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -497,8 +497,8 @@ def gen_window_set_html_command( selector, element_index, html, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -510,8 +510,8 @@ def gen_window_set_html_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'html': html, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -521,8 +521,8 @@ def gen_window_get_attribute_command( selector, element_index, name, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -534,8 +534,8 @@ def gen_window_get_attribute_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'name': name, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -544,8 +544,8 @@ def gen_window_get_attributes_command( window_index, selector, element_index, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -556,8 +556,8 @@ def gen_window_get_attributes_command( args={ 'elementOrSelector': selector, 'elementIndex': element_index, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -567,8 +567,8 @@ def gen_window_set_attributes_command( selector, element_index, attributes, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -580,8 +580,8 @@ def gen_window_set_attributes_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'attributes': attributes, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -591,8 +591,8 @@ def gen_window_remove_attributes_command( selector, element_index, names, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -604,8 +604,8 @@ def gen_window_remove_attributes_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'names': names, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -615,8 +615,8 @@ def gen_window_class_list_add_command( selector, element_index, names, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -628,8 +628,8 @@ def gen_window_class_list_add_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'names': names, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -639,8 +639,8 @@ def gen_window_class_list_remove_command( selector, element_index, names, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -652,8 +652,8 @@ def gen_window_class_list_remove_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'names': names, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -664,8 +664,8 @@ def gen_window_click_command( selector, element_index, animation, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -677,8 +677,8 @@ def gen_window_click_command( 'elementOrSelector': selector, 'elementIndex': element_index, 'animation': animation, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -689,8 +689,8 @@ def gen_window_fill_command( element_index, value, animation, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -703,8 +703,8 @@ def gen_window_fill_command( 'elementIndex': element_index, 'value': value, 'animation': animation, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -715,8 +715,8 @@ def gen_window_check_command( element_index, value, animation, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -729,8 +729,8 @@ def gen_window_check_command( 'elementIndex': element_index, 'value': value, 'animation': animation, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -743,8 +743,8 @@ def gen_window_select_command( index, label, animation, + retry_interval, timeout, - timeout_max, ): return _gen_frontend_run_command( @@ -759,8 +759,8 @@ def gen_window_select_command( 'index': index, 'label': label, 'animation': animation, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, }, ) @@ -771,8 +771,8 @@ def gen_window_highlight_elements_command( selectors, index, count, + retry_interval, timeout, - timeout_max, border_width, border_style, border_color, @@ -793,8 +793,8 @@ def gen_window_highlight_elements_command( 'selectors': selectors, 'index': index, 'count': count, + 'retryInterval': retry_interval * 1000, 'timeout': timeout * 1000, - 'timeoutMax': timeout_max * 1000, 'borderWidth': border_width, 'borderStyle': border_style, 'borderColor': border_color, diff --git a/milan/frontend/static/cursor.js b/milan/frontend/static/cursor.js index 28d7f85..c60a56e 100644 --- a/milan/frontend/static/cursor.js +++ b/milan/frontend/static/cursor.js @@ -108,10 +108,10 @@ // setup config this.config = { - shortTimeout: 200, - shortTimeoutMax: 1000, - timeout: 200, - timeoutMax: 3000, + shortRetryInterval: 200, + shortTimeout: 1000, + retryInterval: 200, + timeout: 3000, maxRetries: 3, }; @@ -207,16 +207,16 @@ elementOrSelector=required('elementOrSelector'), elementIndex=0, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { let elementOrSelectorList = undefined; let element = undefined; let timeSlept = 0; + retryInterval = retryInterval || this.config.shortRetryInterval; timeout = timeout || this.config.shortTimeout; - timeoutMax = timeoutMax || this.config.shortTimeoutMax; if (Array.isArray(elementOrSelector)) { elementOrSelectorList = elementOrSelector; @@ -224,14 +224,14 @@ elementOrSelectorList = [elementOrSelector]; } - while (timeSlept < timeoutMax) { + while (timeSlept < timeout) { for (let elementOrSelector of elementOrSelectorList) { element = this.getElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); if (element) { @@ -239,9 +239,9 @@ } } - await sleep(timeout); + await sleep(retryInterval); - timeSlept += timeout; + timeSlept += retryInterval; } return ''; @@ -252,16 +252,16 @@ elementIndex=0, returnElement=true, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { let elementOrSelectorList = undefined; let element = undefined; let timeSlept = 0; + retryInterval = retryInterval || this.config.retryInterval; timeout = timeout || this.config.timeout; - timeoutMax = timeoutMax || this.config.timeoutMax; if (Array.isArray(elementOrSelector)) { elementOrSelectorList = elementOrSelector; @@ -269,14 +269,14 @@ elementOrSelectorList = [elementOrSelector]; } - while (timeSlept < timeoutMax) { + while (timeSlept < timeout) { for (let elementOrSelector of elementOrSelectorList) { element = this.getElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); if (element) { @@ -288,9 +288,9 @@ } } - await sleep(timeout); + await sleep(retryInterval); - timeSlept += timeout; + timeSlept += retryInterval; } throw `No element with selector '${elementOrSelector}' found`; @@ -305,12 +305,12 @@ index=undefined, returnElements=true, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { + retryInterval = retryInterval || this.config.retryInterval; timeout = timeout || this.config.timeout; - timeoutMax = timeoutMax || this.config.timeoutMax; const matchingElements = new Array(); const matchingSelectors = new Array(); @@ -351,7 +351,7 @@ } // main loop - while (timeSlept < timeoutMax) { + while (timeSlept < timeout) { // reset matchingElements.length = 0; @@ -393,9 +393,9 @@ } // sleep - await sleep(timeout); + await sleep(retryInterval); - timeSlept += timeout; + timeSlept += retryInterval; } throw 'No matching elements found'; @@ -405,33 +405,33 @@ elementOrSelector=required('elementOrSelector'), elementIndex=0, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, text=required('text'), }={}) => { + retryInterval = retryInterval || this.config.retryInterval; timeout = timeout || this.config.timeout; - timeoutMax = timeoutMax || this.config.timeoutMax; let element = undefined; let timeSlept = 0; - while (timeSlept < timeoutMax) { + while (timeSlept < timeout) { element = this.getElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); if (element && element.innerHTML.includes(text)) { return; } - await sleep(timeout); + await sleep(retryInterval); - timeSlept += timeout; + timeSlept += retryInterval; } throw `No element with selector '${elementOrSelector}' and text '${text}' found`; @@ -492,16 +492,16 @@ elementOrSelector=required('elementOrSelector'), elementIndex=0, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); return element.textContent; @@ -511,16 +511,16 @@ elementOrSelector=required('elementOrSelector'), elementIndex=0, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); return element.innerHTML; @@ -531,16 +531,16 @@ elementIndex=0, html=required('html'), iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); element.innerHTML = html; @@ -551,16 +551,16 @@ elementIndex=0, name=required('name'), iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); return element.getAttribute(name); @@ -570,16 +570,16 @@ elementOrSelector=required('elementOrSelector'), elementIndex=0, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); let attributes = {}; @@ -598,16 +598,16 @@ elementIndex=0, attributes=required('attributes'), iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); for (let [name, value] of Object.entries(attributes)) { @@ -620,16 +620,16 @@ elementIndex=0, names=required('names'), iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); for (let name of Array.from(names)) { @@ -642,16 +642,16 @@ elementIndex=0, names=required('names'), iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); for (let name of Array.from(names)) { @@ -664,16 +664,16 @@ elementIndex=0, names=required('names'), iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { const element = await this.awaitElement({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: iframe, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); for (let name of Array.from(names)) { diff --git a/milan/frontend/static/frontend.js b/milan/frontend/static/frontend.js index 2eddb1d..085e24e 100644 --- a/milan/frontend/static/frontend.js +++ b/milan/frontend/static/frontend.js @@ -508,8 +508,8 @@ class BrowserWindow { text=undefined, index=undefined, count=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, borderWidth=undefined, borderStyle=undefined, borderColor=undefined, @@ -524,8 +524,8 @@ class BrowserWindow { count: count, index: index, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); const highlights = []; @@ -603,16 +603,16 @@ class BrowserWindow { elementExists = ({ elementOrSelector=required('elementOrSelector'), elementIndex=0, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.elementExists({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -620,8 +620,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, returnElement=true, + retryInterval=retryInterval, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.awaitElement({ @@ -629,8 +629,8 @@ class BrowserWindow { elementIndex: elementIndex, returnElement: returnElement, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -643,8 +643,8 @@ class BrowserWindow { index=undefined, returnElements=true, iframe=undefined, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.awaitElements({ @@ -656,16 +656,16 @@ class BrowserWindow { index: index, returnElements: returnElements, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } awaitText = ({ elementOrSelector=required('elementOrSelector'), elementIndex=0, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, text=required('text'), }={}) => { @@ -673,8 +673,8 @@ class BrowserWindow { elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, text: text, }); } @@ -750,32 +750,32 @@ class BrowserWindow { getText = ({ elementOrSelector=required('elementOrSelector'), elementIndex=0, + retryInterval: retryInterval, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.getText({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } getHtml = ({ elementOrSelector=required('elementOrSelector'), elementIndex=0, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.getHtml({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -783,8 +783,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, html=required('html'), + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.setHtml({ @@ -792,8 +792,8 @@ class BrowserWindow { elementIndex: elementIndex, html: html, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -801,8 +801,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, name=required('name'), + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.getAttribute({ @@ -810,24 +810,24 @@ class BrowserWindow { elementIndex: elementIndex, name: name, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } getAttributes = ({ elementOrSelector=required('elementOrSelector'), elementIndex=0, + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.getAttributes({ elementOrSelector: elementOrSelector, elementIndex: elementIndex, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -835,8 +835,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, attributes=required('attributes'), + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.setAttributes({ @@ -844,8 +844,8 @@ class BrowserWindow { elementIndex: elementIndex, attributes: attributes, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -853,8 +853,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, names=required('names'), + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.removeAttributes({ @@ -862,8 +862,8 @@ class BrowserWindow { elementIndex: elementIndex, names: names, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -871,8 +871,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, names=required('names'), + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.classListAdd({ @@ -880,8 +880,8 @@ class BrowserWindow { elementIndex: elementIndex, names: names, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } @@ -889,8 +889,8 @@ class BrowserWindow { elementOrSelector=required('elementOrSelector'), elementIndex=0, names=required('names'), + retryInterval=undefined, timeout=undefined, - timeoutMax=undefined, }={}) => { return this.cursor.classListRemove({ @@ -898,8 +898,8 @@ class BrowserWindow { elementIndex: elementIndex, names: names, iframe: this.iframeElement, + retryInterval: retryInterval, timeout: timeout, - timeoutMax: timeoutMax, }); } }