Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test in examples python #2042

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions examples/python/tests/actions_api/test_mouse.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import pytest
from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.mouse_button import MouseButton
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


def test_click_and_hold(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

clickable = driver.find_element(By.ID, "clickable")
ActionChains(driver)\
.click_and_hold(clickable)\
ActionChains(driver) \
.click_and_hold(clickable) \
.perform()

sleep(0.5)
Expand All @@ -22,8 +24,8 @@ def test_click_and_release(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

clickable = driver.find_element(By.ID, "click")
ActionChains(driver)\
.click(clickable)\
ActionChains(driver) \
.click(clickable) \
.perform()

assert "resultPage.html" in driver.current_url
Expand All @@ -33,8 +35,8 @@ def test_right_click(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

clickable = driver.find_element(By.ID, "clickable")
ActionChains(driver)\
.context_click(clickable)\
ActionChains(driver) \
.context_click(clickable) \
.perform()

sleep(0.5)
Expand Down Expand Up @@ -72,8 +74,8 @@ def test_double_click(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

clickable = driver.find_element(By.ID, "clickable")
ActionChains(driver)\
.double_click(clickable)\
ActionChains(driver) \
.double_click(clickable) \
.perform()

assert driver.find_element(By.ID, "click-status").text == "double-clicked"
Expand All @@ -83,8 +85,8 @@ def test_hover(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

hoverable = driver.find_element(By.ID, "hover")
ActionChains(driver)\
.move_to_element(hoverable)\
ActionChains(driver) \
.move_to_element(hoverable) \
.perform()

assert driver.find_element(By.ID, "move-status").text == "hovered"
Expand All @@ -94,8 +96,8 @@ def test_move_by_offset_from_element(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

mouse_tracker = driver.find_element(By.ID, "mouse-tracker")
ActionChains(driver)\
.move_to_element_with_offset(mouse_tracker, 8, 0)\
ActionChains(driver) \
.move_to_element_with_offset(mouse_tracker, 8, 0) \
.perform()

coordinates = driver.find_element(By.ID, "relative-location").text.split(", ")
Expand All @@ -104,7 +106,7 @@ def test_move_by_offset_from_element(driver):

def test_move_by_offset_from_viewport_origin_ab(driver):
driver.get('https://selenium.dev/selenium/web/mouse_interaction.html')

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "absolute-location")))
action = ActionBuilder(driver)
action.pointer_action.move_to_location(8, 0)
action.perform()
Expand All @@ -121,8 +123,8 @@ def test_move_by_offset_from_current_pointer_ab(driver):
action.pointer_action.move_to_location(6, 3)
action.perform()

ActionChains(driver)\
.move_by_offset( 13, 15)\
ActionChains(driver) \
.move_by_offset(13, 15) \
.perform()

coordinates = driver.find_element(By.ID, "absolute-location").text.split(", ")
Expand All @@ -136,8 +138,8 @@ def test_drag_and_drop_onto_element(driver):

draggable = driver.find_element(By.ID, "draggable")
droppable = driver.find_element(By.ID, "droppable")
ActionChains(driver)\
.drag_and_drop(draggable, droppable)\
ActionChains(driver) \
.drag_and_drop(draggable, droppable) \
.perform()

assert driver.find_element(By.ID, "drop-status").text == "dropped"
Expand All @@ -149,15 +151,8 @@ def test_drag_and_drop_by_offset(driver):
draggable = driver.find_element(By.ID, "draggable")
start = draggable.location
finish = driver.find_element(By.ID, "droppable").location
ActionChains(driver)\
.drag_and_drop_by_offset(draggable, finish['x'] - start['x'], finish['y'] - start['y'])\
ActionChains(driver) \
.drag_and_drop_by_offset(draggable, finish['x'] - start['x'], finish['y'] - start['y']) \
.perform()

assert driver.find_element(By.ID, "drop-status").text == "dropped"







3 changes: 3 additions & 0 deletions examples/python/tests/bidi/cdp/test_script.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.common.log import Log
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


@pytest.mark.trio
async def test_mutation(driver):
async with driver.bidi_connection() as session:
async with Log(driver, session).mutation_events() as event:
driver.get('https://www.selenium.dev/selenium/web/dynamic.html')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "reveal")))
driver.find_element(By.ID, "reveal").click()

