Skip to content

Commit 3336f6d

Browse files
JS/Kotlin adding examples and links (SeleniumHQ#1159)[deploy site]
* JS/Kotlin adding examples and links * Link JS examples * Fixing values * Fix JS test and update docs * Fix JS test example Co-authored-by: Titus Fortner <[email protected]>
1 parent b7d454c commit 3336f6d

File tree

5 files changed

+135
-40
lines changed

5 files changed

+135
-40
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const { By } = require('selenium-webdriver')
2+
const { suite } = require('selenium-webdriver/testing')
3+
const assert = require('assert')
4+
5+
suite(function (env) {
6+
describe('Actions API - Wheel Tests', function () {
7+
let driver
8+
9+
before(async function () {
10+
driver = await env.builder().build()
11+
})
12+
13+
after(async() => await driver.quit())
14+
15+
it('Scroll to element', async function () {
16+
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
17+
18+
const iframe = await driver.findElement(By.css("iframe"))
19+
20+
await driver.actions()
21+
.scroll(0, 0, 0, 0, iframe)
22+
.perform()
23+
24+
assert.ok(await inViewport(iframe))
25+
})
26+
27+
it('Scroll by given amount', async function () {
28+
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
29+
30+
const footer = await driver.findElement(By.css("footer"))
31+
const deltaY = (await footer.getRect()).y
32+
33+
await driver.actions()
34+
.scroll(0, 0, 0, deltaY)
35+
.perform()
36+
37+
await driver.sleep(500)
38+
39+
assert.ok(await inViewport(footer))
40+
})
41+
42+
it('Scroll from an element by a given amount', async function () {
43+
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
44+
45+
const iframe = await driver.findElement(By.css("iframe"))
46+
47+
await driver.actions()
48+
.scroll(0, 0, 0, 200, iframe)
49+
.perform()
50+
51+
await driver.sleep(500)
52+
53+
await driver.switchTo().frame(iframe)
54+
const checkbox = await driver.findElement(By.name('scroll_checkbox'))
55+
assert.ok(await inViewport(checkbox))
56+
})
57+
58+
it('Scroll from an element with an offset', async function () {
59+
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html")
60+
61+
const iframe = await driver.findElement(By.css("iframe"))
62+
const footer = await driver.findElement(By.css("footer"))
63+
64+
await driver.actions()
65+
.scroll(0, -50, 0, 200, footer)
66+
.perform()
67+
68+
await driver.sleep(500)
69+
70+
await driver.switchTo().frame(iframe)
71+
const checkbox = await driver.findElement(By.name('scroll_checkbox'))
72+
assert.ok(await inViewport(checkbox))
73+
})
74+
75+
it('Scroll from an offset of origin (element) by given amount', async function () {
76+
await driver.get("https://www.selenium.dev/selenium/web/scrolling_tests/frame_with_nested_scrolling_frame.html")
77+
78+
const iframe = await driver.findElement(By.css("iframe"))
79+
80+
await driver.actions()
81+
.scroll(10, 10, 0, 200)
82+
.perform()
83+
84+
await driver.sleep(500)
85+
86+
await driver.switchTo().frame(iframe)
87+
const checkbox = await driver.findElement(By.name('scroll_checkbox'))
88+
assert.ok(await inViewport(checkbox))
89+
})
90+
91+
function inViewport(element) {
92+
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)
93+
}
94+
})
95+
})

website_and_docs/content/documentation/webdriver/actions_api/wheel.en.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ the viewport will be scrolled so the bottom of the element is at the bottom of t
3636
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L11-L14" >}}
3737
{{< /tab >}}
3838
{{< tab header="JavaScript" >}}
39-
{{< badge-code >}}
39+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L18-L22" >}}
4040
{{< /tab >}}
4141
{{< tab header="Kotlin" >}}
42-
{{< badge-code >}}
42+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L18-L21" >}}
4343
{{< /tab >}}
4444
{{< /tabpane >}}
4545

@@ -62,10 +62,10 @@ in the right and down directions. Negative values represent left and up, respect
6262
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L22-L26" >}}
6363
{{< /tab >}}
6464
{{< tab header="JavaScript" >}}
65-
{{< badge-code >}}
65+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L30-L35" >}}
6666
{{< /tab >}}
6767
{{< tab header="Kotlin" >}}
68-
{{< badge-code >}}
68+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L30-L34" >}}
6969
{{< /tab >}}
7070
{{< /tabpane >}}
7171

