Fix Flaky test_execute_on_shift_enter (#1097)

* Wait for text to render in DOM before 'assert', to fix timing issue.
This commit is contained in:
Jeff Glass
2023-01-05 07:29:20 -06:00
committed by GitHub
parent 77d98a565e
commit e1b4415193
3 changed files with 29 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import dataclasses
import math
import os
import pdb
import re
@@ -372,6 +373,31 @@ class PyScriptTest:
# ============== Helpers and utility functions ==============
MAX_TEST_TIME = 30 # Number of seconds allowed for checking a testing condition
TEST_TIME_INCREMENT = 0.25 # 1/4 second, the length of each iteration
TEST_ITERATIONS = math.ceil(
MAX_TEST_TIME / TEST_TIME_INCREMENT
) # 120 iters of 1/4 second
def wait_for_render(page, selector, pattern):
"""
Assert that rendering inserts data into the page as expected: search the
DOM from within the timing loop for a string that is not present in the
initial markup but should appear by way of rendering
"""
re_sub_content = re.compile(pattern)
py_rendered = False # Flag to be set to True when condition met
for _ in range(TEST_ITERATIONS):
content = page.inner_html(selector)
if re_sub_content.search(content):
py_rendered = True
break
time.sleep(TEST_TIME_INCREMENT)
assert py_rendered # nosec
class JsErrors(Exception):
"""