16
16
# under the License.
17
17
18
18
import time
19
+ from typing import Any
19
20
from typing import Callable
20
21
from typing import Generic
21
22
from typing import Literal
@@ -92,7 +93,9 @@ def __init__(
92
93
def __repr__ (self ) -> str :
93
94
return f'<{ type (self ).__module__ } .{ type (self ).__name__ } (session="{ self ._driver .session_id } ")>'
94
95
95
- def until (self , method : Callable [[D ], Union [Literal [False ], T ]], message : str = "" ) -> T :
96
+ def until (
97
+ self , method : Callable [[D ], Union [Literal [False ], T ]], message : Union [str , Callable [[Any ], str ]] = ""
98
+ ) -> T :
96
99
"""Wait until the method returns a value that is not False.
97
100
98
101
Calls the method provided with the driver as an argument until the
@@ -103,7 +106,7 @@ def until(self, method: Callable[[D], Union[Literal[False], T]], message: str =
103
106
method: callable(WebDriver)
104
107
- A callable object that takes a WebDriver instance as an argument.
105
108
106
- message: str
109
+ message: Union[ str, Callable[[Any], str]]
107
110
- Optional message for :exc:`TimeoutException`
108
111
109
112
Return:
@@ -143,9 +146,13 @@ def until(self, method: Callable[[D], Union[Literal[False], T]], message: str =
143
146
if time .monotonic () > end_time :
144
147
break
145
148
time .sleep (self ._poll )
146
- raise TimeoutException (message , screen , stacktrace )
147
149
148
- def until_not (self , method : Callable [[D ], T ], message : str = "" ) -> Union [T , Literal [True ]]:
150
+ final_msg = message () if callable (message ) else message
151
+ raise TimeoutException (final_msg , screen , stacktrace )
152
+
153
+ def until_not (
154
+ self , method : Callable [[D ], T ], message : Union [str , Callable [[Any ], str ]] = ""
155
+ ) -> Union [T , Literal [True ]]:
149
156
"""Wait until the method returns a value that is not False.
150
157
151
158
Calls the method provided with the driver as an argument until the
@@ -156,7 +163,7 @@ def until_not(self, method: Callable[[D], T], message: str = "") -> Union[T, Lit
156
163
method: callable(WebDriver)
157
164
- A callable object that takes a WebDriver instance as an argument.
158
165
159
- message: str
166
+ message: Union[ str, Callable[[Any], str]]
160
167
- Optional message for :exc:`TimeoutException`
161
168
162
169
Return:
@@ -192,4 +199,5 @@ def until_not(self, method: Callable[[D], T], message: str = "") -> Union[T, Lit
192
199
if time .monotonic () > end_time :
193
200
break
194
201
time .sleep (self ._poll )
195
- raise TimeoutException (message )
202
+ final_msg = message () if callable (message ) else message
203
+ raise TimeoutException (final_msg )
0 commit comments