@@ -95,10 +95,10 @@ delta x and delta y values.
9595
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L34-L38" >}}
9696
{{< /tab >}}
9797
{{< tab header="JavaScript" >}}
98-
{{< badge-code >}}
98+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L45-L49" >}}
9999
{{< /tab >}}
100100
{{< tab header="Kotlin" >}}
101-
{{< badge-code >}}
101+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L43-L47" >}}
102102
{{< /tab >}}
103103
{{< /tabpane >}}
104104

@@ -134,10 +134,10 @@ it will result in an exception.
134134
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L48-L52" >}}
135135
{{< /tab >}}
136136
{{< tab header="JavaScript" >}}
137-
{{< badge-code >}}
137+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L62-L66" >}}
138138
{{< /tab >}}
139139
{{< tab header="Kotlin" >}}
140-
{{< badge-code >}}
140+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L59-L63" >}}
141141
{{< /tab >}}
142142
{{< /tabpane >}}
143143

@@ -168,9 +168,9 @@ it will result in an exception.
168168
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L63-L66" >}}
169169
{{< /tab >}}
170170
{{< tab header="JavaScript" >}}
171-
{{< badge-code >}}
171+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L80-L82" >}}
172172
{{< /tab >}}
173173
{{< tab header="Kotlin" >}}
174-
{{< badge-code >}}
174+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L75-L78" >}}
175175
{{< /tab >}}
176176
{{< /tabpane >}}

website_and_docs/content/documentation/webdriver/actions_api/wheel.ja.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ the viewport will be scrolled so the bottom of the element is at the bottom of t
3636
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L11-L14" >}}
3737
{{< /tab >}}
3838
{{< tab header="JavaScript" >}}
39-
{{< badge-code >}}
39+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L18-L22" >}}
4040
{{< /tab >}}
4141
{{< tab header="Kotlin" >}}
42-
{{< badge-code >}}
42+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L18-L21" >}}
4343
{{< /tab >}}
4444
{{< /tabpane >}}
4545

@@ -62,10 +62,10 @@ in the right and down directions. Negative values represent left and up, respect
6262
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L22-L26" >}}
6363
{{< /tab >}}
6464
{{< tab header="JavaScript" >}}
65-
{{< badge-code >}}
65+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L30-L35" >}}
6666
{{< /tab >}}
6767
{{< tab header="Kotlin" >}}
68-
{{< badge-code >}}
68+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L30-L34" >}}
6969
{{< /tab >}}
7070
{{< /tabpane >}}
7171

@@ -95,10 +95,10 @@ delta x and delta y values.
9595
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L34-L38" >}}
9696
{{< /tab >}}
9797
{{< tab header="JavaScript" >}}
98-
{{< badge-code >}}
98+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L45-L49" >}}
9999
{{< /tab >}}
100100
{{< tab header="Kotlin" >}}
101-
{{< badge-code >}}
101+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L43-L47" >}}
102102
{{< /tab >}}
103103
{{< /tabpane >}}
104104

@@ -134,10 +134,10 @@ it will result in an exception.
134134
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L48-L52" >}}
135135
{{< /tab >}}
136136
{{< tab header="JavaScript" >}}
137-
{{< badge-code >}}
137+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L62-L66" >}}
138138
{{< /tab >}}
139139
{{< tab header="Kotlin" >}}
140-
{{< badge-code >}}
140+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L59-L63" >}}
141141
{{< /tab >}}
142142
{{< /tabpane >}}
143143

@@ -168,9 +168,9 @@ it will result in an exception.
168168
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L63-L66" >}}
169169
{{< /tab >}}
170170
{{< tab header="JavaScript" >}}
171-
{{< badge-code >}}
171+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L80-L82" >}}
172172
{{< /tab >}}
173173
{{< tab header="Kotlin" >}}
174-
{{< badge-code >}}
174+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L75-L78" >}}
175175
{{< /tab >}}
176176
{{< /tabpane >}}

website_and_docs/content/documentation/webdriver/actions_api/wheel.pt-br.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ the viewport will be scrolled so the bottom of the element is at the bottom of t
3636
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L11-L14" >}}
3737
{{< /tab >}}
3838
{{< tab header="JavaScript" >}}
39-
{{< badge-code >}}
39+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L18-L22" >}}
4040
{{< /tab >}}
4141
{{< tab header="Kotlin" >}}
42-
{{< badge-code >}}
42+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L18-L21" >}}
4343
{{< /tab >}}
4444
{{< /tabpane >}}
4545

