Skip to content

Commit f525ae3

Browse files
The addition to the appium#756:
- the draft of architectural improvements
1 parent c817ac4 commit f525ae3

15 files changed

Lines changed: 293 additions & 345 deletions

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

Lines changed: 122 additions & 123 deletions
Large diffs are not rendered by default.

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

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

1919
import io.appium.java_client.PerformsTouchActions;
2020
import io.appium.java_client.TouchAction;
21-
import io.appium.java_client.ios.touch.DoubleTapOptions;
21+
import io.appium.java_client.touch.RelativeOffsetOption;
2222
import org.openqa.selenium.WebElement;
2323

24+
import static io.appium.java_client.touch.RelativeOffsetOption.useRelative;
25+
2426

2527
public class IOSTouchAction extends TouchAction<IOSTouchAction> {
2628

@@ -35,30 +37,28 @@ public IOSTouchAction(PerformsTouchActions performsTouchActions) {
3537
* @param x x offset.
3638
* @param y y offset.
3739
* @return this IOSTouchAction, for chaining.
38-
* @deprecated use {@link #tap(ActionOptions)} with count=2 instead.
40+
* @deprecated use {@link #tap(RelativeOffsetOption)} with count=2 instead.
3941
*/
4042
@Deprecated
4143
public IOSTouchAction doubleTap(WebElement el, int x, int y) {
42-
ActionParameter action = new ActionParameter("doubleTap",
43-
new DoubleTapOptions()
44-
.withElement(el)
45-
.withRelativeOffset(x, y));
46-
parameterBuilder.add(action);
47-
return this;
44+
return doubleTap(useRelative(el, x, y));
4845
}
4946

5047
/**
5148
* Double taps an element, offset from upper left corner.
5249
*
5350
* @param el element to tap.
5451
* @return this IOSTouchAction, for chaining.
55-
* @deprecated use {@link #tap(ActionOptions)} with count=2 instead.
52+
* @deprecated use {@link #tap(RelativeOffsetOption)} with count=2 instead.
5653
*/
5754
@Deprecated
5855
public IOSTouchAction doubleTap(WebElement el) {
56+
return doubleTap(useRelative(el));
57+
}
58+
59+
public IOSTouchAction doubleTap(RelativeOffsetOption doubleTapOption) {
5960
ActionParameter action = new ActionParameter("doubleTap",
60-
new DoubleTapOptions()
61-
.withElement(el));
61+
doubleTapOption);
6262
parameterBuilder.add(action);
6363
return this;
6464
}

src/main/java/io/appium/java_client/ios/touch/DoubleTapOptions.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public AppiumFieldDecorator(SearchContext context, long timeout,
8484
* or {@link org.openqa.selenium.WebElement} or
8585
* {@link io.appium.java_client.pagefactory.Widget} or some other user's
8686
* extension/implementation.
87-
* @param duration is a desired duration of the waiting for an element presence.
87+
* @param duration is a desired waitOptoins of the waiting for an element presence.
8888
*/
8989
public AppiumFieldDecorator(SearchContext context, TimeOutDuration duration) {
9090
this.originalDriver = unpackWebDriverFromSearchContext(context);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.touch;
18+
19+
import org.openqa.selenium.Point;
20+
21+
import java.util.Map;
22+
23+
import static java.util.Optional.ofNullable;
24+
25+
public class AbsoluteOffsetOption extends ActionOptions<AbsoluteOffsetOption> {
26+
private Point absoluteOffset = null;
27+
28+
public static AbsoluteOffsetOption useAbsolute(int xOffset, int yOffset) {
29+
return new AbsoluteOffsetOption().withAbsoluteOffset(xOffset, yOffset);
30+
}
31+
32+
/**
33+
* Set the absolute offset for the corresponding action.
34+
*
35+
* @param xOffset the absolute distance from the left screen corner.
36+
* @param yOffset the absolute distance from the top screen corner.
37+
* @return this instance for chaining.
38+
*/
39+
public AbsoluteOffsetOption withAbsoluteOffset(int xOffset, int yOffset) {
40+
this.absoluteOffset = new Point(xOffset, yOffset);
41+
//noinspection unchecked
42+
return this;
43+
}
44+
45+
@Override
46+
protected void verify() {
47+
ofNullable(absoluteOffset).orElseThrow(() -> new IllegalArgumentException(
48+
"Absolute offset must not be defined"));
49+
}
50+
51+
@Override
52+
public Map<String, Object> build() {
53+
final Map<String, Object> result = super.build();
54+
ofNullable(absoluteOffset).ifPresent(point -> {
55+
result.put("x", point.x);
56+
result.put("y", point.y);
57+
});
58+
return result;
59+
}
60+
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
import java.time.Duration;
2323
import java.util.Map;
2424

25-
public class LongPressOptions extends OptionsWithAbsolutePositioning<LongPressOptions> {
25+
public class LongPressOptions extends OptionsCombinedWithOffset<LongPressOptions> {
2626
protected Duration duration = null;
2727

28+
public static LongPressOptions longPressOptions() {
29+
return new LongPressOptions();
30+
}
31+
2832
/**
29-
* Set the long press duration.
33+
* Set the long press waitOptoins.
3034
*
31-
* @param duration the duration value to set.
35+
* @param duration the waitOptoins value to set.
3236
* Time resolution unit is 1 ms.
3337
* @return this instance for chaining.
3438
*/
@@ -44,7 +48,7 @@ public LongPressOptions withDuration(Duration duration) {
4448
public Map<String, Object> build() {
4549
final Map<String, Object> result = super.build();
4650
if (duration != null) {
47-
result.put("duration", this.duration.toMillis());
51+
result.put("waitOptoins", this.duration.toMillis());
4852
}
4953
return result;
5054
}

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

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.appium.java_client.touch;
2+
3+
import java.util.Map;
4+
5+
import static java.util.Optional.ofNullable;
6+
7+
public abstract class OptionsCombinedWithOffset <T extends OptionsCombinedWithOffset>
8+
extends ActionOptions< OptionsCombinedWithOffset<T>> {
9+
private ActionOptions<?> offsetOption;
10+
11+
/**
12+
* Some actions may require some absolute offset value to be performed.
13+
* Invocation of this method replaces the result of previous invocation of
14+
* the {@link #withOffset(RelativeOffsetOption)}
15+
*
16+
* @param offset is the values of required absolute offset from the left corner of a screen. *
17+
* @return self-reference
18+
*/
19+
public T withOffset(AbsoluteOffsetOption offset) {
20+
offsetOption = offset;
21+
return (T) this;
22+
}
23+
24+
/**
25+
* Some actions may require some relative offset value to be performed.
26+
* Invocation of this method replaces the result of previous invocation of
27+
* the {@link #withOffset(AbsoluteOffsetOption)}
28+
*
29+
* @param offset is the values of required offset from the left corner of an element. *
30+
* @return self-reference
31+
*/
32+
public T withOffset(RelativeOffsetOption offset) {
33+
offsetOption = offset;
34+
return (T) this;
35+
}
36+
37+
protected void verify() {
38+
ofNullable(offsetOption).orElseThrow(() ->
39+
new IllegalArgumentException("Some relative or absolute offset should be defined. Use one of withOffset methods"));
40+
}
41+
42+
@Override
43+
public Map<String, Object> build() {
44+
final Map<String, Object> result = super.build();
45+
result.putAll(offsetOption.build());
46+
return result;
47+
}
48+
}

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

Lines changed: 0 additions & 107 deletions
This file was deleted.

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)