Skip to content

Commit 1a2a35b

Browse files
committed
[java] change scroll wheel class name from origin to scroll origin to match .NET
1 parent 08052f7 commit 1a2a35b

4 files changed

Lines changed: 37 additions & 69 deletions

File tree

java/src/org/openqa/selenium/interactions/Actions.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,20 @@ public Actions release(WebElement target) {
272272
}
273273

274274
/**
275+
* Scrolls by the provided amount from a designated origination point.
276+
* The scroll origin is either the center of an element or the upper left of the viewport plus offsets.
277+
* If the origin is an element, and the element is not in the viewport, the bottom of the element will first
278+
* be scrolled to the bottom of the viewport.
275279
*
276280
* @param x The horizontal offset from the origin from which to start the scroll.
277281
* @param y The vertical offset from the origin from which to start the scroll.
278282
* @param deltaX The distance along X axis to scroll using the wheel. A negative value scrolls left.
279283
* @param deltaY The distance along Y axis to scroll using the wheel. A negative value scrolls up.
280-
* @param origin Where scroll originates, either the viewport or the center of an element.
284+
* @param scrollOrigin Where scroll originates, either the viewport or the center of an element.
281285
* @return A self reference.
282286
*/
283-
public Actions scroll( int x, int y, int deltaX, int deltaY, WheelInput.Origin origin) {
284-
return tick(getActiveWheel().createScroll(x, y, deltaX, deltaY, Duration.ofMillis(250), origin));
287+
public Actions scroll( int x, int y, int deltaX, int deltaY, WheelInput.ScrollOrigin scrollOrigin) {
288+
return tick(getActiveWheel().createScroll(x, y, deltaX, deltaY, Duration.ofMillis(250), scrollOrigin));
285289
}
286290

287291
/**

java/src/org/openqa/selenium/interactions/WheelInput.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public SourceType getInputType() {
5050
return SourceType.WHEEL;
5151
}
5252

53-
public Interaction createScroll(
54-
int x, int y, int deltaX, int deltaY, Duration duration, Origin origin) {
53+
public Interaction createScroll(int x, int y, int deltaX, int deltaY, Duration duration, ScrollOrigin origin) {
5554
return new ScrollInteraction(this, x, y, deltaX, deltaY, duration, origin);
5655
}
5756

@@ -72,7 +71,7 @@ static class ScrollInteraction extends Interaction implements Encodable {
7271
private final int deltaX;
7372
private final int deltaY;
7473
private final Duration duration;
75-
private final Origin origin;
74+
private final ScrollOrigin origin;
7675

7776
protected ScrollInteraction(
7877
InputSource source,
@@ -81,7 +80,7 @@ protected ScrollInteraction(
8180
int deltaX,
8281
int deltaY,
8382
Duration duration,
84-
Origin origin) {
83+
ScrollOrigin origin) {
8584
super(source);
8685

8786
this.x = x;
@@ -108,7 +107,7 @@ public Map<String, Object> encode() {
108107
}
109108
}
110109

111-
public static final class Origin {
110+
public static final class ScrollOrigin {
112111
private final Object originObject;
113112

114113
public Object asArg() {
@@ -119,16 +118,16 @@ public Object asArg() {
119118
return arg;
120119
}
121120

122-
private Origin(Object originObject) {
121+
private ScrollOrigin(Object originObject) {
123122
this.originObject = originObject;
124123
}
125124

126-
public static WheelInput.Origin viewport() {
127-
return new WheelInput.Origin("viewport");
125+
public static ScrollOrigin fromViewport() {
126+
return new ScrollOrigin("viewport");
128127
}
129128

130-
public static WheelInput.Origin fromElement(WebElement element) {
131-
return new WheelInput.Origin(Require.nonNull("Element", element));
129+
public static ScrollOrigin fromElement(WebElement element) {
130+
return new ScrollOrigin(Require.nonNull("Element", element));
132131
}
133132
}
134133
}

java/test/org/openqa/selenium/interactions/DefaultWheelTest.java

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import org.openqa.selenium.WebElement;
2828
import org.openqa.selenium.testing.JUnit4TestBase;
2929

30-
import java.time.Duration;
31-
3230
/**
3331
* Tests operations that involve scroll wheel.
3432
*/
@@ -45,12 +43,8 @@ public void shouldScrollToElement() {
4543

4644
assertFalse(inViewport(iframe));
4745

48-
getBuilder(driver).scroll(
49-
0,
50-
0,
51-
0,
52-
0,
53-
WheelInput.Origin.fromElement(iframe)).perform();
46+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromElement(iframe);
47+
getBuilder(driver).scroll(0, 0, 0, 0, scrollOrigin).perform();
5448

5549
assertTrue(inViewport(iframe));
5650
}
@@ -59,16 +53,11 @@ public void shouldScrollToElement() {
5953
public void shouldScrollFromElementByGivenAmount() {
6054
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
6155
WebElement iframe = driver.findElement(By.tagName("iframe"));
56+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromElement(iframe);
6257

63-
getBuilder(driver).scroll(
64-
0,
65-
0,
66-
0,
67-
200,
68-
WheelInput.Origin.fromElement(iframe)).perform();
58+
getBuilder(driver).scroll(0, 0, 0, 200, scrollOrigin).perform();
6959

7060
driver.switchTo().frame(iframe);
71-
7261
WebElement checkbox = driver.findElement(By.name("scroll_checkbox"));
7362
assertTrue(inViewport(checkbox));
7463
}
@@ -77,16 +66,12 @@ public void shouldScrollFromElementByGivenAmount() {
7766
public void shouldScrollFromElementByGivenAmountWithOffset() {
7867
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
7968
WebElement footer = driver.findElement(By.tagName("footer"));
69+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromElement(footer);
8070

81-
getBuilder(driver).scroll(
82-
0,
83-
-50,
84-
0,
85-
200,
86-
WheelInput.Origin.fromElement(footer)).perform();
87-
88-
driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
71+
getBuilder(driver).scroll(0, -50, 0, 200, scrollOrigin).perform();
8972

73+
WebElement iframe = driver.findElement(By.tagName("iframe"));
74+
driver.switchTo().frame(iframe);
9075
WebElement checkbox = driver.findElement(By.name("scroll_checkbox"));
9176
assertTrue(inViewport(checkbox));
9277
}
@@ -95,61 +80,42 @@ public void shouldScrollFromElementByGivenAmountWithOffset() {
9580
public void throwErrorWhenElementOriginIsOutOfViewport() {
9681
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
9782
WebElement footer = driver.findElement(By.tagName("footer"));
83+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromElement(footer);
9884

99-
getBuilder(driver).scroll(
100-
0,
101-
50,
102-
0,
103-
200,
104-
WheelInput.Origin.fromElement(footer)).perform();
85+
getBuilder(driver).scroll(0, 50, 0, 200, scrollOrigin).perform();
10586
}
10687

10788
@Test
10889
public void shouldScrollFromViewportByGivenAmount() {
10990
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
11091
WebElement footer = driver.findElement(By.tagName("footer"));
92+
int deltaY = footer.getRect().y;
93+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromViewport();
11194

112-
int y = footer.getRect().y;
113-
114-
getBuilder(driver).scroll(
115-
0,
116-
0,
117-
0,
118-
y,
119-
WheelInput.Origin.viewport()).perform();
95+
getBuilder(driver).scroll(0, 0, 0, deltaY, scrollOrigin).perform();
12096

12197
assertTrue(inViewport(footer));
12298
}
12399

124100
@Test
125101
public void shouldScrollFromViewportByGivenAmountFromOrigin() {
126102
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame.html"));
103+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromViewport();
127104

128-
WebElement iframe = driver.findElement(By.tagName("iframe"));
129-
130-
getBuilder(driver).scroll(
131-
10,
132-
10,
133-
0,
134-
200,
135-
WheelInput.Origin.viewport()).perform();
105+
getBuilder(driver).scroll(10, 10, 0, 200, scrollOrigin).perform();
136106

107+
WebElement iframe = driver.findElement(By.tagName("iframe"));
137108
driver.switchTo().frame(iframe);
138-
139109
WebElement checkbox = driver.findElement(By.name("scroll_checkbox"));
140110
assertTrue(inViewport(checkbox));
141111
}
142112

143113
@Test(expected = MoveTargetOutOfBoundsException.class)
144114
public void throwErrorWhenOriginOffsetIsOutOfViewport() {
145115
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame.html"));
116+
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromViewport();
146117

147-
getBuilder(driver).scroll(
148-
-10,
149-
-10,
150-
0,
151-
200,
152-
WheelInput.Origin.viewport()).perform();
118+
getBuilder(driver).scroll(-10, -10, 0, 200, scrollOrigin).perform();
153119
}
154120

155121
private boolean inViewport(WebElement element) {

java/test/org/openqa/selenium/interactions/WheelInputTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.experimental.categories.Category;
2525
import org.openqa.selenium.WebElement;
2626
import org.openqa.selenium.WrappedWebElement;
27-
import org.openqa.selenium.interactions.PointerInput.Origin;
2827
import org.openqa.selenium.json.Json;
2928
import org.openqa.selenium.json.PropertySetting;
3029
import org.openqa.selenium.remote.RemoteWebElement;
@@ -50,7 +49,7 @@ public void shouldEncodeWrappedElementInScrollOrigin() {
5049
0,
5150
0,
5251
Duration.ofMillis(100),
53-
WheelInput.Origin.fromElement(element));
52+
WheelInput.ScrollOrigin.fromElement(element));
5453
Sequence sequence = new Sequence(wheelInput, 0).addAction(scroll);
5554

5655
String rawJson = new Json().toJson(sequence);
@@ -84,7 +83,7 @@ public void shouldEncodeScrollInteractionWithViewPortOrigin() {
8483
30,
8584
60,
8685
Duration.ofSeconds(1),
87-
WheelInput.Origin.viewport());
86+
WheelInput.ScrollOrigin.fromViewport());
8887

8988
Map<String, Object> encodedResult = interaction.encode();
9089
assertThat(encodedResult)
@@ -110,7 +109,7 @@ public void shouldEncodeScrollInteractionWithElementOrigin() {
110109
30,
111110
60,
112111
Duration.ofSeconds(1),
113-
WheelInput.Origin.fromElement(innerElement));
112+
WheelInput.ScrollOrigin.fromElement(innerElement));
114113

115114
Map<String, Object> encodedResult = interaction.encode();
116115
assertThat(encodedResult)

0 commit comments

Comments
 (0)