Skip to content

Commit 4363d95

Browse files
author
User
committed
Fix flaky test_component_view_to_iframe_* tests
view_to_iframe renders the iframe with loading="lazy", so the browser only fetches the iframe's document once it is scrolled close to the viewport. These iframes sit well below the fold of the home page and the shared browser page is (usually) already sitting on /, so navigate_to_page performs no navigation and the page is never scrolled. Left alone, the browser can defer the iframe's document fetch long enough that the test's 30 second wait_for times out (observed intermittently on slow CI runners, e.g. test_component_view_to_iframe_sync_func on windows-latest). Scrolling the container into view is the browser's documented trigger for a lazy load, so the document is fetched immediately and the test is not at the mercy of the browser's load-timing heuristics. A small shared helper applies this to each of the iframe component tests. Co-authored-by: User <user@example.com>
1 parent 4fd0434 commit 4363d95

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎tests/test_app/tests/test_components.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,38 +182,61 @@ def test_component_view_to_component_args(self):
182182
def test_component_view_to_component_kwargs(self):
183183
self._click_btn_and_check_success("view_to_component_kwargs")
184184

185+
def _scroll_iframe_into_view(self, container_id: str) -> None:
186+
"""
187+
Scroll a `view_to_iframe` container into the browser viewport.
188+
189+
`view_to_iframe` renders the iframe with `loading="lazy"`, so the
190+
browser only fetches the iframe's document once it is scrolled close to
191+
the viewport. These iframes sit well below the fold of the home page and
192+
the shared browser page is (usually) already sitting on "/", so
193+
`navigate_to_page` performs no navigation and the page is never scrolled.
194+
Left alone, the browser can defer the iframe's document fetch long enough
195+
that the test's 30 second `wait_for` times out (observed on slow CI
196+
runners). Scrolling the container into view is the browser's documented
197+
trigger for a lazy load, so the document is fetched immediately and the
198+
test is not at the mercy of the browser's load-timing heuristics.
199+
"""
200+
self.page.locator(f"#{container_id}").scroll_into_view_if_needed()
201+
185202
@navigate_to_page("/")
186203
def test_component_view_to_iframe_sync_func(self):
204+
self._scroll_iframe_into_view("view_to_iframe_sync_func")
187205
self.page.frame_locator("#view_to_iframe_sync_func > iframe").locator(
188206
"#view_to_iframe_sync_func[data-success=true]"
189207
).wait_for()
190208

191209
@navigate_to_page("/")
192210
def test_component_view_to_iframe_async_func(self):
211+
self._scroll_iframe_into_view("view_to_iframe_async_func")
193212
self.page.frame_locator("#view_to_iframe_async_func > iframe").locator(
194213
"#view_to_iframe_async_func[data-success=true]"
195214
).wait_for()
196215

197216
@navigate_to_page("/")
198217
def test_component_view_to_iframe_sync_class(self):
218+
self._scroll_iframe_into_view("view_to_iframe_sync_class")
199219
self.page.frame_locator("#view_to_iframe_sync_class > iframe").locator(
200220
"#ViewToIframeSyncClass[data-success=true]"
201221
).wait_for()
202222

203223
@navigate_to_page("/")
204224
def test_component_view_to_iframe_async_class(self):
225+
self._scroll_iframe_into_view("view_to_iframe_async_class")
205226
self.page.frame_locator("#view_to_iframe_async_class > iframe").locator(
206227
"#ViewToIframeAsyncClass[data-success=true]"
207228
).wait_for()
208229

209230
@navigate_to_page("/")
210231
def test_component_view_to_iframe_template_view_class(self):
232+
self._scroll_iframe_into_view("view_to_iframe_template_view_class")
211233
self.page.frame_locator("#view_to_iframe_template_view_class > iframe").locator(
212234
"#ViewToIframeTemplateViewClass[data-success=true]"
213235
).wait_for()
214236

215237
@navigate_to_page("/")
216238
def test_component_view_to_iframe_args(self):
239+
self._scroll_iframe_into_view("view_to_iframe_args")
217240
self.page.frame_locator("#view_to_iframe_args > iframe").locator(
218241
"#view_to_iframe_args[data-success=Success]"
219242
).wait_for()

0 commit comments

Comments
 (0)