Skip to content

Commit dea186d

Browse files
committed
Add wait_for_tag to avoid race condition in display isolation test
Attempts to fix flakiness in `test_display_isolation`. We now ensure the iframe has been added to the dom before calling the selector. To make this work, we clean up the iframe cells (and all other cells) at the end of each test. I'm not 100% positive this fixes, since I haven't been able to reproduce the failure. But the hope is that this fixes the intermittent failing seen in #4182.
1 parent c9378c7 commit dea186d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

notebook/tests/selenium/test_display_isolation.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
An object whose metadata contains an "isolated" tag must be isolated
44
from the rest of the document.
55
"""
6+
from .utils import wait_for_tag
67

78

89
def test_display_isolation(notebook):
@@ -26,7 +27,7 @@ def isolated_html(notebook):
2627
"""
2728
red = 'rgb(255, 0, 0)'
2829
blue = 'rgb(0, 0, 255)'
29-
test_str = "<div id='test'>Should be red from non-isolation</div>"
30+
test_str = "<div id='test'>Should turn red from non-isolation</div>"
3031
notebook.add_and_execute_cell(content="display(HTML(%r))" % test_str)
3132
non_isolated = (
3233
"<style>div{color:%s;}</style>" % red +
@@ -41,6 +42,8 @@ def isolated_html(notebook):
4142
isolated)
4243
notebook.add_and_execute_cell(content=display_i)
4344

45+
wait_for_tag(notebook.browser, "iframe")
46+
4447
# The non-isolated div will be in the body
4548
non_isolated_div = notebook.body.find_element_by_id("non-isolated")
4649
assert non_isolated_div.value_of_css_property("color") == red
@@ -55,6 +58,9 @@ def isolated_html(notebook):
5558
isolated_div = notebook.browser.find_element_by_id("isolated")
5659
assert isolated_div.value_of_css_property("color") == blue
5760
notebook.browser.switch_to.default_content()
61+
# Clean up the html test cells
62+
for i in range(1, len(notebook.cells)):
63+
notebook.delete_cell(1)
5864

5965

6066
def isolated_svg(notebook):
@@ -73,16 +79,20 @@ def isolated_svg(notebook):
7379
content="display_svg(SVG(s1), metadata=dict(isolated=True))")
7480
notebook.add_and_execute_cell(
7581
content="display_svg(SVG(s2), metadata=dict(isolated=True))")
82+
wait_for_tag(notebook.browser, "iframe")
7683
iframes = notebook.body.find_elements_by_tag_name("iframe")
7784

7885
# The first rectangle will be red
79-
notebook.browser.switch_to.frame(iframes[1])
86+
notebook.browser.switch_to.frame(iframes[0])
8087
isolated_svg_1 = notebook.browser.find_element_by_id('r1')
8188
assert isolated_svg_1.value_of_css_property("fill") == yellow
8289
notebook.browser.switch_to.default_content()
8390

8491
# The second rectangle will be black
85-
notebook.browser.switch_to.frame(iframes[2])
92+
notebook.browser.switch_to.frame(iframes[1])
8693
isolated_svg_2 = notebook.browser.find_element_by_id('r2')
8794
assert isolated_svg_2.value_of_css_property("fill") == black
8895

96+
# Clean up the svg test cells
97+
for i in range(1, len(notebook.cells)):
98+
notebook.delete_cell(1)

0 commit comments

Comments
 (0)