Skip to content

Commit 997b2a9

Browse files
committed
Updating the swipe coefficients calculation:
- test.resources.settings.json, test.resources.settings.androidwebsession.json, src.resources.settings.json: -- replacing swipe coefficients with verticalOffset and horizontalOffset -- replacing swipe timeout with swipe duration - ITouchActionsConfiguration, TouchActionsConfiguration: -- replacing getSwipeTimeout() with getSwipeDuration() -- getSwipePointCoefficients() with getSwipeVerticalOffset() and getSwipeHorizontalOffset() -- added explicit documentation for getSwipeHorizontalOffset() and getSwipeVerticalOffset() - actions.TouchActions: -- replacing call to getSwipeTimeout() with getSwipeDuration() - elements.actions.ELementTouchActions: -- replacted getITouchActionsConfiguration() with getConfiguration() -- replaced getITouchActionsConfiguration().getSwipePointCoefficient() with getSwipeOffset() - elements.actions.IELementTouchActions: -- made interface parameters final - actions.SwipeDirection, action.ITouchActions: -- updated javadoc - actions.IActionsModule -- replaced import
1 parent b8edd47 commit 997b2a9

File tree

11 files changed

+83
-176
lines changed

11 files changed

+83
-176
lines changed

src/main/java/aquality/appium/mobile/actions/IActionsModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package aquality.appium.mobile.actions;
22

