-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathwheelTest.spec.js
89 lines (64 loc) · 3.16 KB
/
wheelTest.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const { By, Browser, Builder} = require('selenium-webdriver')
const assert = require('assert')
describe('Actions API - Wheel Tests', function () {
let driver
before(async function () {
driver = await new Builder().forBrowser('chrome').build();
})
after(async() => await driver.quit())
it('Scroll to element', async function () {
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
const iframe = await driver.findElement(By.css("iframe"))
await driver.actions()
.scroll(0, 0, 0, 0, iframe)
.perform()
assert.ok(await inViewport(iframe))
})
it('Scroll by given amount', async function () {
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
const footer = await driver.findElement(By.css("footer"))
const deltaY = (await footer.getRect()).y
await driver.actions()
.scroll(0, 0, 0, deltaY)
.perform()
await driver.sleep(500)
assert.ok(await inViewport(footer))
})
it('Scroll from an element by a given amount', async function () {
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
const iframe = await driver.findElement(By.css("iframe"))
await driver.actions()
.scroll(0, 0, 0, 200, iframe)
.perform()
await driver.sleep(500)
await driver.switchTo().frame(iframe)
const checkbox = await driver.findElement(By.name('scroll_checkbox'))
assert.ok(await inViewport(checkbox))
})
it('Scroll from an element with an offset', async function () {
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
const iframe = await driver.findElement(By.css("iframe"))
const footer = await driver.findElement(By.css("footer"))
await driver.actions()
.scroll(0, -50, 0, 200, footer)
.perform()
await driver.sleep(500)
await driver.switchTo().frame(iframe)
const checkbox = await driver.findElement(By.name('scroll_checkbox'))
assert.ok(await inViewport(checkbox))
})
it('Scroll from an offset of origin (element) by given amount', async function () {
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame.html")
const iframe = await driver.findElement(By.css("iframe"))
await driver.actions()
.scroll(10, 10, 0, 200)
.perform()
await driver.sleep(500)
await driver.switchTo().frame(iframe)
const checkbox = await driver.findElement(By.name('scroll_checkbox'))
assert.ok(await inViewport(checkbox))
})
function inViewport(element) {
return driver.executeScript("for(var e=arguments[0],f=e.offsetTop,t=e.offsetLeft,o=e.offsetWidth,n=e.offsetHeight;\ne.offsetParent;)f+=(e=e.offsetParent).offsetTop,t+=e.offsetLeft;\nreturn f<window.pageYOffset+window.innerHeight&&t<window.pageXOffset+window.innerWidth&&f+n>\nwindow.pageYOffset&&t+o>window.pageXOffset", element)
}
})