Skip to content
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

Expand touch options API to accept coordinates as Point #997

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ public class ElementOption extends PointOption<ElementOption> {

private String elementId;

/**
* This method creates a build instance of the {@link ElementOption}.
*
* @param element is the element to calculate offset from.
* @param offset is the offset from the upper left corner of the given element.
* @return the built option
*/
public static ElementOption element(WebElement element, Point offset) {
return new ElementOption().withElement(element).withCoordinates(offset);
}


/**
* This method creates a build instance of the {@link ElementOption}.
*
Expand All @@ -40,13 +52,25 @@ public static ElementOption element(WebElement element) {
/**
* It defines x and y offset from the upper left corner of an element.
*
* @param xOffset is x value.
* @param yOffset is y value.
* @param offset is the offset from the upper left corner of the given element.
* @return self-reference
*/
@Override
public ElementOption withCoordinates(Point offset) {
super.withCoordinates(offset);
return this;
}

/**
* It defines x and y offset from the upper left corner of an element.
*
* @param xOffset is the x-offset from the upper left corner of the given element.
* @param yOffset is the y-offset from the upper left corner of the given element.
* @return self-reference
*/
@Override
public ElementOption withCoordinates(int xOffset, int yOffset) {
coordinates = new Point(xOffset, yOffset);
super.withCoordinates(xOffset, yOffset);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ public class PointOption<T extends PointOption<T>> extends ActionOptions<T> {

protected Point coordinates;

/**
* It creates a built instance of {@link PointOption} which takes x and y coordinates.
* This is offset from the upper left corner of the screen.
*
* @param offset is an offset value.
* @return a built option
*/
public static PointOption point(Point offset) {
return new PointOption().withCoordinates(offset);
}

/**
* It creates a built instance of {@link PointOption} which takes x and y coordinates.
* This is offset from the upper left corner of the screen.
Expand All @@ -23,6 +34,17 @@ public static PointOption point(int xOffset, int yOffset) {
return new PointOption().withCoordinates(xOffset, yOffset);
}

/**
* It defines x and y coordinates.
* This is offset from the upper left corner of the screen.
*
* @param offset is an offset value.
* @return self-reference
*/
public T withCoordinates(Point offset) {
return withCoordinates(offset.x, offset.y);
}

/**
* It defines x and y coordinates.
* This is offset from the upper left corner of the screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import org.junit.Test;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;

Expand Down Expand Up @@ -43,7 +44,7 @@ public void invalidEmptyElementOptionsShouldFailOnBuild() {
public void invalidOptionsArgumentsShouldFailOnAltering() {
final List<Runnable> invalidOptions = new ArrayList<>();
invalidOptions.add(() -> waitOptions(ofMillis(-1)));
invalidOptions.add(() -> new ElementOption().withCoordinates(0, 0).withElement(null));
invalidOptions.add(() -> new ElementOption().withCoordinates(new Point(0, 0)).withElement(null));
invalidOptions.add(() -> new WaitOptions().withDuration(null));
invalidOptions.add(() -> tapOptions().withTapsCount(-1));
invalidOptions.add(() -> longPressOptions().withDuration(null));
Expand Down Expand Up @@ -71,7 +72,7 @@ public void longPressOptionsShouldBuildProperly() {
@Test
public void tapOptionsShouldBuildProperly() {
final Map<String, Object> actualOpts = tapOptions()
.withPosition(point(0, 0))
.withPosition(point(new Point(0, 0)))
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now both would be possible: point(0, 0) and point(new Point(0, 0)) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes both are possible now.

.withTapsCount(2)
.build();
final Map<String, Object> expectedOpts = new HashMap<>();
Expand Down