blob: 8d47d89dfb88d030e842b701502f5274e03f865a [file] [log] [blame]
George Keishing04d93452017-05-03 09:14:15 -05001#!/usr/bin/env python
2
3r"""
4This module contains keyword functions to supplement robot's built in
5functions and use in test where generic robot keywords don't support.
6
7"""
8import time
9from robot.libraries.BuiltIn import BuiltIn
10from robot.libraries import DateTime
11
12###############################################################################
13def run_until_keyword_fails(retry, retry_interval, name, *args):
14
15 r"""
16 Execute a robot keyword repeatedly until it either fails or the timeout
17 value is exceeded.
18 Note: Opposite of robot keyword "Wait Until Keyword Succeeds".
19
20 Description of argument(s):
21 retry Max timeout time in hour(s).
22 retry_interval Time interval in minute(s) for looping.
23 name Robot keyword to execute.
24 args Robot keyword arguments.
25 """
26
27 # Convert the retry time in seconds
28 retry_seconds= DateTime.convert_time(retry)
29 timeout = time.time() + int(retry_seconds)
30
31 # Convert the interval time in seconds
32 interval_seconds= DateTime.convert_time(retry_interval)
33 interval = int(interval_seconds)
34
35 BuiltIn().log(timeout)
36 BuiltIn().log(interval)
37
38 while True:
39 status= BuiltIn().run_keyword_and_return_status(name, *args)
40
41 # Return if keywords returns as failure.
42 if status==False:
43 BuiltIn().log("Failed as expected")
44 return False
45 # Return if retry timeout as success.
46 elif time.time() > timeout > 0:
47 BuiltIn().log("Max retry timeout")
48 return True
49 time.sleep(interval)
50 BuiltIn().log(time.time())
51
52 return True
53
54###############################################################################