Skip to content

Commit

Permalink
Improve builders code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mykola Mokhnach committed Oct 16, 2017
1 parent 061379e commit 3ee2aca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

public abstract class OptionsWithRelativePositioning<T extends OptionsWithRelativePositioning<T>>
extends ActionOptions {
extends ActionOptions<T> {
private String elementId = null;
private Point relativeOffset = null;

Expand Down
53 changes: 36 additions & 17 deletions src/test/java/io/appium/java_client/android/AndroidTouchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public void setUp() throws Exception {
assertEquals("Drag text not empty", "", dragText.getText());

TouchAction dragNDrop = new TouchAction(driver)
.longPress(new LongPressOptions().withElement(dragDot1))
.moveTo(new MoveToOptions().withElement(dragDot3))
.longPress(new LongPressOptions()
.withElement(dragDot1))
.moveTo(new MoveToOptions()
.withElement(dragDot3))
.release();
dragNDrop.perform();
assertNotEquals("Drag text empty", "", dragText.getText());
Expand All @@ -54,8 +56,12 @@ public void setUp() throws Exception {
assertEquals("Drag text not empty", "", dragText.getText());

TouchAction dragNDrop = new TouchAction(driver)
.longPress(new LongPressOptions().withElement(dragDot1).withDuration(Duration.ofSeconds(2)))
.moveTo(new MoveToOptions().withElement(dragDot3)).release();
.longPress(new LongPressOptions()
.withElement(dragDot1)
.withDuration(Duration.ofSeconds(2)))
.moveTo(new MoveToOptions()
.withElement(dragDot3))
.release();
dragNDrop.perform();
assertNotEquals("Drag text empty", "", dragText.getText());
}
Expand All @@ -73,8 +79,10 @@ public void setUp() throws Exception {
Point center2 = dragDot3.getCenter();

TouchAction dragNDrop = new TouchAction(driver)
.longPress(new LongPressOptions().withAbsoluteOffset(center1.x, center1.y))
.moveTo(new MoveToOptions().withRelativeOffset(center2.x, center2.y))
.longPress(new LongPressOptions()
.withAbsoluteOffset(center1.x, center1.y))
.moveTo(new MoveToOptions()
.withRelativeOffset(center2.x, center2.y))
.release();
dragNDrop.perform();
assertNotEquals("Drag text empty", "", dragText.getText());
Expand All @@ -96,7 +104,8 @@ public void setUp() throws Exception {
.longPress(new LongPressOptions()
.withAbsoluteOffset(center1.x, center1.y)
.withDuration(Duration.ofSeconds(2)))
.moveTo(new MoveToOptions().withRelativeOffset(center2.x, center2.y))
.moveTo(new MoveToOptions()
.withRelativeOffset(center2.x, center2.y))
.release();
dragNDrop.perform();
assertNotEquals("Drag text empty", "", dragText.getText());
Expand All @@ -108,8 +117,10 @@ public void setUp() throws Exception {
Point point =
driver.findElementById("io.appium.android.apis:id/button_toggle").getLocation();
new TouchAction(driver)
.press(new PressOptions().withAbsoluteOffset(point.x + 20, point.y + 30))
.waitAction(new WaitOptions().withDuration(Duration.ofSeconds(1)))
.press(new PressOptions()
.withAbsoluteOffset(point.x + 20, point.y + 30))
.waitAction(new WaitOptions()
.withDuration(Duration.ofSeconds(1)))
.release()
.perform();
assertEquals("ON" ,driver
Expand All @@ -122,7 +133,8 @@ public void setUp() throws Exception {
new TouchAction(driver)
.press(new PressOptions()
.withElement(driver.findElementById("io.appium.android.apis:id/button_toggle")))
.waitAction(new WaitOptions().withDuration(Duration.ofSeconds(1)))
.waitAction(new WaitOptions()
.withDuration(Duration.ofSeconds(1)))
.release()
.perform();
assertEquals("ON" ,driver
Expand All @@ -136,9 +148,12 @@ public void setUp() throws Exception {
driver.findElementById("io.appium.android.apis:id/chronometer");

TouchAction startStop = new TouchAction(driver)
.tap(new TapOptions().withElement(driver.findElementById("io.appium.android.apis:id/start")))
.waitAction(new WaitOptions().withDuration(Duration.ofSeconds(2)))
.tap(new TapOptions().withElement(driver.findElementById("io.appium.android.apis:id/stop")));
.tap(new TapOptions()
.withElement(driver.findElementById("io.appium.android.apis:id/start")))
.waitAction(new WaitOptions()
.withDuration(Duration.ofSeconds(2)))
.tap(new TapOptions()
.withElement(driver.findElementById("io.appium.android.apis:id/stop")));

startStop.perform();

Expand All @@ -157,7 +172,8 @@ public void setUp() throws Exception {
Point center1 = driver.findElementById("io.appium.android.apis:id/start").getCenter();

TouchAction startStop = new TouchAction(driver)
.tap(new TapOptions().withAbsoluteOffset(center1.x, center1.y))
.tap(new TapOptions()
.withAbsoluteOffset(center1.x, center1.y))
.tap(new TapOptions()
.withElement(driver.findElementById("io.appium.android.apis:id/stop"))
.withRelativeOffset(5, 5));
Expand All @@ -181,9 +197,11 @@ public void setUp() throws Exception {
Point center = gallery.getCenter();

TouchAction swipe = new TouchAction(driver)
.press(new PressOptions().withElement(images.get(2))
.press(new PressOptions()
.withElement(images.get(2))
.withRelativeOffset( -10, center.y - location.y))
.waitAction(new WaitOptions().withDuration(Duration.ofSeconds(2)))
.waitAction(new WaitOptions()
.withDuration(Duration.ofSeconds(2)))
.moveTo(new MoveToOptions()
.withElement(gallery)
.withRelativeOffset( 10, center.y - location.y))
Expand All @@ -201,7 +219,8 @@ public void setUp() throws Exception {
.withElement(driver.findElementById("io.appium.android.apis:id/button_toggle")))
.waitAction(new WaitOptions().withDuration(Duration.ofSeconds(1)))
.release();
new MultiTouchAction(driver).add(press)
new MultiTouchAction(driver)
.add(press)
.perform();
assertEquals("ON" ,driver
.findElementById("io.appium.android.apis:id/button_toggle").getText());
Expand Down

0 comments on commit 3ee2aca

Please sign in to comment.