Skip to content

Commit dab928e

Browse files
committed
[py] add more scroll tests
1 parent 273644a commit dab928e

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

‎py/test/selenium/webdriver/common/interactions_tests.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
"""Tests for advanced user interactions."""
1919
import pytest
20+
from selenium.common.exceptions import MoveTargetOutOfBoundsException
2021

2122
from selenium.webdriver.common.by import By
2223
from selenium.webdriver.common.keys import Keys
@@ -260,6 +261,93 @@ def test_can_pause(driver, pages):
260261
assert "Clicked" == toDoubleClick.get_attribute('value')
261262

262263

264+
@pytest.mark.xfail_firefox
265+
@pytest.mark.xfail_remote
266+
def test_can_scroll_to_element(driver, pages):
267+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
268+
iframe = driver.find_element(By.TAG_NAME, "iframe")
269+
270+
assert not _in_viewport(driver, iframe)
271+
272+
ActionChains(driver).scroll(0, 0, 0, 0, origin=iframe).perform()
273+
274+
assert _in_viewport(driver, iframe)
275+
276+
277+
@pytest.mark.xfail_firefox
278+
@pytest.mark.xfail_remote
279+
def test_can_scroll_from_element_by_amount(driver, pages):
280+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
281+
iframe = driver.find_element(By.TAG_NAME, "iframe")
282+
283+
ActionChains(driver).scroll(0, 0, 0, 200, origin=iframe).pause(0.2).perform()
284+
285+
driver.switch_to.frame(iframe)
286+
checkbox = driver.find_element(By.NAME, "scroll_checkbox")
287+
288+
assert _in_viewport(driver, checkbox)
289+
290+
291+
@pytest.mark.xfail_firefox
292+
@pytest.mark.xfail_remote
293+
def test_can_scroll_from_element_with_offset_by_amount(driver, pages):
294+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
295+
footer = driver.find_element(By.TAG_NAME, "footer")
296+
297+
ActionChains(driver).scroll(0, -50, 0, 200, origin=footer).pause(0.2).perform()
298+
299+
iframe = driver.find_element(By.TAG_NAME, "iframe")
300+
driver.switch_to.frame(iframe)
301+
checkbox = driver.find_element(By.NAME, "scroll_checkbox")
302+
303+
assert _in_viewport(driver, checkbox)
304+
305+
306+
@pytest.mark.xfail_firefox
307+
@pytest.mark.xfail_remote
308+
def test_errors_when_element_offset_not_in_viewport(driver, pages):
309+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
310+
footer = driver.find_element(By.TAG_NAME, "footer")
311+
312+
with pytest.raises(MoveTargetOutOfBoundsException):
313+
ActionChains(driver).scroll(0, 50, 0, 200, origin=footer).perform()
314+
315+
316+
@pytest.mark.xfail_firefox
317+
@pytest.mark.xfail_remote
318+
def test_can_scroll_from_viewport_by_amount(driver, pages):
319+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
320+
footer = driver.find_element(By.TAG_NAME, "footer")
321+
y = footer.rect['y']
322+
323+
ActionChains(driver).scroll(0, 0, 0, y, origin="viewport").pause(0.2).perform()
324+
325+
assert _in_viewport(driver, footer)
326+
327+
328+
@pytest.mark.xfail_firefox
329+
@pytest.mark.xfail_remote
330+
def test_can_scroll_from_viewport_with_offset_by_amount(driver, pages):
331+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame.html")
332+
iframe = driver.find_element(By.TAG_NAME, "iframe")
333+
334+
ActionChains(driver).scroll(10, 10, 0, 200, origin="viewport").pause(0.2).perform()
335+
336+
driver.switch_to.frame(iframe)
337+
checkbox = driver.find_element(By.NAME, "scroll_checkbox")
338+
339+
assert _in_viewport(driver, checkbox)
340+
341+
342+
@pytest.mark.xfail_firefox
343+
@pytest.mark.xfail_remote
344+
def test_errors_when_origin_offset_not_in_viewport(driver, pages):
345+
pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
346+
347+
with pytest.raises(MoveTargetOutOfBoundsException):
348+
ActionChains(driver).scroll(-10, -10, 0, 200, origin="viewport").perform()
349+
350+
263351
@pytest.mark.xfail_firefox
264352
@pytest.mark.xfail_remote
265353
def test_can_scroll_mouse_wheel(driver, pages):
@@ -294,3 +382,13 @@ def _get_events(driver):
294382
if "code" in e and e["code"] == "Unidentified":
295383
e["code"] = ""
296384
return events
385+
386+
387+
def _in_viewport(driver, element):
388+
script = (
389+
"for(var e=arguments[0],f=e.offsetTop,t=e.offsetLeft,o=e.offsetWidth,n=e.offsetHeight;\n"
390+
"e.offsetParent;)f+=(e=e.offsetParent).offsetTop,t+=e.offsetLeft;\n"
391+
"return f<window.pageYOffset+window.innerHeight&&t<window.pageXOffset+window.innerWidth&&f+n>\n"
392+
"window.pageYOffset&&t+o>window.pageXOffset"
393+
)
394+
return driver.execute_script(script, element)

0 commit comments

Comments
 (0)