-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from aquality-automation/feature/Swipe-Actions
Feature/swipe actions
- Loading branch information
Showing
26 changed files
with
546 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/aquality/appium/mobile/actions/IActionsModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package aquality.appium.mobile.actions; | ||
|
||
import aquality.appium.mobile.configuration.IConfigurationsModule; | ||
|
||
/** | ||
* Describes implementations of actions services to be registered in DI container. | ||
*/ | ||
public interface IActionsModule extends IConfigurationsModule { | ||
|
||
/** | ||
* @return class which implements {@link ITouchActions} | ||
*/ | ||
default Class<? extends ITouchActions> getTouchActionsImplementation() { | ||
return TouchActions.class; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/aquality/appium/mobile/actions/ITouchActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package aquality.appium.mobile.actions; | ||
|
||
import org.openqa.selenium.Point; | ||
|
||
/** | ||
* Describes general Touch Actions. | ||
*/ | ||
public interface ITouchActions { | ||
|
||
/** | ||
* Swipes from start point to end point using TouchAction. | ||
* | ||
* @param startPoint point on screen to swipe from. | ||
* @param endPoint point on screen to swipe to. | ||
*/ | ||
void swipe(Point startPoint, Point endPoint); | ||
|
||
/** | ||
* Performs long press action and moves cursor from a start point to an end point imitating the swipe action. | ||
* | ||
* @param startPoint point on screen to swipe from. | ||
* @param endPoint point on screen to swipe to. | ||
*/ | ||
void swipeWithLongPress(Point startPoint, Point endPoint); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/aquality/appium/mobile/actions/SwipeDirection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package aquality.appium.mobile.actions; | ||
|
||
/** | ||
* The enum describing the possible swipe directions. | ||
*/ | ||
public enum SwipeDirection { | ||
UP, | ||
DOWN, | ||
LEFT, | ||
RIGHT; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/aquality/appium/mobile/actions/TouchActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package aquality.appium.mobile.actions; | ||
|
||
import aquality.appium.mobile.application.AqualityServices; | ||
import aquality.appium.mobile.configuration.ITouchActionsConfiguration; | ||
import aquality.selenium.core.utilities.IElementActionRetrier; | ||
import io.appium.java_client.TouchAction; | ||
import io.appium.java_client.touch.offset.PointOption; | ||
import org.openqa.selenium.Point; | ||
import java.util.function.UnaryOperator; | ||
import static io.appium.java_client.touch.WaitOptions.waitOptions; | ||
|
||
public class TouchActions implements ITouchActions { | ||
|
||
@Override | ||
public void swipe(Point startPoint, Point endPoint) { | ||
AqualityServices.getLocalizedLogger().info( | ||
"loc.action.swipe", | ||
startPoint.getX(), | ||
startPoint.getY(), | ||
endPoint.getX(), | ||
endPoint.getY()); | ||
performTouchAction(touchAction -> touchAction | ||
.press(PointOption.point(startPoint)) | ||
.waitAction(waitOptions(AqualityServices.get(ITouchActionsConfiguration.class).getSwipeDuration())), | ||
endPoint); | ||
} | ||
|
||
@Override | ||
public void swipeWithLongPress(Point startPoint, Point endPoint) { | ||
AqualityServices.getLocalizedLogger().info( | ||
"loc.action.swipeLongPress", | ||
startPoint.getX(), | ||
startPoint.getY(), | ||
endPoint.getX(), | ||
endPoint.getY()); | ||
performTouchAction(touchAction -> touchAction.longPress(PointOption.point(startPoint)), endPoint); | ||
} | ||
|
||
protected void performTouchAction(UnaryOperator<TouchAction<?>> function, Point endPoint) { | ||
TouchAction<?> touchAction = new TouchAction<>(AqualityServices.getApplication().getDriver()); | ||
AqualityServices.get(IElementActionRetrier.class).doWithRetry(() -> | ||
function.apply(touchAction).moveTo(PointOption.point(endPoint)).release().perform()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package aquality.appium.mobile.configuration; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Describes Touch Actions settings. | ||
*/ | ||
public interface ITouchActionsConfiguration { | ||
/** | ||
* Gets number of retries to perform swipe. | ||
* | ||
* @return arguments map. | ||
*/ | ||
int getSwipeRetries(); | ||
|
||
/** | ||
* Gets the number of seconds required to perform a swipe action. | ||
* | ||
* @return number of seconds required to perform a swipe action. | ||
*/ | ||
Duration getSwipeDuration(); | ||
|
||
/** | ||
* Gets the offset coefficient to adjust the start/end point for swipe action relatively to the parallel screen edge. | ||
* Example for swipe down action: | ||
* The offset coefficient is used to calculate start/end point's Y coordinate. | ||
* If offset coefficient == 0.2, then the start point's Y coordinate == screen's length * (1 - 0.2). | ||
* If offset coefficient == 0.2, then the end point's Y coordinate == screen's length * 0.2. | ||
* The vice versa for swipe up action. | ||
* Example for swipe left action: | ||
* The offset coefficient is used to calculate start/end point's X coordinate. | ||
* If offset coefficient == 0.2, then the start point's X coordinate == screen's width * (1 - 0.2). | ||
* If offset coefficient == 0.2, then the end point's X coordinate == screen's width * 0.2. | ||
* The vice versa for swipe right action. | ||
* | ||
* @return offset coefficient to adjust the start/end point for swipe action relatively to the parallel screen edge | ||
*/ | ||
double getSwipeVerticalOffset(); | ||
|
||
/** | ||
* Gets the offset coefficient to adjust the start/end point for swipe action relatively to the perpendicular screen edge. | ||
* Example for swipe down action: | ||
* The offset coefficient is used to calculate start/end point's X coordinate. | ||
* If offset coefficient == 0.5, then the start point's X coordinate == screen's width * (1 - 0.5). | ||
* If offset coefficient == 0.5, then the end point's X coordinate == screen's width * 0.5. | ||
* The vice versa for swipe up action. | ||
* Example for swipe left action: | ||
* The offset coefficient is used to calculate start/end point's X coordinate. | ||
* If offset coefficient == 0.5, then the start point's Y coordinate == screen's length * (1 - 0.5). | ||
* If offset coefficient == 0.5, then the end point's Y coordinate == screen's length * 0.5. | ||
* The vice versa for swipe right action. | ||
* | ||
* @return offset coefficient to adjust the start/end point for swipe action relatively to the perpendicular screen edge | ||
*/ | ||
double getSwipeHorizontalOffset(); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package aquality.appium.mobile.configuration; | ||
|
||
import aquality.selenium.core.utilities.ISettingsFile; | ||
import com.google.inject.Inject; | ||
|
||
import java.time.Duration; | ||
|
||
public class TouchActionsConfiguration implements ITouchActionsConfiguration { | ||
private final Duration swipeDuration; | ||
private final int swipeRetries; | ||
private final double swipeVerticalOffset; | ||
private final double swipeHorizontalOffset; | ||
|
||
@Inject | ||
public TouchActionsConfiguration(ISettingsFile settingsFile) { | ||
this.swipeDuration = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/touchActions/swipe/duration").toString())); | ||
this.swipeRetries = (int) settingsFile.getValue("/touchActions/swipe/retries"); | ||
this.swipeVerticalOffset = (double) settingsFile.getValue("/touchActions/swipe/verticalOffset"); | ||
this.swipeHorizontalOffset = (double) settingsFile.getValue("/touchActions/swipe/horizontalOffset"); | ||
} | ||
|
||
@Override | ||
public int getSwipeRetries() { | ||
return this.swipeRetries; | ||
} | ||
|
||
@Override | ||
public Duration getSwipeDuration() { | ||
return this.swipeDuration; | ||
} | ||
|
||
@Override | ||
public double getSwipeVerticalOffset() { | ||
return this.swipeVerticalOffset; | ||
} | ||
|
||
@Override | ||
public double getSwipeHorizontalOffset() { | ||
return this.swipeHorizontalOffset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.