Skip to content

Commit 811a8fe

Browse files
authored
[java] Overload methods creating interactions to accept Point (#11477)
[java] Overload methods creating interaction to accept `Point`
1 parent b0ffee0 commit 811a8fe

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

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

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

1818
package org.openqa.selenium.interactions;
1919

20+
import org.openqa.selenium.Point;
2021
import org.openqa.selenium.WebElement;
2122
import org.openqa.selenium.WrapsElement;
2223
import org.openqa.selenium.internal.Require;
@@ -71,10 +72,18 @@ public Interaction createPointerMove(Duration duration, Origin origin, int x, in
7172
return new Move(this, duration, origin, x, y);
7273
}
7374

75+
public Interaction createPointerMove(Duration duration, Origin origin, Point offset) {
76+
return createPointerMove(duration, origin, offset.x, offset.y);
77+
}
78+
7479
public Interaction createPointerMove(Duration duration, Origin origin, int x, int y, PointerEventProperties eventProperties) {
7580
return new Move(this, duration, origin, x, y, eventProperties);
7681
}
7782

83+
public Interaction createPointerMove(Duration duration, Origin origin, Point offset, PointerEventProperties eventProperties) {
84+
return createPointerMove(duration, origin, offset.x, offset.y, eventProperties);
85+
}
86+
7887
public Interaction createPointerDown(int button) {
7988
return new PointerPress(this, PointerPress.Direction.DOWN, button);
8089
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Optional;
2626
import java.util.UUID;
2727

28+
import org.openqa.selenium.Point;
2829
import org.openqa.selenium.WebElement;
2930
import org.openqa.selenium.WrapsElement;
3031
import org.openqa.selenium.internal.Require;
@@ -54,6 +55,10 @@ public Interaction createScroll(int x, int y, int deltaX, int deltaY, Duration d
5455
return new ScrollInteraction(this, x, y, deltaX, deltaY, duration, origin);
5556
}
5657

58+
public Interaction createScroll(Point start, int deltaX, int deltaY, Duration duration, ScrollOrigin origin) {
59+
return createScroll(start.x, start.y, deltaX, deltaY, duration, origin);
60+
}
61+
5762
@Override
5863
public Map<String, Object> encode() {
5964
Map<String, Object> toReturn = new HashMap<>();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public void testMoveRelativeToBody() {
312312
wait.until(fuzzyMatchingOfCoordinates(reporter, 40, 20));
313313
} finally {
314314
Sequence actionList = new Sequence(defaultPen, 0)
315-
.addAction(defaultPen.createPointerMove(Duration.ZERO, PointerInput.Origin.pointer(), -50, -100));
315+
.addAction(defaultPen.createPointerMove(Duration.ZERO, PointerInput.Origin.pointer(), new Point(-50, -100)));
316316
((RemoteWebDriver) driver).perform(Collections.singletonList(actionList));
317317
}
318318
}
@@ -394,7 +394,7 @@ public void setPointerEventProperties() {
394394
Sequence actionListPen = new Sequence(pen, 0)
395395
.addAction(pen.createPointerMove(Duration.ZERO, origin, 0, 0))
396396
.addAction(pen.createPointerDown(0))
397-
.addAction(pen.createPointerMove(Duration.ofMillis(800), origin, 2, 2, eventProperties))
397+
.addAction(pen.createPointerMove(Duration.ofMillis(800), origin, new Point(2, 2), eventProperties))
398398
.addAction(pen.createPointerUp(0));
399399

400400
((RemoteWebDriver) driver).perform(List.of(actionListPen));

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.Tag;
25+
import org.openqa.selenium.Point;
2526
import org.openqa.selenium.WebElement;
2627
import org.openqa.selenium.WrappedWebElement;
2728
import org.openqa.selenium.json.Json;
@@ -43,8 +44,7 @@ void shouldEncodeWrappedElementInScrollOrigin() {
4344

4445
WheelInput wheelInput = new WheelInput("wheel");
4546
Interaction scroll = wheelInput.createScroll(
46-
20,
47-
30,
47+
new Point(20, 30),
4848
0,
4949
0,
5050
Duration.ofMillis(100),
@@ -75,8 +75,7 @@ void shouldEncodeWheelInput() {
7575
@Test
7676
void shouldEncodeScrollInteractionWithViewPortOrigin() {
7777
WheelInput wheelInput = new WheelInput("test-wheel");
78-
WheelInput.ScrollInteraction interaction = new WheelInput.ScrollInteraction(
79-
wheelInput,
78+
WheelInput.ScrollInteraction interaction = (WheelInput.ScrollInteraction) wheelInput.createScroll(
8079
25,
8180
50,
8281
30,
@@ -101,10 +100,8 @@ void shouldEncodeScrollInteractionWithElementOrigin() {
101100
innerElement.setId("12345");
102101

103102
WheelInput wheelInput = new WheelInput("test-wheel");
104-
WheelInput.ScrollInteraction interaction = new WheelInput.ScrollInteraction(
105-
wheelInput,
106-
25,
107-
50,
103+
WheelInput.ScrollInteraction interaction = (WheelInput.ScrollInteraction) wheelInput.createScroll(
104+
new Point(25, 50),
108105
30,
109106
60,
110107
Duration.ofSeconds(1),

0 commit comments

Comments
 (0)