Skip to content

Mykola mokhnach's actions params: The addition to the #756 #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 36 additions & 39 deletions src/main/java/io/appium/java_client/TouchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import static com.google.common.collect.ImmutableList.builder;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static io.appium.java_client.touch.offset.OffsetOption.offset;
import static io.appium.java_client.touch.offset.PointOption.coordinates;
import static io.appium.java_client.touch.offset.Position.position;
import static io.appium.java_client.touch.offset.PointOption.point;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -31,9 +29,8 @@
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.TapOptions;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.AbstractPositionOption;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import io.appium.java_client.touch.offset.Position;
import org.openqa.selenium.WebElement;

import java.time.Duration;
Expand Down Expand Up @@ -61,10 +58,10 @@ public TouchAction(PerformsTouchActions performsTouchActions) {
/**
* Press action on the screen.
*
* @param pressOptions see {@link Position}.
* @param pressOptions see {@link PointOption} and {@link ElementOption}.
* @return this TouchAction, for chaining.
*/
public T press(Position<PointOption> pressOptions) {
public T press(PointOption pressOptions) {
parameterBuilder.add(new ActionParameter("press", pressOptions));
//noinspection unchecked
return (T) this;
Expand All @@ -75,11 +72,11 @@ public T press(Position<PointOption> pressOptions) {
*
* @param el element to press on.
* @return this TouchAction, for chaining.
* @deprecated use {@link #press(Position)} instead
* @deprecated use {@link #press(PointOption)} instead
*/
@Deprecated
public T press(WebElement el) {
return press(Position.<PointOption>position().withElement(element(el)));
return press(element(el));
}

/**
Expand All @@ -88,11 +85,11 @@ public T press(WebElement el) {
* @param x x coordinate.
* @param y y coordinate.
* @return this TouchAction, for chaining.
* @deprecated use {@link #press(Position)} instead
* @deprecated use {@link #press(PointOption)} instead
*/
@Deprecated
public T press(int x, int y) {
return press(Position.<PointOption>position().withPosition(coordinates(x, y)));
return press(point(x, y));
}

/**
Expand All @@ -102,11 +99,11 @@ public T press(int x, int y) {
* @param x x offset.
* @param y y offset.
* @return this TouchAction, for chaining.
* @deprecated use {@link #press(Position)} instead
* @deprecated use {@link #press(PointOption)} instead
*/
@Deprecated
public T press(WebElement el, int x, int y) {
return press(Position.<PointOption>position().withElement(element(el, x, y)));
return press(element(el, x, y));
}

/**
Expand All @@ -124,10 +121,10 @@ public T release() {
/**
* Moves current touch to a new position.
*
* @param moveToOptions see {@link Position}
* @param moveToOptions see {@link PointOption} and {@link ElementOption}
* @return this TouchAction, for chaining.
*/
public <S extends AbstractPositionOption> T moveTo(Position<S> moveToOptions) {
public T moveTo(PointOption moveToOptions) {
ActionParameter action = new ActionParameter("moveTo", moveToOptions);
parameterBuilder.add(action);
return (T) this;
Expand All @@ -138,11 +135,11 @@ public <S extends AbstractPositionOption> T moveTo(Position<S> moveToOptions) {
*
* @param el element to move to.
* @return this TouchAction, for chaining.
* @deprecated {@link #moveTo(Position)} instead
* @deprecated {@link #moveTo(PointOption)} instead
*/
@Deprecated
public T moveTo(WebElement el) {
return moveTo(position().withElement(element(el)));
return moveTo(element(el));
}

/**
Expand All @@ -153,11 +150,11 @@ public T moveTo(WebElement el) {
* @param x change in x coordinate to move through.
* @param y change in y coordinate to move through.
* @return this TouchAction, for chaining.
* @deprecated {@link #moveTo(Position)} instead
* @deprecated {@link #moveTo(PointOption)} instead
*/
@Deprecated
public T moveTo(int x, int y) {
return moveTo(position().withPosition(offset(x, y)));
return moveTo(point(x, y));
}

/**
Expand All @@ -167,11 +164,11 @@ public T moveTo(int x, int y) {
* @param x x offset.
* @param y y offset.
* @return this TouchAction, for chaining.
* @deprecated {@link #moveTo(Position)} instead
* @deprecated {@link #moveTo(PointOption)} instead
*/
@Deprecated
public T moveTo(WebElement el, int x, int y) {
return moveTo(position().withElement(element(el, x, y)));
return moveTo(element(el, x, y));
}

/**
Expand All @@ -189,10 +186,10 @@ public T tap(TapOptions tapOptions) {
/**
* Tap on a position.
*
* @param tapOptions see {@link Position}
* @param tapOptions see {@link PointOption} and {@link ElementOption}
* @return this TouchAction, for chaining.
*/
public T tap(Position<PointOption> tapOptions) {
public T tap(PointOption tapOptions) {
ActionParameter action = new ActionParameter("tap", tapOptions);
parameterBuilder.add(action);
return (T) this;
Expand All @@ -203,11 +200,11 @@ public T tap(Position<PointOption> tapOptions) {
*
* @param el element to tap.
* @return this TouchAction, for chaining.
* @deprecated use {@link #tap(Position)} instead.
* @deprecated use {@link #tap(PointOption)} instead.
*/
@Deprecated
public T tap(WebElement el) {
return tap(Position.<PointOption>position().withElement(element(el)));
return tap(element(el));
}

/**
Expand All @@ -216,11 +213,11 @@ public T tap(WebElement el) {
* @param x x coordinate.
* @param y y coordinate.
* @return this TouchAction, for chaining.
* @deprecated use {@link #tap(Position)} instead.
* @deprecated use {@link #tap(PointOption)} instead.
*/
@Deprecated
public T tap(int x, int y) {
return (T) tap(Position.<PointOption>position().withPosition(coordinates(x, y)));
return tap(point(x, y));
}

/**
Expand All @@ -230,11 +227,11 @@ public T tap(int x, int y) {
* @param x x offset.
* @param y y offset.
* @return this TouchAction, for chaining.
* @deprecated use {@link #tap(Position)} instead.
* @deprecated use {@link #tap(PointOption)} instead.
*/
@Deprecated
public T tap(WebElement el, int x, int y) {
return tap(Position.<PointOption>position().withElement(element(el, x, y)));
return tap(element(el, x, y));
}

/**
Expand Down Expand Up @@ -295,10 +292,10 @@ public T longPress(LongPressOptions longPressOptions) {
/**
* Press and hold the at the center of an element until the context menu event has fired.
*
* @param longPressOptions see {@link Position}.
* @param longPressOptions see {@link PointOption} and {@link ElementOption}.
* @return this TouchAction, for chaining.
*/
public T longPress(Position<PointOption> longPressOptions) {
public T longPress(PointOption longPressOptions) {
ActionParameter action = new ActionParameter("longPress", longPressOptions);
parameterBuilder.add(action);
//noinspection unchecked
Expand All @@ -310,11 +307,11 @@ public T longPress(Position<PointOption> longPressOptions) {
*
* @param el element to long-press.
* @return this TouchAction, for chaining.
* @deprecated use {@link #longPress(Position)} instead
* @deprecated use {@link #longPress(PointOption)} instead
*/
@Deprecated
public T longPress(WebElement el) {
return longPress(Position.<PointOption>position().withElement(element(el)));
return longPress(element(el));
}

/**
Expand All @@ -338,11 +335,11 @@ public T longPress(WebElement el, Duration duration) {
* @param x x coordinate.
* @param y y coordinate.
* @return this TouchAction, for chaining.
* @deprecated use {@link #longPress(Position)} instead
* @deprecated use {@link #longPress(PointOption)} instead
*/
@Deprecated
public T longPress(int x, int y) {
return longPress(Position.<PointOption>position().withPosition(coordinates(x, y)));
return longPress(point(x, y));
}

/**
Expand All @@ -357,8 +354,8 @@ public T longPress(int x, int y) {
*/
@Deprecated
public T longPress(int x, int y, Duration duration) {
return (T) longPress(longPressOptions()
.withDuration(duration).withPosition(coordinates(x, y)));
return longPress(longPressOptions()
.withDuration(duration).withPosition(point(x, y)));
}

/**
Expand All @@ -369,11 +366,11 @@ public T longPress(int x, int y, Duration duration) {
* @param x x offset.
* @param y y offset.
* @return this TouchAction, for chaining.
* @deprecated use {@link #longPress(Position)} instead
* @deprecated use {@link #longPress(PointOption)} instead
*/
@Deprecated
public T longPress(WebElement el, int x, int y) {
return longPress(Position.<PointOption>position().withElement(element(el, x, y)));
return longPress(element(el, x, y));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/appium/java_client/ios/IOSTouchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import io.appium.java_client.touch.offset.Position;
import org.openqa.selenium.WebElement;

public class IOSTouchAction extends TouchAction<IOSTouchAction> {
Expand All @@ -37,32 +37,32 @@ public IOSTouchAction(PerformsTouchActions performsTouchActions) {
* @param x x offset.
* @param y y offset.
* @return this IOSTouchAction, for chaining.
* @deprecated use {@link #tap(Position)} with count=2 instead.
* @deprecated use {@link #doubleTap(PointOption)} with count=2 instead.
*/
@Deprecated
public IOSTouchAction doubleTap(WebElement el, int x, int y) {
return doubleTap(Position.<PointOption>position().withElement(element(el, x, y)));
return doubleTap(element(el, x, y));
}

/**
* Double taps an element, offset from upper left corner.
*
* @param el element to tap.
* @return this IOSTouchAction, for chaining.
* @deprecated use {@link #tap(Position)} with count=2 instead.
* @deprecated use {@link #doubleTap(PointOption)} with count=2 instead.
*/
@Deprecated
public IOSTouchAction doubleTap(WebElement el) {
return doubleTap(Position.<PointOption>position().withElement(element(el)));
return doubleTap(element(el));
}

/**
* Double taps using coordinates.
*
* @param doubleTapOption see {@link Position}.
* @param doubleTapOption see {@link PointOption} and {@link ElementOption}..
* @return self-reference
*/
public IOSTouchAction doubleTap(Position<PointOption> doubleTapOption) {
public IOSTouchAction doubleTap(PointOption doubleTapOption) {
ActionParameter action = new ActionParameter("doubleTap",
doubleTapOption);
parameterBuilder.add(action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import static java.util.Optional.ofNullable;

import io.appium.java_client.touch.offset.AbstractOptionCombinedWithPosition;
import io.appium.java_client.touch.offset.PointOption;

import java.time.Duration;
import java.util.Map;

public class LongPressOptions
extends AbstractOptionCombinedWithPosition<LongPressOptions, PointOption> {
public class LongPressOptions extends AbstractOptionCombinedWithPosition<LongPressOptions> {
protected Duration duration = null;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/appium/java_client/touch/TapOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import static java.util.Optional.ofNullable;

import io.appium.java_client.touch.offset.AbstractOptionCombinedWithPosition;
import io.appium.java_client.touch.offset.PointOption;

import java.util.Map;

public class TapOptions extends AbstractOptionCombinedWithPosition<TapOptions, PointOption> {
public class TapOptions extends AbstractOptionCombinedWithPosition<TapOptions> {
private Integer tapsCount = null;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,45 @@

import java.util.Map;

public abstract class AbstractOptionCombinedWithPosition<T extends AbstractOptionCombinedWithPosition<T, S>,
S extends AbstractPositionOption>
extends ActionOptions<AbstractOptionCombinedWithPosition<T, S>> {
private ActionOptions<?> offsetOption;
public abstract class AbstractOptionCombinedWithPosition<T extends AbstractOptionCombinedWithPosition<T>>
extends ActionOptions<AbstractOptionCombinedWithPosition<T>> {
private ActionOptions<?> positionOption;

/**
* Some actions may require offset. It may be option which contains x,y - offset
* from the left corner of the screen or from the current point on the screen
* or x,y - offset from the left corner of the element. Invocation of this method
* Some actions may require coordinates. Invocation of this method
* replaces the result of previous {@link #withElement(ElementOption)} invocation.
*
* @param offset required offset option. *
* @param positionOption required coordinates. *
* @return self-reference
*/
public T withPosition(S offset) {
offsetOption = offset;
public T withPosition(PointOption positionOption) {
this.positionOption = positionOption;
return (T) this;
}

/**
* Most of touch action may use position which is relative to some element. In order to unify
* this behaviour this method was added. Invocation of this method
* replaces the result of previous {@link #withPosition(AbstractPositionOption)} invocation.
* replaces the result of previous {@link #withPosition(PointOption)} invocation.
*
* @param element required position which is relative to some element
* @return self-reference
*/
public T withElement(ElementOption element) {
offsetOption = element;
positionOption = element;
return (T) this;
}

protected void verify() {
ofNullable(offsetOption).orElseThrow(() ->
new IllegalArgumentException("Some relative or absolute position should "
ofNullable(positionOption).orElseThrow(() ->
new IllegalArgumentException("Some coordinates or an offset from an element should "
+ "be defined. Use withPosition or withElement methods"));
}

@Override
public Map<String, Object> build() {
final Map<String, Object> result = super.build();
result.putAll(offsetOption.build());
result.putAll(positionOption.build());
return result;
}
}
Loading