Skip to content

Commit 483ba5a

Browse files
The addition to the #756. Method renaming
Also issues whick were pointed out by @mykola-mokhnach were fixed out
1 parent c892098 commit 483ba5a

File tree

9 files changed

+83
-69
lines changed

9 files changed

+83
-69
lines changed

src/main/java/io/appium/java_client/TouchAction.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
21-
import static io.appium.java_client.touch.PositionOffsetOption.positionOffsetOption;
22-
import static io.appium.java_client.touch.WebElementOption.elementOption;
21+
import static io.appium.java_client.touch.PositionOffsetOption.offset;
22+
import static io.appium.java_client.touch.WebElementOption.element;
2323

2424
import com.google.common.collect.ImmutableList;
2525
import com.google.common.collect.ImmutableMap;
@@ -75,7 +75,7 @@ public <S extends PositionOffsetOption> T press(S pressOptions) {
7575
*/
7676
@Deprecated
7777
public T press(WebElement el) {
78-
return press(elementOption(el));
78+
return press(element(el));
7979
}
8080

8181
/**
@@ -88,7 +88,7 @@ public T press(WebElement el) {
8888
*/
8989
@Deprecated
9090
public T press(int x, int y) {
91-
return (T) press(positionOffsetOption(x, y));
91+
return (T) press(offset(x, y));
9292
}
9393

9494
/**
@@ -102,7 +102,7 @@ public T press(int x, int y) {
102102
*/
103103
@Deprecated
104104
public T press(WebElement el, int x, int y) {
105-
return press(elementOption(el, x, y));
105+
return press(WebElementOption.element(el, x, y));
106106
}
107107

108108
/**
@@ -139,7 +139,7 @@ public <S extends PositionOffsetOption> T moveTo(S moveToOptions) {
139139
*/
140140
@Deprecated
141141
public T moveTo(WebElement el) {
142-
return moveTo(elementOption(el));
142+
return moveTo(element(el));
143143
}
144144

145145
/**
@@ -154,7 +154,7 @@ public T moveTo(WebElement el) {
154154
*/
155155
@Deprecated
156156
public T moveTo(int x, int y) {
157-
return (T) moveTo(positionOffsetOption(x, y));
157+
return (T) moveTo(offset(x, y));
158158
}
159159

160160
/**
@@ -168,7 +168,7 @@ public T moveTo(int x, int y) {
168168
*/
169169
@Deprecated
170170
public T moveTo(WebElement el, int x, int y) {
171-
return moveTo(elementOption(el, x, y));
171+
return moveTo(WebElementOption.element(el, x, y));
172172
}
173173

174174
/**
@@ -204,7 +204,7 @@ public <S extends PositionOffsetOption> T tap(S tapOptions) {
204204
*/
205205
@Deprecated
206206
public T tap(WebElement el) {
207-
return tap(elementOption(el));
207+
return tap(element(el));
208208
}
209209

210210
/**
@@ -217,7 +217,7 @@ public T tap(WebElement el) {
217217
*/
218218
@Deprecated
219219
public T tap(int x, int y) {
220-
return (T) tap(positionOffsetOption(x, y));
220+
return (T) tap(offset(x, y));
221221
}
222222

223223
/**
@@ -231,7 +231,7 @@ public T tap(int x, int y) {
231231
*/
232232
@Deprecated
233233
public T tap(WebElement el, int x, int y) {
234-
return tap(elementOption(el, x, y));
234+
return tap(WebElementOption.element(el, x, y));
235235
}
236236

237237
/**
@@ -311,7 +311,7 @@ public <S extends PositionOffsetOption> T longPress(S longPressOptions) {
311311
*/
312312
@Deprecated
313313
public T longPress(WebElement el) {
314-
return longPress(elementOption(el));
314+
return longPress(element(el));
315315
}
316316

317317
/**
@@ -325,7 +325,7 @@ public T longPress(WebElement el) {
325325
@Deprecated
326326
public T longPress(WebElement el, Duration duration) {
327327
return longPress(longPressOptions()
328-
.withDuration(duration).withOffset(elementOption(el)));
328+
.withDuration(duration).withOffset(element(el)));
329329
}
330330

331331
/**
@@ -339,7 +339,7 @@ public T longPress(WebElement el, Duration duration) {
339339
*/
340340
@Deprecated
341341
public T longPress(int x, int y) {
342-
return (T) longPress(positionOffsetOption(x, y));
342+
return (T) longPress(offset(x, y));
343343
}
344344

345345
/**
@@ -355,7 +355,7 @@ public T longPress(int x, int y) {
355355
@Deprecated
356356
public T longPress(int x, int y, Duration duration) {
357357
return (T) longPress(longPressOptions()
358-
.withDuration(duration).withOffset(positionOffsetOption(x, y)));
358+
.withDuration(duration).withOffset(offset(x, y)));
359359
}
360360

361361
/**
@@ -370,7 +370,7 @@ public T longPress(int x, int y, Duration duration) {
370370
*/
371371
@Deprecated
372372
public T longPress(WebElement el, int x, int y) {
373-
return longPress(elementOption(el, x, y));
373+
return longPress(WebElementOption.element(el, x, y));
374374
}
375375

376376
/**
@@ -387,7 +387,7 @@ public T longPress(WebElement el, int x, int y) {
387387
@Deprecated
388388
public TouchAction longPress(WebElement el, int x, int y, Duration duration) {
389389
return longPress(longPressOptions()
390-
.withOffset(elementOption(el, x, y)).withDuration(duration));
390+
.withOffset(WebElementOption.element(el, x, y)).withDuration(duration));
391391
}
392392

393393
/**

src/main/java/io/appium/java_client/ios/IOSTouchAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.appium.java_client.ios;
1818

19-
import static io.appium.java_client.touch.WebElementOption.elementOption;
19+
import static io.appium.java_client.touch.WebElementOption.element;
2020

2121
import io.appium.java_client.PerformsTouchActions;
2222
import io.appium.java_client.TouchAction;
@@ -42,7 +42,7 @@ public IOSTouchAction(PerformsTouchActions performsTouchActions) {
4242
*/
4343
@Deprecated
4444
public IOSTouchAction doubleTap(WebElement el, int x, int y) {
45-
return doubleTap(elementOption(el, x, y));
45+
return doubleTap(element(el, x, y));
4646
}
4747

4848
/**
@@ -54,7 +54,7 @@ public IOSTouchAction doubleTap(WebElement el, int x, int y) {
5454
*/
5555
@Deprecated
5656
public IOSTouchAction doubleTap(WebElement el) {
57-
return doubleTap(elementOption(el));
57+
return doubleTap(element(el));
5858
}
5959

6060
/**

src/main/java/io/appium/java_client/touch/PositionOffsetOption.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.Map;
88

99
public class PositionOffsetOption<T extends PositionOffsetOption<T>> extends ActionOptions<T> {
10-
private Point offset = new Point(0, 0);
10+
protected Point offset;
1111

1212
/**
1313
* It creates a built instance of {@link PositionOffsetOption} which takes x and y position
@@ -18,8 +18,8 @@ public class PositionOffsetOption<T extends PositionOffsetOption<T>> extends Act
1818
* @param yOffset is y-axis offset.
1919
* @return a built option
2020
*/
21-
public static PositionOffsetOption positionOffsetOption(int xOffset, int yOffset) {
22-
return new PositionOffsetOption().withOffet(xOffset, yOffset);
21+
public static PositionOffsetOption offset(int xOffset, int yOffset) {
22+
return new PositionOffsetOption().setOffset(xOffset, yOffset);
2323
}
2424

2525
/**
@@ -30,7 +30,7 @@ public static PositionOffsetOption positionOffsetOption(int xOffset, int yOffset
3030
* @param yOffset is y-axis offset.
3131
* @return this instance for chaining.
3232
*/
33-
public T withOffet(int xOffset, int yOffset) {
33+
public T setOffset(int xOffset, int yOffset) {
3434
this.offset = new Point(xOffset, yOffset);
3535
return (T) this;
3636
}

src/main/java/io/appium/java_client/touch/WebElementOption.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import org.openqa.selenium.WebElement;
88
import org.openqa.selenium.internal.HasIdentity;
99

10+
import java.util.HashMap;
1011
import java.util.Map;
1112

1213
public class WebElementOption extends PositionOffsetOption<WebElementOption> {
1314

14-
private HasIdentity elementId;
15+
private String elementId;
1516

1617
/**
1718
* This method creates a build instance of the {@link WebElementOption}
@@ -21,8 +22,8 @@ public class WebElementOption extends PositionOffsetOption<WebElementOption> {
2122
* @param y is the y-offset from the upper left corner of the given element.
2223
* @return the built option
2324
*/
24-
public static WebElementOption elementOption(WebElement element, int x, int y) {
25-
return new WebElementOption().withElement(element).withOffet(x, y);
25+
public static WebElementOption element(WebElement element, int x, int y) {
26+
return new WebElementOption().withElement(element).setOffset(x, y);
2627
}
2728

2829
/**
@@ -31,8 +32,8 @@ public static WebElementOption elementOption(WebElement element, int x, int y) {
3132
* @param element is the element to calculate offset from.
3233
* @return the built option
3334
*/
34-
public static WebElementOption elementOption(WebElement element) {
35-
return elementOption(element, 0, 0);
35+
public static WebElementOption element(WebElement element) {
36+
return new WebElementOption().withElement(element);
3637
}
3738

3839
/**
@@ -47,7 +48,7 @@ public WebElementOption withElement(WebElement element) {
4748
checkArgument(true, "Element should be an instance of the class which "
4849
+ "implements org.openqa.selenium.internal.HasIdentity",
4950
(HasIdentity.class.isAssignableFrom(element.getClass())));
50-
elementId = HasIdentity.class.cast(element);
51+
elementId = HasIdentity.class.cast(element).getId();
5152
return this;
5253
}
5354

@@ -59,8 +60,14 @@ protected void verify() {
5960

6061
@Override
6162
public Map<String, Object> build() {
62-
final Map<String, Object> result = super.build();
63-
result.put("element", elementId.getId());
63+
verify();
64+
final Map<String, Object> result = new HashMap<>();
65+
result.put("element", elementId);
66+
67+
ofNullable(offset).ifPresent(point -> {
68+
result.put("x", point.x);
69+
result.put("y", point.y);
70+
});
6471
return result;
6572
}
6673
}

src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.appium.java_client.android;
22

33
import static io.appium.java_client.touch.WaitOptions.waitOptions;
4-
import static io.appium.java_client.touch.WebElementOption.elementOption;
4+
import static io.appium.java_client.touch.WebElementOption.element;
55
import static java.time.Duration.ofSeconds;
66
import static org.junit.Assert.assertNotEquals;
77

@@ -24,17 +24,17 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
2424
Point center = gallery.getCenter();
2525

2626
return new AndroidTouchAction(driver)
27-
.press(elementOption(images.get(2),-10,center.y - location.y))
27+
.press(element(images.get(2),-10,center.y - location.y))
2828
.waitAction(waitOptions(ofSeconds(2)))
29-
.moveTo(elementOption(gallery, 10,center.y - location.y))
29+
.moveTo(element(gallery, 10,center.y - location.y))
3030
.release();
3131
};
3232

3333
private final ActionSupplier<AndroidTouchAction> verticalSwiping = () ->
3434
new AndroidTouchAction(driver)
35-
.press(elementOption(driver.findElementByAccessibilityId("Gallery")))
35+
.press(element(driver.findElementByAccessibilityId("Gallery")))
3636
.waitAction(waitOptions(ofSeconds(2)))
37-
.moveTo(elementOption(driver.findElementByAccessibilityId("Auto Complete")))
37+
.moveTo(element(driver.findElementByAccessibilityId("Auto Complete")))
3838
.release();
3939

4040
@Test public void horizontalSwipingWithSupplier() throws Exception {

0 commit comments

Comments
 (0)