Skip to content

Commit ea31b9f

Browse files
authored
feat(java): ✨ added longPress and doubleTap support for mobile (#954)
1 parent 0877f82 commit ea31b9f

File tree

12 files changed

+112
-9
lines changed

12 files changed

+112
-9
lines changed

.github/workflows/test-core.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ jobs:
135135
run-ios: false
136136
run-android: true
137137
emulator-name: Pixel_8_Pro
138-
emulator-profile: pixel_7_pro
139-
emulator-version: 34
138+
emulator-profile: pixel_6_pro
139+
emulator-version: 31
140140
# emulator-channel: canary
141141
emulator-arch: x86_64
142142
emulator-target: google_apis

core-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<okhttp.version>4.12.0</okhttp.version>
3535
<lombok.version>1.18.36</lombok.version>
3636
<google-gson.version>2.11.0</google-gson.version>
37-
<google.guava.version>33.3.1-jre</google.guava.version>
37+
<google.guava.version>33.4.0-jre</google.guava.version>
3838
<google-truth.version>1.4.4</google-truth.version>
3939
<apache-commons-text.version>1.13.0</apache-commons-text.version>
4040
<commons-io.version>2.18.0</commons-io.version>

core-java/src/main/java/io/github/boykaframework/actions/elements/FingerActions.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import static java.util.Optional.ofNullable;
3030
import static org.apache.logging.log4j.LogManager.getLogger;
3131

32+
import java.util.List;
33+
3234
import io.github.boykaframework.actions.interfaces.elements.IFingerActions;
3335
import io.github.boykaframework.actions.interfaces.listeners.elements.IFingerActionsListener;
3436
import io.github.boykaframework.builders.Locator;
@@ -82,6 +84,20 @@ public static IFingerActions withFinger () {
8284
}
8385
}
8486

