Skip to content

Commit 04d00ec

Browse files
committed
change assertion polling
1 parent a2041ce commit 04d00ec

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

Browser/assertion_engine.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ def verify_assertion(
6767

6868

6969
@wrapt.decorator
70-
def with_assertions(wrapped, instance, args, kwargs):
70+
def with_assertion_polling(wrapped, instance, args, kwargs):
7171
start = time.time()
72-
err: Optional[AssertionError] = None
7372
timeout = timestr_to_secs(instance.timeout)
74-
while time.time() - start < timeout:
73+
while True:
7574
try:
7675
return wrapped(*args, **kwargs)
7776
except AssertionError as e:
78-
err = e
79-
if timeout - (time.time() - start) > 0.1:
80-
logger.debug("Verification failure - retrying")
81-
time.sleep(0.1)
82-
raise err
77+
elapsed = time.time() - start
78+
if elapsed > timeout:
79+
raise e
80+
logger.debug("Verification failure - retrying")
81+
if timeout - elapsed > 0.016:
82+
time.sleep(0.016) # 60 fps
8383

8484

8585
def int_str_verify_assertion(

Browser/keywords/getters.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
int_str_verify_assertion,
1111
list_verify_assertion,
1212
verify_assertion,
13-
with_assertions,
13+
with_assertion_polling,
1414
)
1515
from ..base import LibraryComponent
1616
from ..generated.playwright_pb2 import Request
@@ -20,7 +20,7 @@
2020

2121
class Getters(LibraryComponent):
2222
@keyword(tags=["Getter", "Assertion", "BrowserControl"])
23-
@with_assertions
23+
@with_assertion_polling
2424
def get_url(
2525
self,
2626
assertion_operator: Optional[AssertionOperator] = None,
@@ -41,7 +41,7 @@ def get_url(
4141
)
4242

4343
@keyword(tags=["Getter", "Assertion", "BrowserControl"])
44-
@with_assertions
44+
@with_assertion_polling
4545
def get_page_state(
4646
self,
4747
assertion_operator: Optional[AssertionOperator] = None,
@@ -68,7 +68,7 @@ def get_page_state(
6868
)
6969

7070
@keyword(tags=["Getter", "Assertion", "BrowserControl"])
71-
@with_assertions
71+
@with_assertion_polling
7272
def get_page_source(
7373
self,
7474
assertion_operator: Optional[AssertionOperator] = None,
@@ -89,7 +89,7 @@ def get_page_source(
8989
)
9090

9191
@keyword(tags=["Getter", "Assertion", "PageContent"])
92-
@with_assertions
92+
@with_assertion_polling
9393
def get_title(
9494
self,
9595
assertion_operator: Optional[AssertionOperator] = None,
@@ -110,7 +110,7 @@ def get_title(
110110
)
111111

112112
@keyword(tags=["Getter", "Assertion", "PageContent"])
113-
@with_assertions
113+
@with_assertion_polling
114114
def get_text(
115115
self,
116116
selector: str,
@@ -134,7 +134,7 @@ def get_text(
134134
)
135135

136136
@keyword(tags=["Getter", "Assertion", "PageContent"])
137-
@with_assertions
137+
@with_assertion_polling
138138
def get_attribute(
139139
self,
140140
selector: str,
@@ -183,7 +183,7 @@ def get_textfield_value(
183183
)
184184

185185
@keyword(tags=["Getter", "Assertion", "PageContent"])
186-
@with_assertions
186+
@with_assertion_polling
187187
def get_selected_options(
188188
self,
189189
selector: str,
@@ -240,7 +240,7 @@ def get_selected_options(
240240
)
241241

242242
@keyword(tags=["Getter", "Assertion", "PageContent"])
243-
@with_assertions
243+
@with_assertion_polling
244244
def get_checkbox_state(
245245
self,
246246
selector: str,
@@ -280,7 +280,7 @@ def get_checkbox_state(
280280
)
281281

282282
@keyword(tags=["Getter", "Assertion", "PageContent"])
283-
@with_assertions
283+
@with_assertion_polling
284284
def get_element_count(
285285
self,
286286
selector: str,
@@ -358,7 +358,7 @@ def get_browser_catalog(self):
358358
return parsed
359359

360360
@keyword(tags=["Getter", "Assertion", "BrowserControl"])
361-
@with_assertions
361+
@with_assertion_polling
362362
def get_viewport_size(
363363
self,
364364
assertion_operator: Optional[AssertionOperator] = None,
@@ -404,7 +404,7 @@ def get_elements(self, selector: str):
404404
return data
405405

406406
@keyword(tags=["Getter", "Assertion"])
407-
@with_assertions
407+
@with_assertion_polling
408408
def get_style(
409409
self,
410410
selector: str,

Browser/keywords/webapp_state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from robotlibcore import keyword # type: ignore
55

6-
from ..assertion_engine import verify_assertion, with_assertions
6+
from ..assertion_engine import verify_assertion, with_assertion_polling
77
from ..base import LibraryComponent
88
from ..generated.playwright_pb2 import Request
99
from ..utils import logger
@@ -12,7 +12,7 @@
1212

1313
class WebAppState(LibraryComponent):
1414
@keyword(name="localStorage get Item", tags=["WebAppState", "Assertion", "Getter"])
15-
@with_assertions
15+
@with_assertion_polling
1616
def local_storage_get_item(
1717
self,
1818
key: str,
@@ -84,7 +84,7 @@ def local_storage_clear(self):
8484
@keyword(
8585
name="sessionStorage get Item", tags=["WebAppState", "Assertion", "Getter"]
8686
)
87-
@with_assertions
87+
@with_assertion_polling
8888
def session_storage_get_item(
8989
self,
9090
key: str,

utest/test_assertion_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from Browser.assertion_engine import verify_assertion, AssertionOperator, with_assertions
2+
from Browser.assertion_engine import verify_assertion, AssertionOperator, with_assertion_polling
33
from robot.libraries.BuiltIn import EXECUTION_CONTEXTS # type: ignore
44

55

@@ -26,11 +26,11 @@ class FakeBrowser:
2626
timeout = "0.3s"
2727
counter = 1
2828

29-
@with_assertions
29+
@with_assertion_polling
3030
def is_three(self, value):
3131
verify_assertion(value, AssertionOperator['=='], 3)
3232

33-
@with_assertions
33+
@with_assertion_polling
3434
def second_run_success(self):
3535
current = self.counter
3636
self.counter += 1

0 commit comments

Comments
 (0)