Skip to content

Commit

Permalink
fix: test flakiness
Browse files Browse the repository at this point in the history
Clicking on elements instead of pixel coordinates. ALso switched to `to_be_in_viewport` from `to_be_visible`
  • Loading branch information
iisakkirotko committed Sep 22, 2023
1 parent b984f4d commit 0e2fa9b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/integration/menu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def on_click():

child_button = page_session.locator("text=child")
page_session.wait_for_timeout(350) # Wait for any animations after click
expect(page_session.locator(".test-class-child")).to_be_visible
expect(page_session.locator(".test-class-child")).to_be_visible()
child_button.click()
page_session.wait_for_timeout(350)
expect(text_el).to_contain_text("Works!")
Expand All @@ -58,7 +58,7 @@ def test_menus_successive(test_type, solara_test, page_session: Page):

@solara.component
def Page():
menu_activator = solara.Div(style="height: 200px; width: 400px;")
menu_activator = solara.Div(style="height: 200px; width: 400px;", classes=["test-class-activator"])
menu_child = solara.Div(classes=["test-class-menu"], style="height: 100px; width: 50px;")

if test_type == "Menu":
Expand All @@ -70,19 +70,21 @@ def Page():

solara.display(Page())

activator_el = page_session.locator(".test-class-activator")
expect(page_session.locator(".test-class-menu")).to_have_count(0) # Menu should not exist yet
if test_type == "ContextMenu":
page_session.mouse.click(10, 10, button="right")
activator_el.click(button="right")
else:
page_session.mouse.click(10, 10)
activator_el.click()

page_session.wait_for_timeout(350) # Wait for any animations after click
expect(page_session.locator(".test-class-menu")).to_be_visible() # Menu should be visible now
expect(page_session.locator(".test-class-menu")).to_be_in_viewport() # Menu should be visible now

if test_type == "ContextMenu":
page_session.mouse.click(350, 10, button="right")
activator_el.click(button="right")
page_session.wait_for_timeout(350)
expect(page_session.locator(".test-class-menu")).to_be_visible()
expect(page_session.locator(".test-class-menu")).to_be_in_viewport()
else:
page_session.mouse.click(350, 10)
activator_el.click()
page_session.wait_for_timeout(350)
expect(page_session.locator(".test-class-menu")).not_to_be_visible() # After second click, Menu and ClickMenu should disappear
expect(page_session.locator(".test-class-menu")).not_to_be_in_viewport() # After second click, Menu and ClickMenu should disappear

0 comments on commit 0e2fa9b

Please sign in to comment.