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
89 changes: 46 additions & 43 deletions src/main/java/io/appium/java_client/TouchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@
package io.appium.java_client;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.builder;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
import static io.appium.java_client.touch.PositionOffsetOption.offset;
import static io.appium.java_client.touch.WebElementOption.element;
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 com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import io.appium.java_client.touch.ActionOptions;
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.PositionOffsetOption;
import io.appium.java_client.touch.TapOptions;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.WebElementOption;
import io.appium.java_client.touch.offset.AbstractPositionOption;
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 All @@ -51,16 +55,16 @@ public class TouchAction<T extends TouchAction<T>> implements PerformsActions<T>

public TouchAction(PerformsTouchActions performsTouchActions) {
this.performsTouchActions = performsTouchActions;
parameterBuilder = ImmutableList.builder();
parameterBuilder = builder();
}

/**
* Press action on the screen.
*
* @param pressOptions see {@link WebElementOption} and {@link PositionOffsetOption}.
* @param pressOptions see {@link Position}.
* @return this TouchAction, for chaining.
*/
public <S extends PositionOffsetOption> T press(S pressOptions) {
public T press(Position<PointOption> pressOptions) {
parameterBuilder.add(new ActionParameter("press", pressOptions));
//noinspection unchecked
return (T) this;
Expand All @@ -71,11 +75,11 @@ public <S extends PositionOffsetOption> T press(S pressOptions) {
*
* @param el element to press on.
* @return this TouchAction, for chaining.
* @deprecated use {@link #press(PositionOffsetOption)} instead
* @deprecated use {@link #press(Position)} instead
*/
@Deprecated
public T press(WebElement el) {
return press(element(el));
return press(Position.<PointOption>position().withElement(element(el)));
}

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

/**
Expand All @@ -98,11 +102,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(PositionOffsetOption)} instead
* @deprecated use {@link #press(Position)} instead
*/
@Deprecated
public T press(WebElement el, int x, int y) {
return press(WebElementOption.element(el, x, y));
return press(Position.<PointOption>position().withElement(element(el, x, y)));
}

/**
Expand All @@ -120,13 +124,12 @@ public T release() {
/**
* Moves current touch to a new position.
*
* @param moveToOptions see {@link WebElementOption} and {@link PositionOffsetOption}.
* @param moveToOptions see {@link Position}
* @return this TouchAction, for chaining.
*/
public <S extends PositionOffsetOption> T moveTo(S moveToOptions) {
public <S extends AbstractPositionOption> T moveTo(Position<S> moveToOptions) {
ActionParameter action = new ActionParameter("moveTo", moveToOptions);
parameterBuilder.add(action);
//noinspection unchecked
return (T) this;
}

Expand All @@ -135,11 +138,11 @@ public <S extends PositionOffsetOption> T moveTo(S moveToOptions) {
*
* @param el element to move to.
* @return this TouchAction, for chaining.
* @deprecated {@link #moveTo(PositionOffsetOption)} instead
* @deprecated {@link #moveTo(Position)} instead
*/
@Deprecated
public T moveTo(WebElement el) {
return moveTo(element(el));
return moveTo(position().withElement(element(el)));
}

/**
Expand All @@ -150,11 +153,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(PositionOffsetOption)} instead
* @deprecated {@link #moveTo(Position)} instead
*/
@Deprecated
public T moveTo(int x, int y) {
return (T) moveTo(offset(x, y));
return moveTo(position().withPosition(offset(x, y)));
}

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

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

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

/**
Expand All @@ -227,11 +230,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(PositionOffsetOption)} instead.
* @deprecated use {@link #tap(Position)} instead.
*/
@Deprecated
public T tap(WebElement el, int x, int y) {
return tap(WebElementOption.element(el, x, y));
return tap(Position.<PointOption>position().withElement(element(el, x, y)));
}

/**
Expand Down Expand Up @@ -292,10 +295,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 WebElementOption} and {@link PositionOffsetOption}.
* @param longPressOptions see {@link Position}.
* @return this TouchAction, for chaining.
*/
public <S extends PositionOffsetOption> T longPress(S longPressOptions) {
public T longPress(Position<PointOption> longPressOptions) {
ActionParameter action = new ActionParameter("longPress", longPressOptions);
parameterBuilder.add(action);
//noinspection unchecked
Expand All @@ -307,11 +310,11 @@ public <S extends PositionOffsetOption> T longPress(S longPressOptions) {
*
* @param el element to long-press.
* @return this TouchAction, for chaining.
* @deprecated use {@link #longPress(PositionOffsetOption)} instead
* @deprecated use {@link #longPress(Position)} instead
*/
@Deprecated
public T longPress(WebElement el) {
return longPress(element(el));
return longPress(Position.<PointOption>position().withElement(element(el)));
}

/**
Expand All @@ -325,7 +328,7 @@ public T longPress(WebElement el) {
@Deprecated
public T longPress(WebElement el, Duration duration) {
return longPress(longPressOptions()
.withDuration(duration).withOffset(element(el)));
.withDuration(duration).withElement(element(el)));
}

/**
Expand All @@ -335,11 +338,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(PositionOffsetOption)} instead
* @deprecated use {@link #longPress(Position)} instead
*/
@Deprecated
public T longPress(int x, int y) {
return (T) longPress(offset(x, y));
return longPress(Position.<PointOption>position().withPosition(coordinates(x, y)));
}

/**
Expand All @@ -355,7 +358,7 @@ public T longPress(int x, int y) {
@Deprecated
public T longPress(int x, int y, Duration duration) {
return (T) longPress(longPressOptions()
.withDuration(duration).withOffset(offset(x, y)));
.withDuration(duration).withPosition(coordinates(x, y)));
}

/**
Expand All @@ -366,11 +369,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(PositionOffsetOption)} instead
* @deprecated use {@link #longPress(Position)} instead
*/
@Deprecated
public T longPress(WebElement el, int x, int y) {
return longPress(WebElementOption.element(el, x, y));
return longPress(Position.<PointOption>position().withElement(element(el, x, y)));
}

/**
Expand All @@ -387,7 +390,7 @@ public T longPress(WebElement el, int x, int y) {
@Deprecated
public T longPress(WebElement el, int x, int y, Duration duration) {
return longPress(longPressOptions()
.withOffset(WebElementOption.element(el, x, y)).withDuration(duration));
.withElement(element(el, x, y)).withDuration(duration));
}

/**
Expand Down Expand Up @@ -417,7 +420,7 @@ public T perform() {
*/
protected ImmutableMap<String, ImmutableList<Object>> getParameters() {

ImmutableList.Builder<Object> parameters = ImmutableList.builder();
ImmutableList.Builder<Object> parameters = builder();
ImmutableList<ActionParameter> actionList = parameterBuilder.build();

actionList.forEach(action -> parameters.add(action.getParameterMap()));
Expand All @@ -430,7 +433,7 @@ protected ImmutableMap<String, ImmutableList<Object>> getParameters() {
* @return this TouchAction, for possible segmented-touches.
*/
protected T clearParameters() {
parameterBuilder = ImmutableList.builder();
parameterBuilder = builder();
//noinspection unchecked
return (T) this;
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/io/appium/java_client/ios/IOSTouchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package io.appium.java_client.ios;

import static io.appium.java_client.touch.WebElementOption.element;
import static io.appium.java_client.touch.offset.ElementOption.element;

import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.ActionOptions;
import io.appium.java_client.touch.PositionOffsetOption;
import io.appium.java_client.touch.WebElementOption;
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 @@ -38,33 +37,32 @@ public IOSTouchAction(PerformsTouchActions performsTouchActions) {
* @param x x offset.
* @param y y offset.
* @return this IOSTouchAction, for chaining.
* @deprecated use {@link #tap(PositionOffsetOption)} with count=2 instead.
* @deprecated use {@link #tap(Position)} with count=2 instead.
*/
@Deprecated
public IOSTouchAction doubleTap(WebElement el, int x, int y) {
return doubleTap(element(el, x, y));
return doubleTap(Position.<PointOption>position().withElement(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(PositionOffsetOption)} with count=2 instead.
* @deprecated use {@link #tap(Position)} with count=2 instead.
*/
@Deprecated
public IOSTouchAction doubleTap(WebElement el) {
return doubleTap(element(el));
return doubleTap(Position.<PointOption>position().withElement(element(el)));
}

/**
* Double taps using relative offset from an element.
* Double taps using coordinates.
*
* @param doubleTapOption is the relative offset parameter from the element.
* see {@link WebElementOption} and {@link PositionOffsetOption}.
* @param doubleTapOption see {@link Position}.
* @return self-reference
*/
public <S extends WebElementOption> IOSTouchAction doubleTap(ActionOptions<? super S> doubleTapOption) {
public IOSTouchAction doubleTap(Position<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 @@ -20,10 +20,14 @@
import static com.google.common.base.Preconditions.checkNotNull;
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 OptionsCombinedWithOffset<LongPressOptions> {
public class LongPressOptions
extends AbstractOptionCombinedWithPosition<LongPressOptions, PointOption> {
protected Duration duration = null;

/**
Expand Down
Loading