3+
import aquality.appium.mobile.configuration.IConfigurationsModule;
4+
35
/**
46
* Describes implementations of actions services to be registered in DI container.
57
*/
6-
public interface IActionsModule extends aquality.selenium.core.configurations.IConfigurationsModule {
8+
public interface IActionsModule extends IConfigurationsModule {
79

810
/**
911
* @return class which implements {@link ITouchActions}

src/main/java/aquality/appium/mobile/actions/ITouchActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface ITouchActions {
1616
void swipe(Point startPoint, Point endPoint);
1717

1818
/**
19-
* Performs long press action and moves cursor from a start point to an end end point imitating the swipe action
19+
* Performs long press action and moves cursor from a start point to an end end point imitating the swipe action.
2020
*
2121
* @param startPoint point on screen to swipe from.
2222
* @param endPoint point on screen to swipe to.

src/main/java/aquality/appium/mobile/actions/SwipeDirection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package aquality.appium.mobile.actions;
22

3+
/**
4+
* The enum describing the possible swipe directions.
5+
*/
36
public enum SwipeDirection {
47
UP,
58
DOWN,

src/main/java/aquality/appium/mobile/actions/TouchActions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public void swipe(Point startPoint, Point endPoint) {
2020
endPoint.getX(),
2121
endPoint.getY());
2222
performTouchAction(touchAction -> touchAction
23-
.press(PointOption.point(startPoint))
24-
.waitAction(waitOptions(AqualityServices.get(ITouchActionsConfiguration.class).getSwipeTimeout())),
23+
.press(PointOption.point(startPoint))
24+
.waitAction(waitOptions(AqualityServices.get(ITouchActionsConfiguration.class).getSwipeDuration())),
2525
endPoint);
2626
}
2727

src/main/java/aquality/appium/mobile/configuration/ITouchActionsConfiguration.java

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,66 +14,43 @@ public interface ITouchActionsConfiguration {
1414
int getSwipeRetries();
1515

1616
/**
17-
* Gets the timeout to perform a swipe.
17+
* Gets the number of seconds required to perform a swipe action.
1818
*
19-
* @return timeout to perform swipe.
19+
* @return number of seconds required to perform a swipe action.
2020
*/
21-
Duration getSwipeTimeout();
21+
Duration getSwipeDuration();
2222

2323
/**
24-
* Gets the coefficient to calculate the 'x' coordinate of top point for swipe action.
24+
* Gets the offset coefficient to adjust the start/end point for swipe action relatively to the parallel screen edge.
25+
* Example for swipe down action:
26+
* The offset coefficient is used to calculate start/end point's Y coordinate.
27+
* If offset coefficient == 0.2, then the start point's Y coordinate == screen's length * (1 - 0.2).
28+
* If offset coefficient == 0.2, then the end point's Y coordinate == screen's length * 0.2.
29+
* The vice versa for swipe up action.
30+
* Example for swipe left action:
31+
* The offset coefficient is used to calculate start/end point's X coordinate.
32+
* If offset coefficient == 0.2, then the start point's X coordinate == screen's width * (1 - 0.2).
33+
* If offset coefficient == 0.2, then the end point's X coordinate == screen's width * 0.2.
34+
* The vice versa for swipe right action.
2535
*
26-
* @return coefficient to calculate the 'x' coordinate of top point for swipe action
36+
* @return offset coefficient to adjust the start/end point for swipe action relatively to the parallel screen edge
2737
*/
28-
double getHorizontalSwipeTopPointXCoefficient();
38+
double getSwipeVerticalOffset();
2939

3040
/**
31-
* Gets the coefficient to calculate the 'x' coordinate of bottom point for swipe action.
41+
* Gets the offset coefficient to adjust the start/end point for swipe action relatively to the perpendicular screen edge.
42+
* Example for swipe down action:
43+
* The offset coefficient is used to calculate start/end point's X coordinate.
44+
* If offset coefficient == 0.5, then the start point's X coordinate == screen's width * (1 - 0.5).
45+
* If offset coefficient == 0.5, then the end point's X coordinate == screen's width * 0.5.
46+
* The vice versa for swipe up action.
47+
* Example for swipe left action:
48+
* The offset coefficient is used to calculate start/end point's X coordinate.
49+
* If offset coefficient == 0.5, then the start point's Y coordinate == screen's length * (1 - 0.5).
50+
* If offset coefficient == 0.5, then the end point's Y coordinate == screen's length * 0.5.
51+
* The vice versa for swipe right action.
3252
*
33-
* @return coefficient to calculate the 'x' coordinate of bottom point for swipe action
53+
* @return offset coefficient to adjust the start/end point for swipe action relatively to the perpendicular screen edge
3454
*/
35-
double getHorizontalSwipeBottomPointXCoefficient();
36-
37-
/**
38-
* Gets the coefficient to calculate the 'y' coordinate of top point for swipe action.
39-
*
40-
* @return coefficient to calculate the 'y' coordinate of top point for swipe action
41-
*/
42-
double getHorizontalSwipeTopPointYCoefficient();
43-
44-
/**
45-
* Gets the coefficient to calculate the 'y' coordinate of bottom point for swipe action.
46-
*
47-
* @return coefficient to calculate the 'y' coordinate of bottom point for swipe action
48-
*/
49-
double getHorizontalSwipeBottomPointYCoefficient();
50-
51-
/**
52-
* Gets the coefficient to calculate the 'x' coordinate of top point for swipe action.
53-
*
54-
* @return timeout to perform swipe.
55-
*/
56-
double getVerticalSwipeLeftPointXCoefficient();
57-
58-
/**
59-
* Gets the coefficient to calculate the 'x' coordinate of right-hand point for swipe action.
60-
*
61-
* @return coefficient to calculate the 'x' coordinate of right-hand point for swipe action
62-
*/
63-
double getVerticalSwipeRightPointXCoefficient();
64-
65-
/**
66-
* Gets the coefficient to calculate the 'y' coordinate of left-hand point for swipe action.
67-
*
68-
* @return coefficient to calculate the 'y' coordinate of left-hand point for swipe action
69-
*/
70-
double getVerticalSwipeLeftPointYCoefficient();
71-
72-
73-
/**
74-
* Gets the coefficient to calculate the 'y' coordinate of right-hand point for swipe action.
75-
*
76-
* @return coefficient to calculate the 'y' coordinate of right-hand point for swipe action
77-
*/
78-
double getVerticalSwipeRightPointYCoefficient();
55+
double getSwipeHorizontalOffset();
7956
}

src/main/java/aquality/appium/mobile/configuration/TouchActionsConfiguration.java

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,17 @@
66
import java.time.Duration;
77

88
public class TouchActionsConfiguration implements ITouchActionsConfiguration {
9+
private final Duration swipeDuration;
910
private final int swipeRetries;
10-
private final Duration swipeTimeout;
11-
private final double horizontalSwipeTopPointXCoefficient;
12-
private final double horizontalSwipeBottomPointXCoefficient;
13-
private final double horizontalSwipeTopPointYCoefficient;
14-
private final double horizontalSwipeBottomPointYCoefficient;
15-
private final double verticalSwipeLeftPointXCoefficient;
16-
private final double verticalSwipeRightPointXCoefficient;
17-
private final double verticalSwipeLeftPointYCoefficient;
18-
private final double verticalSwipeRightPointYCoefficient;
11+
private final double swipeVerticalOffset;
12+
private final double swipeHorizontalOffset;
1913

2014
@Inject
2115
public TouchActionsConfiguration(ISettingsFile settingsFile) {
16+
this.swipeDuration = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/touchActions/swipe/duration").toString()));
2217
this.swipeRetries = (int) settingsFile.getValue("/touchActions/swipe/retries");
23-
this.swipeTimeout = Duration.ofSeconds(Long.parseLong(settingsFile.getValue("/touchActions/swipe/timeout").toString()));
24-
this.horizontalSwipeTopPointXCoefficient = getSwipeCoefficient(
25-
settingsFile, "horizontalSwipeTopPointXCoefficient");
26-
this.horizontalSwipeBottomPointXCoefficient = getSwipeCoefficient(
27-
settingsFile, "horizontalSwipeBottomPointXCoefficient");
28-
this.horizontalSwipeTopPointYCoefficient = getSwipeCoefficient(
29-
settingsFile, "horizontalSwipeTopPointYCoefficient");
30-
this.horizontalSwipeBottomPointYCoefficient = getSwipeCoefficient(
31-
settingsFile, "horizontalSwipeBottomPointYCoefficient");
32-
this.verticalSwipeLeftPointXCoefficient = getSwipeCoefficient(
33-
settingsFile, "verticalSwipeLeftPointXCoefficient");
34-
this.verticalSwipeRightPointXCoefficient = getSwipeCoefficient(
35-
settingsFile, "verticalSwipeRightPointXCoefficient");
36-
this.verticalSwipeLeftPointYCoefficient = getSwipeCoefficient(
37-
settingsFile, "verticalSwipeLeftPointYCoefficient");
38-
this.verticalSwipeRightPointYCoefficient = getSwipeCoefficient(
39-
settingsFile, "verticalSwipeRightPointYCoefficient");
18+
this.swipeVerticalOffset = (double) settingsFile.getValue("/touchActions/swipe/verticalOffset");
19+
this.swipeHorizontalOffset = (double) settingsFile.getValue("/touchActions/swipe/horizontalOffset");
4020
}
4121

4222
@Override
@@ -45,51 +25,17 @@ public int getSwipeRetries() {
4525
}
4626

4727
@Override
48-
public Duration getSwipeTimeout() {
49-
return this.swipeTimeout;
28+
public Duration getSwipeDuration() {
29+
return this.swipeDuration;
5030
}
5131

5232
@Override
53-
public double getHorizontalSwipeTopPointXCoefficient() {
54-
return this.horizontalSwipeTopPointXCoefficient;
33+
public double getSwipeVerticalOffset() {
34+
return this.swipeVerticalOffset;
5535
}
5636

5737
@Override
58-
public double getHorizontalSwipeBottomPointXCoefficient() {
59-
return this.horizontalSwipeBottomPointXCoefficient;
60-
}
61-
62-
@Override
63-
public double getHorizontalSwipeTopPointYCoefficient() {
64-
return this.horizontalSwipeTopPointYCoefficient;
65-
}
66-
67-
@Override
68-
public double getHorizontalSwipeBottomPointYCoefficient() {
69-
return this.horizontalSwipeBottomPointYCoefficient;
70-
}
71-
72-
@Override
73-
public double getVerticalSwipeLeftPointXCoefficient() {
74-
return this.verticalSwipeLeftPointXCoefficient;
75-
}
76-
77-
@Override
78-
public double getVerticalSwipeRightPointXCoefficient() {
79-
return this.verticalSwipeRightPointXCoefficient;
80-
}
81-
82-
@Override
83-
public double getVerticalSwipeLeftPointYCoefficient() {
84-
return this.verticalSwipeLeftPointYCoefficient;
85-
}
86-
87-
@Override
88-
public double getVerticalSwipeRightPointYCoefficient() {
89-
return this.verticalSwipeRightPointYCoefficient;
90-
}
91-
92-
private double getSwipeCoefficient(ISettingsFile settingsFile, String swipeCoefficientKey) {
93-
return Double.parseDouble(settingsFile.getValue(String.format("/touchActions/swipe/%s", swipeCoefficientKey)).toString());
38+
public double getSwipeHorizontalOffset() {
39+
return this.swipeHorizontalOffset;
9440
}
9541
}

src/main/java/aquality/appium/mobile/elements/actions/ElementTouchActions.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ public ElementTouchActions(IElement element) {
2323
this.element = element;
2424
this.scrollDownStartPoint = recalculatePointCoordinates(
2525
getBottomRightCornerPoint(),
26-
getITouchActionsConfiguration().getHorizontalSwipeBottomPointXCoefficient(),
27-
getITouchActionsConfiguration().getHorizontalSwipeBottomPointYCoefficient());
26+
(1 - getConfiguration().getSwipeHorizontalOffset()),
27+
(1 - getConfiguration().getSwipeVerticalOffset()));
2828
this.scrollDownEndPoint = recalculatePointCoordinates(
2929
getBottomRightCornerPoint(),
30-
getITouchActionsConfiguration().getHorizontalSwipeTopPointXCoefficient(),
31-
getITouchActionsConfiguration().getHorizontalSwipeTopPointYCoefficient());
30+
getConfiguration().getSwipeHorizontalOffset(),
31+
getConfiguration().getSwipeVerticalOffset());
3232
this.swipeLeftStartPoint = recalculatePointCoordinates(
3333
getBottomRightCornerPoint(),
34-
getITouchActionsConfiguration().getVerticalSwipeRightPointXCoefficient(),
35-
getITouchActionsConfiguration().getVerticalSwipeRightPointYCoefficient());
34+
(1 - getConfiguration().getSwipeVerticalOffset()),
35+
(1 - getConfiguration().getSwipeHorizontalOffset()));
3636
this.swipeLeftEndPoint = recalculatePointCoordinates(
3737
getBottomRightCornerPoint(),
38-
getITouchActionsConfiguration().getVerticalSwipeLeftPointXCoefficient(),
39-
getITouchActionsConfiguration().getVerticalSwipeLeftPointYCoefficient());
38+
getConfiguration().getSwipeVerticalOffset(),
39+
getConfiguration().getSwipeHorizontalOffset());
4040
this.scrollUpStartPoint = this.scrollDownEndPoint;
4141
this.scrollUpEndPoint = this.scrollDownStartPoint;
4242
this.swipeRightStartPoint = this.swipeLeftEndPoint;
@@ -92,23 +92,23 @@ private Point getBottomRightCornerPoint() {
9292
/**
9393
* Returns the point with recalculated coordinates.
9494
*
95-
* @param point point to recalculate coordinates
96-
* @param coefficientX coefficient to recalculate the point's x coordinate. Example: x' = x * coefficientX
97-
* @param coefficientY coefficient to recalculate the point's y coordinate. Example: y' = y * coefficientY
98-
* @return point with recalculated coordinates according to the xCoefficient and yCoefficient
95+
* @param point point to recalculate coordinates
96+
* @param horizontalOffset coefficient to recalculate the point with horizontal offset.
97+
* @param verticalOffset coefficient to recalculate the point with vertical offset.
98+
* @return point with recalculated coordinates with horizontal and vertical offset.
9999
*/
100-
private Point recalculatePointCoordinates(Point point, double coefficientX, double coefficientY) {
100+
private Point recalculatePointCoordinates(Point point, double horizontalOffset, double verticalOffset) {
101101
return new Point(
102-
(int) (point.getX() * coefficientX),
103-
(int) (point.getY() * coefficientY));
102+
(int) (point.getX() * horizontalOffset),
103+
(int) (point.getY() * verticalOffset));
104104
}
105105

106106
/**
107107
* Returns ITouchActionsConfiguration class.
108108
*
109109
* @return ITouchActionsConfiguration class
110110
*/
111-
private ITouchActionsConfiguration getITouchActionsConfiguration() {
111+
private ITouchActionsConfiguration getConfiguration() {
112112
return AqualityServices.get(ITouchActionsConfiguration.class);
113113
}
114114
}

src/main/java/aquality/appium/mobile/elements/actions/IElementTouchActions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ public interface IElementTouchActions {
1313
*
1414
* @param endPoint point on screen to swipe to.
1515
*/
16-
void swipe(Point endPoint);
16+
void swipe(final Point endPoint);
1717

1818
/**
1919
* Swipes from element to end point using LongPress.
2020
*
2121
* @param endPoint point on screen to swipe to.
2222
*/
23-
void swipeWithLongPress(Point endPoint);
23+
void swipeWithLongPress(final Point endPoint);
2424

2525
/**
2626
* Scrolls current screen in provided direction until element is displayed.
2727
*
2828
* @param direction direction to swipe.
2929
*/
30-
void scrollToElement(SwipeDirection direction);
30+
void scrollToElement(final SwipeDirection direction);
3131
}

src/main/resources/settings.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"platformName" : "android",
2+
"platformName": "android",
33
"isRemote": false,
44
"remoteConnectionUrl": "http://127.0.0.1:4723/wd/hub",
55
"screensLocation": "<NAME_OF_PACKAGE_WITH_SCREENS>",
6-
76
"driverSettings": {
87
"android": {
98
"deviceKey": "<KEY_OF_ANDROID_DEVICE_FROM_DEVICES_JSON>",
@@ -47,16 +46,10 @@
4746
},
4847
"touchActions": {
4948
"swipe": {
50-
"timeout": 1,
49+
"duration": 1,
5150
"retries": 5,
52-
"horizontalSwipeTopPointXCoefficient": 0.5,
53-
"horizontalSwipeBottomPointXCoefficient": 0.5,
54-
"horizontalSwipeTopPointYCoefficient": 0.2,
55-
"horizontalSwipeBottomPointYCoefficient": 0.8,
56-
"verticalSwipeLeftPointXCoefficient": 0.2,
57-
"verticalSwipeRightPointXCoefficient": 0.8,
58-
"verticalSwipeLeftPointYCoefficient": 0.5,
59-
"verticalSwipeRightPointYCoefficient": 0.5
51+
"verticalOffset": 0.2,
52+
"horizontalOffset": 0.5
6053
}
6154
}
6255
}

0 commit comments

Comments
 (0)