87+
@Override
88+
public void doubleTap () {
89+
LOGGER.traceEntry ();
90+
LOGGER.info ("Double Tapping on the element...");
91+
ofNullable (this.listener).ifPresent (l -> l.onDoubleTap (this.locator));
92+
final var sequences = getElementAttribute (element -> FingerGestureBuilder.init ()
93+
.sourceElement (this.locator)
94+
.pause (ofMillis (this.delaySetting.getBeforeTap ()))
95+
.build ()
96+
.tapOn (), this.locator, null);
97+
performMobileGestures (List.of (sequences, sequences));
98+
LOGGER.traceExit ();
99+
}
100+
85101
@Override
86102
public void dragTo (final Locator destination) {
87103
LOGGER.traceEntry ();
@@ -96,6 +112,24 @@ public void dragTo (final Locator destination) {
96112
LOGGER.traceExit ();
97113
}
98114

115+
@Override
116+
public void longPress (final long millis) {
117+
LOGGER.traceEntry ();
118+
LOGGER.info ("Long pressing on [{}] for [{}] ms.", this.locator.getName (), millis);
119+
ofNullable (this.listener).ifPresent (l -> l.onLongPress (this.locator, millis));
120+
final var dragSequence = getDriverAttribute (driver -> FingerGestureBuilder.init ()
121+
.sourceElement (this.locator)
122+
.build ()
123+
.tapAndHold (millis), null);
124+
performMobileGestures (singletonList (dragSequence));
125+
LOGGER.traceExit ();
126+
}
127+
128+
@Override
129+
public void longPress () {
130+
longPress (500);
131+
}
132+
99133
@Override
100134
public void swipe (final SwipeDirection direction) {
101135
LOGGER.traceEntry ();

core-java/src/main/java/io/github/boykaframework/actions/elements/FingerGestureBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static io.github.boykaframework.utils.Validator.validateDelay;
3232
import static java.time.Duration.ZERO;
3333
import static java.time.Duration.ofMillis;
34-
import static java.time.Duration.ofSeconds;
3534
import static java.util.Objects.isNull;
3635
import static org.openqa.selenium.interactions.PointerInput.Kind.TOUCH;
3736
import static org.openqa.selenium.interactions.PointerInput.Origin.viewport;
@@ -89,9 +88,9 @@ Sequence swipe () {
8988
return singleFingerGesture (startPosition, endPosition);
9089
}
9190

92-
Sequence tapAndHold () {
91+
Sequence tapAndHold (final long millis) {
9392
final var start = getElementCenter (this.sourceElement);
94-
this.pause = ofSeconds (1);
93+
this.pause = ofMillis (millis);
9594
return singleFingerGesture (start, null);
9695
}
9796

core-java/src/main/java/io/github/boykaframework/actions/interfaces/elements/IFingerActions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,30 @@
2626
* @since 15-Feb-2023
2727
*/
2828
public interface IFingerActions extends IElementActions {
29+
/**
30+
* Double tap on an element.
31+
*/
32+
void doubleTap ();
33+
2934
/**
3035
* Drag one element to another element.
3136
*
3237
* @param destination Target element
3338
*/
3439
void dragTo (final Locator destination);
3540

41+
/**
42+
* Long press on element for a particular duration.
43+
*
44+
* @param millis Duration of long press.
45+
*/
46+
void longPress (long millis);
47+
48+
/**
49+
* Long press on an element for 500 ms.
50+
*/
51+
void longPress ();
52+
3653
/**
3754
* Swipe on the Mobile screen starting from center of the screen to the direction mentioned
3855
*

core-java/src/main/java/io/github/boykaframework/actions/interfaces/listeners/elements/IFingerActionsListener.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
* @since 09-Apr-2023
2828
*/
2929
public interface IFingerActionsListener extends BoykaListener {
30+
/**
31+
* Handles double tap method.
32+
*
33+
* @param locator Locator of the element.
34+
*/
35+
default void onDoubleTap (final Locator locator) {
36+
// not implemented
37+
}
38+
3039
/**
3140
* Handle drag to method.
3241
*
@@ -37,6 +46,16 @@ default void onDragTo (final Locator source, final Locator destination) {
3746
// not implemented.
3847
}
3948

49+
/**
50+
* Handles long press method with specified duration
51+
*
52+
* @param locator Locator of the element.
53+
* @param millis Duration of long press.
54+
*/
55+
default void onLongPress (final Locator locator, long millis) {
56+
// not implemented
57+
}
58+
4059
/**
4160
* Handle swipe method.
4261
*

core-java/src/main/java/io/github/boykaframework/config/ui/mobile/device/DeviceSetting.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class DeviceSetting {
4242
private Map<String, Object> capabilities;
4343
private boolean clearFiles = true;
4444
private boolean clearLogs = true;
45+
private int commandTimeout = 60;
4546
private boolean fullReset;
4647
private boolean ignoreUnimportantViews = true;
4748
private String name;

core-java/src/main/java/io/github/boykaframework/manager/AndroidManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ private void setLocalUiAutomatorOptions (final UiAutomator2Options options) {
9999
options.setClearSystemFiles (this.settings.isClearFiles ());
100100
options.setClearDeviceLogsOnStart (this.settings.isClearLogs ());
101101
options.setNoReset (this.settings.isNoReset ());
102-
options.setAutoGrantPermissions (settings.isAutoGrantPermissions ());
102+
options.setNewCommandTimeout (ofSeconds (this.settings.getCommandTimeout ()));
103+
options.setAutoGrantPermissions (this.settings.isAutoGrantPermissions ());
103104
options.setFullReset (this.settings.isFullReset ());
104105
options.setUiautomator2ServerLaunchTimeout (ofSeconds (this.settings.getServerLaunchTimeout ()));
105106
options.setUiautomator2ServerInstallTimeout (ofSeconds (this.settings.getServerInstallTimeout ()));

core-java/src/main/java/io/github/boykaframework/manager/IOSManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ private void setupLocalSimulatorOptions (final XCUITestOptions options) {
136136
options.setClearSystemFiles (this.settings.isClearFiles ());
137137
options.setNoReset (this.settings.isNoReset ());
138138
options.setFullReset (this.settings.isFullReset ());
139+
options.setNewCommandTimeout (ofSeconds (this.settings.getCommandTimeout ()));
139140
options.setWebviewConnectTimeout (ofSeconds (this.settings.getWebViewConnectTimeout ()));
140141
options.setWebviewConnectRetries (this.settings.getWebViewConnectRetries ());
141142
options.setMaxTypingFrequency (this.settings.getTypingSpeed ());
142143
setWdaOptions (this.settings.getWda (), options);
143-
setPermissions (options, settings);
144+
setPermissions (options, this.settings);
144145
}
145146

146147
private void setupVirtualDeviceSetting (final DeviceType deviceType, final VirtualDeviceSetting virtualDevice,

core-java/src/test/resources/boyka-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
},
233233
"device": {
234234
"os": "ANDROID",
235-
"version": "14",
235+
"version": "12",
236236
"name": "Pixel_8_Pro",
237237
"type": "VIRTUAL",
238238
"server_install_timeout": 60,

0 commit comments

Comments
 (0)