@@ -62,10 +62,10 @@ in the right and down directions. Negative values represent left and up, respect
6262
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L22-L26" >}}
6363
{{< /tab >}}
6464
{{< tab header="JavaScript" >}}
65-
{{< badge-code >}}
65+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L30-L35" >}}
6666
{{< /tab >}}
6767
{{< tab header="Kotlin" >}}
68-
{{< badge-code >}}
68+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L30-L34" >}}
6969
{{< /tab >}}
7070
{{< /tabpane >}}
7171

@@ -95,10 +95,10 @@ delta x and delta y values.
9595
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L34-L38" >}}
9696
{{< /tab >}}
9797
{{< tab header="JavaScript" >}}
98-
{{< badge-code >}}
98+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L45-L49" >}}
9999
{{< /tab >}}
100100
{{< tab header="Kotlin" >}}
101-
{{< badge-code >}}
101+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L43-L47" >}}
102102
{{< /tab >}}
103103
{{< /tabpane >}}
104104

@@ -134,10 +134,10 @@ it will result in an exception.
134134
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L48-L52" >}}
135135
{{< /tab >}}
136136
{{< tab header="JavaScript" >}}
137-
{{< badge-code >}}
137+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L62-L66" >}}
138138
{{< /tab >}}
139139
{{< tab header="Kotlin" >}}
140-
{{< badge-code >}}
140+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L59-L63" >}}
141141
{{< /tab >}}
142142
{{< /tabpane >}}
143143

@@ -168,9 +168,9 @@ it will result in an exception.
168168
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L63-L66" >}}
169169
{{< /tab >}}
170170
{{< tab header="JavaScript" >}}
171-
{{< badge-code >}}
171+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L80-L82" >}}
172172
{{< /tab >}}
173173
{{< tab header="Kotlin" >}}
174-
{{< badge-code >}}
174+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L75-L78" >}}
175175
{{< /tab >}}
176176
{{< /tabpane >}}

website_and_docs/content/documentation/webdriver/actions_api/wheel.zh-cn.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ the viewport will be scrolled so the bottom of the element is at the bottom of t
3636
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L11-L14" >}}
3737
{{< /tab >}}
3838
{{< tab header="JavaScript" >}}
39-
{{< badge-code >}}
39+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L18-L22" >}}
4040
{{< /tab >}}
4141
{{< tab header="Kotlin" >}}
42-
{{< badge-code >}}
42+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L18-L21" >}}
4343
{{< /tab >}}
4444
{{< /tabpane >}}
4545

@@ -62,10 +62,10 @@ in the right and down directions. Negative values represent left and up, respect
6262
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L22-L26" >}}
6363
{{< /tab >}}
6464
{{< tab header="JavaScript" >}}
65-
{{< badge-code >}}
65+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L30-L35" >}}
6666
{{< /tab >}}
6767
{{< tab header="Kotlin" >}}
68-
{{< badge-code >}}
68+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L30-L34" >}}
6969
{{< /tab >}}
7070
{{< /tabpane >}}
7171

@@ -95,10 +95,10 @@ delta x and delta y values.
9595
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L34-L38" >}}
9696
{{< /tab >}}
9797
{{< tab header="JavaScript" >}}
98-
{{< badge-code >}}
98+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L45-L49" >}}
9999
{{< /tab >}}
100100
{{< tab header="Kotlin" >}}
101-
{{< badge-code >}}
101+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L43-L47" >}}
102102
{{< /tab >}}
103103
{{< /tabpane >}}
104104

@@ -134,10 +134,10 @@ it will result in an exception.
134134
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L48-L52" >}}
135135
{{< /tab >}}
136136
{{< tab header="JavaScript" >}}
137-
{{< badge-code >}}
137+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L62-L66" >}}
138138
{{< /tab >}}
139139
{{< tab header="Kotlin" >}}
140-
{{< badge-code >}}
140+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L59-L63" >}}
141141
{{< /tab >}}
142142
{{< /tabpane >}}
143143

@@ -168,9 +168,9 @@ it will result in an exception.
168168
{{< gh-codeblock path="examples/ruby/spec/actions_api/wheel_spec.rb#L63-L66" >}}
169169
{{< /tab >}}
170170
{{< tab header="JavaScript" >}}
171-
{{< badge-code >}}
171+
{{< gh-codeblock path="examples/javascript/test/actionsApi/wheelTest.spec.js#L80-L82" >}}
172172
{{< /tab >}}
173173
{{< tab header="Kotlin" >}}
174-
{{< badge-code >}}
174+
{{< gh-codeblock path="examples/kotlin/src/test/kotlin/dev/selenium/actions_api/WheelTest.kt#L75-L78" >}}
175175
{{< /tab >}}
176176
{{< /tabpane >}}

0 commit comments

Comments
 (0)