assert event["element"] == driver.find_element(By.ID, "revealed")
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is useful for focusing a specific element:
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L22-L25" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L12-L15" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L14-L17" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L17-L20" >}}
Expand All @@ -51,7 +51,7 @@ This is otherwise known as "clicking":
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L34-L37" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L24-L27" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L26-L29" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L30-L33" >}}
Expand Down Expand Up @@ -86,7 +86,7 @@ This is otherwise known as "right-clicking":
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L46-L49" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L35-L38" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L37-L40" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L43-L46" >}}
Expand All @@ -112,7 +112,7 @@ There is no convenience method for this, it is just pressing and releasing mouse
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.2" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L49-L52" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L51-L54" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< badge-version version="4.2" >}}
Expand Down Expand Up @@ -141,7 +141,7 @@ There is no convenience method for this, it is just pressing and releasing mouse
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.2" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L63-L66" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L65-L68" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< badge-version version="4.2" >}}
Expand Down Expand Up @@ -169,7 +169,7 @@ This method combines moving to the center of an element with pressing and releas
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L93-L96" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L74-L77" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L76-L79" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L91-L94" >}}
Expand All @@ -196,7 +196,7 @@ Note that the element must be in the viewport or else the command will error.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L105-L108" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L85-L88" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L87-L90" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L104-L107" >}}
Expand Down Expand Up @@ -228,7 +228,7 @@ then moves by the provided offset.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L118-L121" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L96-L99" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L98-L101" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L132-L135" >}}
Expand All @@ -254,7 +254,7 @@ offset.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L131-L136" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L108-L110" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L110-L112" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L146-L150" >}}
Expand Down Expand Up @@ -286,7 +286,7 @@ the current mouse position.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L153-L155" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L124-L126" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L126-L128" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L167-L169" >}}
Expand All @@ -312,7 +312,7 @@ moves to the location of the target element and then releases the mouse.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L166-L170" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L137-L141" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L139-L143" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L181-L185" >}}
Expand All @@ -337,7 +337,7 @@ This method firstly performs a click-and-hold on the source element, moves to th
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L179-L184" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L149-L154" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L151-L156" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L195-L200" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is useful for focusing a specific element:
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L22-L25" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L12-L15" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L14-L17" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L17-L20" >}}
Expand All @@ -51,7 +51,7 @@ This is otherwise known as "clicking":
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L34-L37" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L24-L27" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L26-L29" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L30-L33" >}}
Expand Down Expand Up @@ -86,7 +86,7 @@ This is otherwise known as "right-clicking":
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L46-L49" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L35-L38" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L37-L40" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L43-L46" >}}
Expand All @@ -112,7 +112,7 @@ There is no convenience method for this, it is just pressing and releasing mouse
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.2" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L49-L52" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L51-L54" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< badge-version version="4.2" >}}
Expand Down Expand Up @@ -141,7 +141,7 @@ There is no convenience method for this, it is just pressing and releasing mouse
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.2" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L63-L66" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L65-L68" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< badge-version version="4.2" >}}
Expand Down Expand Up @@ -169,7 +169,7 @@ This method combines moving to the center of an element with pressing and releas
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L93-L96" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L74-L77" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L76-L79" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L91-L94" >}}
Expand All @@ -196,7 +196,7 @@ Note that the element must be in the viewport or else the command will error.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L105-L108" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L85-L88" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L87-L90" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L104-L107" >}}
Expand Down Expand Up @@ -228,7 +228,7 @@ then moves by the provided offset.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L118-L121" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L96-L99" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L98-L101" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L132-L135" >}}
Expand All @@ -254,7 +254,7 @@ offset.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L131-L136" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L108-L110" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L110-L112" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L146-L150" >}}
Expand Down Expand Up @@ -286,7 +286,7 @@ the current mouse position.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L153-L155" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L124-L126" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L126-L128" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L167-L169" >}}
Expand All @@ -312,7 +312,7 @@ moves to the location of the target element and then releases the mouse.
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L166-L170" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L137-L141" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L139-L143" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L181-L185" >}}
Expand All @@ -337,7 +337,7 @@ This method firstly performs a click-and-hold on the source element, moves to th
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/actions_api/MouseTest.java#L179-L184" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L149-L154" >}}
{{< gh-codeblock path="/examples/python/tests/actions_api/test_mouse.py#L151-L156" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/ActionsAPI/MouseTest.cs#L195-L200" >}}
Expand Down
Loading
Loading