Skip to content

Commit 80fed10

Browse files
committed
Wait until populated with non-empty value
1 parent e7b4d4a commit 80fed10

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/python/dashboard/test_python_import.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def test_python_import(dashboard):
2424
"""
2525
dashboard.load_example("testdata/example.py", manual=True)
2626

27+
# Wait for the file to finish loading and processing
28+
# The importing_file state is True while loading, False when done
29+
dashboard.assert_state("importing_file", False)
30+
2731
BEAM_PARAMETERS = [
2832
("tracking_mode", "Particle Tracking"),
2933
("space_charge", "false"),
@@ -76,6 +80,10 @@ def test_python_import(dashboard):
7680
# This is important for CI environments where rendering may be slower
7781
dashboard.sb.wait_for_element_present(element_id, timeout=10)
7882

83+
# Wait for the element's value to be populated
84+
# DOM elements may take time to reflect updated state values after file loading
85+
dashboard.wait_for_element_value(element_id, timeout=10)
86+
7987
# Get the value attribute - this works even if the element isn't visible
8088
actual_value = float(dashboard.sb.get_attribute(element_id, "value"))
8189
assert actual_value == pytest.approx(expected_value, **APPROX_TOL), (

tests/python/dashboard/utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,39 @@ def get_state(self, state_name):
275275
"""
276276
return self.sb.execute_script(js_script, state_name)
277277

278+
def wait_for_element_value(self, element_id: str, timeout=TIMEOUT):
279+
"""
280+
Wait for an element's value attribute to be populated (non-empty).
281+
282+
This is useful after loading files, as DOM elements may take time to
283+
reflect the updated state values.
284+
285+
:param element_id: ID of the input element to check (with or without # prefix).
286+
:param timeout: Maximum time to wait in seconds.
287+
"""
288+
for i in range(timeout):
289+
try:
290+
value = self.sb.get_attribute(element_id, "value")
291+
if value and value.strip(): # Non-empty value
292+
return value
293+
except Exception:
294+
pass
295+
296+
time.sleep(1)
297+
298+
# If we get here, try one more time to get the value (even if empty)
299+
# to provide a better error message
300+
try:
301+
final_value = self.sb.get_attribute(element_id, "value")
302+
raise TimeoutError(
303+
f"Element '{element_id}' value never populated after {timeout} seconds "
304+
f"(last value: '{final_value}')"
305+
)
306+
except Exception as e:
307+
raise TimeoutError(
308+
f"Element '{element_id}' value never populated after {timeout} seconds"
309+
) from e
310+
278311

279312
def save_failure_screenshot(
280313
dashboard, request, directory: str | None = None

0 commit comments

Comments
 (0)