Skip to content
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
39 changes: 24 additions & 15 deletions py/test/selenium/webdriver/common/_bidi/input_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,24 @@ def _center(element):
return location["x"] + size["width"] // 2, location["y"] + size["height"] // 2


def test_basic_key_input(driver, pages):
def _load_single_text_input(driver, pages):
"""Return ``#textInput`` once it is the active element.

``single_text_input.html`` relies on ``autofocus``, which Firefox may apply after the load event.
Dispatching keys before then sends them to ``<body>`` and drops the leading characters, so focus is
requested explicitly and confirmed rather than assumed.
"""
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
driver.execute_script("arguments[0].focus();", input_element)
WebDriverWait(driver, 5).until(
lambda d: d.execute_script("return document.activeElement === arguments[0];", input_element)
)
return input_element


def test_basic_key_input(driver, pages):
input_element = _load_single_text_input(driver, pages)

key_actions = KeySourceActions(
id="keyboard",
Expand All @@ -75,8 +90,7 @@ def test_basic_key_input(driver, pages):


def test_key_input_with_pause(driver, pages):
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

key_actions = KeySourceActions(
id="keyboard",
Expand Down Expand Up @@ -161,8 +175,7 @@ def test_wheel_scroll(driver, pages):


def test_combined_input_actions(driver, pages):
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)
x, y = _center(input_element)

pointer_actions = PointerSourceActions(
Expand Down Expand Up @@ -238,8 +251,7 @@ def test_set_multiple_files(driver):


def test_release_actions(driver, pages):
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

Input(driver).perform_actions(
context=driver.current_window_handle,
Expand All @@ -255,16 +267,15 @@ def test_release_actions(driver, pages):


def test_perform_actions_with_none_source(driver, pages):
pages.load("single_text_input.html")
input_element = _load_single_text_input(driver, pages)
none_actions = NoneSourceActions(id="none_id", actions=[PauseAction(duration=100), PauseAction(duration=50)])
Input(driver).perform_actions(context=driver.current_window_handle, actions=[none_actions])

assert driver.find_element(By.ID, "textInput").get_attribute("value") == ""
assert input_element.get_attribute("value") == ""


def test_perform_actions_rapid_key_sequence(driver, pages):
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

key_actions = KeySourceActions(
id="keyboard",
Expand Down Expand Up @@ -396,8 +407,7 @@ def test_wheel_scroll_horizontal(driver, pages):


def test_key_input_special_characters(driver, pages):
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

key_actions = KeySourceActions(
id="keyboard",
Expand Down Expand Up @@ -510,8 +520,7 @@ def test_combined_keyboard_and_wheel_actions(driver, pages):


def test_key_input_with_value_attribute(driver, pages):
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

key_actions = KeySourceActions(
id="keyboard",
Expand Down
47 changes: 24 additions & 23 deletions py/test/selenium/webdriver/common/bidi/input_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,30 @@
from selenium.webdriver.support.ui import WebDriverWait


def _load_single_text_input(driver, pages):
"""Return ``#textInput`` once it is the active element.

``single_text_input.html`` relies on ``autofocus``, which Firefox may apply after the load event.
Dispatching keys before then sends them to ``<body>`` and drops the leading characters, so focus is
requested explicitly and confirmed rather than assumed.
"""
pages.load("single_text_input.html")
input_element = driver.find_element(By.ID, "textInput")
driver.execute_script("arguments[0].focus();", input_element)
WebDriverWait(driver, 5).until(
lambda d: d.execute_script("return document.activeElement === arguments[0];", input_element)
)
return input_element


def test_input_initialized(driver):
"""Test that the input module is initialized properly."""
assert driver.input is not None


def test_basic_key_input(driver, pages):
"""Test basic keyboard input using BiDi."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# Create keyboard actions to type "hello"
key_actions = KeySourceActions(
Expand All @@ -80,9 +94,7 @@ def test_basic_key_input(driver, pages):

def test_key_input_with_pause(driver, pages):
"""Test keyboard input with pause actions."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# Create keyboard actions with pauses
key_actions = KeySourceActions(
Expand Down Expand Up @@ -216,9 +228,7 @@ def test_wheel_scroll(driver, pages):

def test_combined_input_actions(driver, pages):
"""Test combining multiple input sources."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# First click on the input field, then type
location = input_element.location
Expand Down Expand Up @@ -324,9 +334,7 @@ def test_set_multiple_files(driver):

def test_release_actions(driver, pages):
"""Test releasing input actions."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# Perform some actions first
key_actions = KeySourceActions(
Expand Down Expand Up @@ -428,7 +436,7 @@ def file_dialog_handler(file_dialog_info):

def test_perform_actions_with_none_source(driver, pages):
"""Test performing NoneSourceActions (pause only)."""
pages.load("single_text_input.html")
input_element = _load_single_text_input(driver, pages)

# Create none actions (pause only - no actual input)
none_actions = NoneSourceActions(
Expand All @@ -443,15 +451,12 @@ def test_perform_actions_with_none_source(driver, pages):
driver.input.perform_actions(driver.current_window_handle, [none_actions])

# Verify input field is still empty
input_element = driver.find_element(By.ID, "textInput")
assert input_element.get_attribute("value") == ""


def test_perform_actions_rapid_key_sequence(driver, pages):
"""Test rapid key input sequence without pause between keys."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# Create rapid key sequence
key_actions = KeySourceActions(
Expand Down Expand Up @@ -659,9 +664,7 @@ def test_wheel_scroll_horizontal(driver, pages):

def test_key_input_special_characters(driver, pages):
"""Test keyboard input with special characters."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# Create keyboard actions for special characters
key_actions = KeySourceActions(
Expand Down Expand Up @@ -855,9 +858,7 @@ def test_combined_keyboard_and_wheel_actions(driver, pages):

def test_key_input_with_value_attribute(driver, pages):
"""Test KeyDownAction and KeyUpAction use value attribute correctly."""
pages.load("single_text_input.html")

input_element = driver.find_element(By.ID, "textInput")
input_element = _load_single_text_input(driver, pages)

# Use explicit value attribute in actions
key_actions = KeySourceActions(
Expand Down
Loading