Skip to content

Add library argument and keyword to set sleep between wait until loop #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion AppiumLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AppiumLibrary(
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = VERSION

def __init__(self, timeout=5, run_on_failure='Capture Page Screenshot'):
def __init__(self, timeout=5, run_on_failure='Capture Page Screenshot', sleep_between_wait_loop=0.2):
"""AppiumLibrary can be imported with optional arguments.

``timeout`` is the default timeout used to wait for all waiting actions.
Expand All @@ -92,12 +92,16 @@ def __init__(self, timeout=5, run_on_failure='Capture Page Screenshot'):
Using the value `No Operation` will disable this feature altogether. See
`Register Keyword To Run On Failure` keyword for more information about this
functionality.

``sleep_between_wait_loop`` is the default sleep used to wait between loop in all wait until keywords

Examples:
| Library | AppiumLibrary | 10 | # Sets default timeout to 10 seconds |
| Library | AppiumLibrary | timeout=10 | run_on_failure=No Operation | # Sets default timeout to 10 seconds and does nothing on failure |
| Library | AppiumLibrary | timeout=10 | sleep_between_wait_loop=0.3 | # Sets default timeout to 10 seconds and sleep 300 ms between wait loop |
"""
for base in AppiumLibrary.__bases__:
base.__init__(self)
self.set_appium_timeout(timeout)
self.register_keyword_to_run_on_failure(run_on_failure)
self.set_sleep_between_wait_loop(sleep_between_wait_loop)
22 changes: 21 additions & 1 deletion AppiumLibrary/keywords/_waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@


class _WaitingKeywords(KeywordGroup):

def __init__(self):
self._sleep_between_wait = 0.2

def wait_until_element_is_visible(self, locator, timeout=None, error=None):
"""Waits until element specified with `locator` is visible.

Expand Down Expand Up @@ -111,6 +115,22 @@ def check_present():

self._wait_until_no_error(timeout, check_present)

def set_sleep_between_wait_loop(self, seconds=0.2):
"""Sets the sleep in seconds used by wait until loop.

If you use the remote appium server, the default value is not recommended because
it is another 200ms overhead to the network latency and will slow down your test
execution.
"""
old_sleep = self._sleep_between_wait
self._sleep_between_wait = robot.utils.timestr_to_secs(seconds)
return old_sleep

def get_sleep_between_wait_loop(self):
"""Gets the sleep between wait loop in seconds that is used by wait until keywords.
"""
return robot.utils.secs_to_timestr(self._sleep_between_wait)

# Private

def _wait_until(self, timeout, error, function, *args):
Expand All @@ -131,7 +151,7 @@ def _wait_until_no_error(self, timeout, wait_func, *args):
if time.time() > maxtime:
self.log_source()
raise AssertionError(timeout_error)
time.sleep(0.2)
time.sleep(self._sleep_between_wait)

def _format_timeout(self, timeout):
timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs
Expand Down