Skip to content

Commit 863ea54

Browse files
committed
Add timeout handling for cell editing state checks
Updated OutputDataFrame to pass timeout to expect_cell_class for all cell state checks. Improved test reliability by adding retries and timeout when verifying cell enters editing state after pressing Enter.
1 parent c4c2b48 commit 863ea54

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

shiny/playwright/controller/_output.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,13 +1058,21 @@ def expect_class_state(
10581058
"cell-edit-editing", timeout=timeout
10591059
)
10601060
elif value == "editing":
1061-
self.expect_cell_class("cell-edit-editing", row=row, col=col)
1061+
self.expect_cell_class(
1062+
"cell-edit-editing", row=row, col=col, timeout=timeout
1063+
)
10621064
elif value == "saving":
1063-
self.expect_cell_class("cell-edit-saving", row=row, col=col)
1065+
self.expect_cell_class(
1066+
"cell-edit-saving", row=row, col=col, timeout=timeout
1067+
)
10641068
elif value == "failure":
1065-
self.expect_cell_class("cell-edit-failure", row=row, col=col)
1069+
self.expect_cell_class(
1070+
"cell-edit-failure", row=row, col=col, timeout=timeout
1071+
)
10661072
elif value == "success":
1067-
self.expect_cell_class("cell-edit-success", row=row, col=col)
1073+
self.expect_cell_class(
1074+
"cell-edit-success", row=row, col=col, timeout=timeout
1075+
)
10681076
else:
10691077
raise ValueError(
10701078
"Invalid state. Select one of 'success', 'failure', 'saving', 'editing', 'ready'"
@@ -1096,6 +1104,9 @@ def _edit_cell_no_save(
10961104

10971105
self._cell_scroll_if_needed(row=row, col=col, timeout=timeout)
10981106
cell.dblclick(timeout=timeout)
1107+
1108+
# Wait for the cell to enter editing mode before filling the textarea
1109+
expect_to_have_class(cell, "cell-edit-editing", timeout=timeout)
10991110
cell.locator("> textarea").fill(text)
11001111

11011112
def set_sort(

tests/playwright/shiny/components/data_frame/validate_row_selection_edit_mode/test_validate_row_selection_edit_mode.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,24 @@ def test_validate_row_selection_in_edit_mode(
6161
data_frame._edit_cell_no_save("Temp value", row=1, col=16)
6262
page.keyboard.press("Escape")
6363
page.keyboard.press("Enter")
64-
data_frame.expect_class_state(
65-
"editing",
66-
row=1,
67-
col=0,
68-
) # Stage column begins to be edited.
64+
65+
# This interaction (Enter key to start editing) can be flaky, so we retry if needed
66+
max_retries = 3
67+
for attempt in range(max_retries):
68+
try:
69+
page.wait_for_timeout(100)
70+
data_frame.expect_class_state(
71+
"editing",
72+
row=1,
73+
col=0,
74+
timeout=1000,
75+
)
76+
break
77+
except AssertionError:
78+
if attempt < max_retries - 1:
79+
page.keyboard.press("Enter")
80+
else:
81+
raise
6982

7083
# Click outside the table/Press Escape to exit row focus.
7184
# Tab to the column name, hit enter. Verify the table becomes sorted.

0 commit comments

Comments
 (0)