-
Notifications
You must be signed in to change notification settings - Fork 16
feat/CUS-8510-Added support for tap and hold on element for duration on Android elements #255
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
Conversation
WalkthroughThis pull request introduces a new Maven module implementing an Android action addon for Testsigma that enables tap-and-hold gesture functionality on mobile elements with configurable duration. The module includes Maven configuration, an action implementation class, and SDK properties setup. Changes
Sequence DiagramsequenceDiagram
participant Test as Test Framework
participant Action as TapAndHoldOnElementForDuration
participant Driver as AndroidDriver
participant Element as WebElement
Test->>Action: execute()
activate Action
rect rgb(200, 220, 255)
Note over Action: Validate Duration
alt Duration < 0
Action-->>Test: FAILED (Invalid duration)
end
end
rect rgb(220, 200, 255)
Note over Action: Get & Check Element
Action->>Driver: findElement()
Driver-->>Element: WebElement
alt Element not visible
Action-->>Test: FAILED (Element not visible)
end
end
rect rgb(200, 255, 220)
Note over Action: Perform Gesture
Action->>Driver: new TouchAction(driver)
Driver->>Element: longPress(duration)
Driver->>Driver: release().perform()
end
Action->>Action: Log Success
Action-->>Test: SUCCESS
deactivate Action
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested Reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
tap_and_hold_on_element_for_duration/pom.xml (1)
42-46: Update TestNG to a recent version.TestNG 6.14.3 is from 2018 and is significantly outdated. Consider upgrading to version 7.x for bug fixes, security patches, and compatibility improvements.
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> - <version>6.14.3</version> + <version>7.10.2</version> </dependency>tap_and_hold_on_element_for_duration/src/main/java/com/testsigma/addons/android/TapAndHoldOnElementForDuration.java (1)
51-69: Add explicit wait for element visibility.The direct
isDisplayed()check without an explicit wait can lead to flaky test execution. If the element is still rendering, the check might fail prematurely.+ WebDriverWait wait = new WebDriverWait(androidDriver, Duration.ofSeconds(10)); + try { + wait.until(ExpectedConditions.visibilityOf(webElement)); + } catch (TimeoutException e) { + result = com.testsigma.sdk.Result.FAILED; + logger.warn("Element is not visible within timeout"); + setErrorMessage("Element is not visible within timeout"); + return result; + } + - if (webElement.isDisplayed()) { logger.info("Element is visible, performing long press for " + holdSeconds + " seconds..."); // ... rest of the code - } else { - result = com.testsigma.sdk.Result.FAILED; - logger.warn("Element is not visible"); - setErrorMessage("Element is not visible"); - return result; - }Note: Add imports:
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.TimeoutException;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tap_and_hold_on_element_for_duration/pom.xml(1 hunks)tap_and_hold_on_element_for_duration/src/main/java/com/testsigma/addons/android/TapAndHoldOnElementForDuration.java(1 hunks)tap_and_hold_on_element_for_duration/src/main/resources/testsigma-sdk.properties(1 hunks)
🔇 Additional comments (4)
tap_and_hold_on_element_for_duration/src/main/java/com/testsigma/addons/android/TapAndHoldOnElementForDuration.java (2)
42-47: Good validation, but consider zero as valid.The validation correctly rejects negative durations. However, consider whether a zero-second hold duration is a valid use case (immediate tap-release). If so, the condition should be
holdSeconds < 0(which is already correct). If not, it should beholdSeconds <= 0.
60-63: LGTM: Clear and informative success message.The success message provides all relevant details including duration, locator type, and locator value, which is helpful for debugging and test reporting.
tap_and_hold_on_element_for_duration/pom.xml (2)
59-63: jackson-annotations 2.13.0 is current stable and no known security vulnerabilities found for this package.Version 2.13.0 is part of Jackson's current stable, actively maintained branch. The 2.13 release notes indicate "No changes since 2.12", and this version was released on September 30, 2021. The GitHub Security Advisory search returned no known CVEs for jackson-annotations 2.13.0 (distinct from jackson-databind vulnerabilities). For consistency with newer releases, Jackson 2.20 was released on August 28, 2025, though updating to a newer minor version is optional rather than critical.
48-58: Update dependency versions to latest stable releases.Selenium-java 4.33.0 is outdated; the latest stable version is 4.38.0 (released Oct 25, 2025). Appium java-client 9.4.0 should be updated to 10.0.0 (released Aug 13, 2025). Verify that the Appium major version upgrade introduces no breaking changes in your codebase before updating.
| import io.appium.java_client.TouchAction; | ||
| import io.appium.java_client.android.AndroidDriver; | ||
| import io.appium.java_client.touch.WaitOptions; | ||
| import io.appium.java_client.touch.offset.ElementOption; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: TouchAction API is deprecated.
The TouchAction class and related APIs (WaitOptions, ElementOption) are deprecated in Appium's java-client. Modern Appium uses W3C Actions API or mobile-specific gesture commands.
Consider using one of these modern approaches:
Option 1: W3C Actions API (preferred)
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Pause;
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
// In execute method:
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence longPress = new Sequence(finger, 1)
.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(),
webElement.getLocation().getX(), webElement.getLocation().getY()))
.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()))
.addAction(new Pause(finger, Duration.ofSeconds(holdSeconds)))
.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
androidDriver.perform(List.of(longPress));Option 2: Mobile gesture command
androidDriver.executeScript("mobile: longClickGesture", Map.of(
"elementId", ((RemoteWebElement) webElement).getId(),
"duration", holdSeconds * 1000
));🤖 Prompt for AI Agents
In
tap_and_hold_on_element_for_duration/src/main/java/com/testsigma/addons/android/TapAndHoldOnElementForDuration.java
around lines 8 to 11, the code imports and uses deprecated
TouchAction/WaitOptions/ElementOption APIs; replace this with a modern W3C
Actions or mobile gesture implementation. Preferred: use Selenium W3C
PointerInput/Sequence to perform a touch pointer move to the element center,
pointerDown, a Pause for the required duration, then pointerUp and call
androidDriver.perform with the sequence; ensure you compute element coordinates
(center) and convert duration to a java.time.Duration. Alternate: use the mobile
gesture command via androidDriver.executeScript("mobile: longClickGesture",
Map.of("elementId", ((RemoteWebElement)element).getId(), "duration",
holdSeconds*1000)) if you prefer a simpler platform-specific approach. Ensure to
remove deprecated imports and add required imports for PointerInput, Sequence,
Pause and Duration.
| WebElement webElement = element.getElement(); | ||
|
|
||
| try { | ||
| int holdSeconds = Integer.parseInt(timeInSeconds.getValue().toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Add explicit handling for invalid numeric input.
Integer.parseInt() will throw NumberFormatException if the input is not a valid integer. While this is caught by the generic exception handler, providing a specific error message would improve user experience.
+ try {
int holdSeconds = Integer.parseInt(timeInSeconds.getValue().toString());
+ } catch (NumberFormatException e) {
+ logger.warn("Invalid time format: " + timeInSeconds.getValue());
+ setErrorMessage("Time parameter must be a valid integer, received: " + timeInSeconds.getValue());
+ return com.testsigma.sdk.Result.FAILED;
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| int holdSeconds = Integer.parseInt(timeInSeconds.getValue().toString()); | |
| try { | |
| int holdSeconds = Integer.parseInt(timeInSeconds.getValue().toString()); | |
| } catch (NumberFormatException e) { | |
| logger.warn("Invalid time format: " + timeInSeconds.getValue()); | |
| setErrorMessage("Time parameter must be a valid integer, received: " + timeInSeconds.getValue()); | |
| return com.testsigma.sdk.Result.FAILED; | |
| } |
🤖 Prompt for AI Agents
In
tap_and_hold_on_element_for_duration/src/main/java/com/testsigma/addons/android/TapAndHoldOnElementForDuration.java
around line 40, Integer.parseInt(timeInSeconds.getValue().toString()) can throw
NumberFormatException for invalid input; wrap the parse in a try/catch that
catches NumberFormatException (after trimming the string), and in the catch
log/throw a clear, user-facing error that includes the invalid value and states
an integer number of seconds is expected (or set a validated default/exit flow
as appropriate) so the error is explicit rather than buried in a generic
exception handler.
| @@ -0,0 +1 @@ | |||
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjU2MTYiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.xMWTzBwe5zvZWgizb9c0wOhdMRMWJ5J2mo9hVPfsXezVQ3HfNixUaRstWCbenKuq2E6WrCHPjS0u2qTidNsERA No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Remove hardcoded API key from version control.
This file contains a hardcoded JWT token that appears to be a sensitive API key. Credentials should never be committed to version control as they can be exposed to anyone with repository access.
Recommended approach:
- Remove this file from the repository and add it to
.gitignore - Use environment variables or a secure secrets management system
- Provide a template file (e.g.,
testsigma-sdk.properties.template) with placeholder values - Rotate the exposed API key immediately as it may already be compromised
#!/bin/bash
# Verify if there's a .gitignore that excludes properties files with secrets
rg -n "testsigma-sdk\.properties" .gitignore || echo "No .gitignore entry found for testsigma-sdk.properties"
# Check if similar patterns exist in other modules
fd -e properties . --exec grep -l "api.key"🤖 Prompt for AI Agents
In
tap_and_hold_on_element_for_duration/src/main/resources/testsigma-sdk.properties
lines 1-1: this file contains a hardcoded sensitive API/JWT token; remove the
credential from version control immediately by deleting the file from the repo
(or removing the secret line and committing), add testsigma-sdk.properties to
.gitignore, create a testsigma-sdk.properties.template with placeholder keys,
switch the code to read the API key from an environment variable or a secret
manager instead of this file, and rotate/revoke the exposed API key as it may be
compromised.
Publish this addon as public
Addon Name: Tap And Hold On Element For Duration
Jarvis Link: https://jarvis.testsigma.com/ui/tenants/2817/addons
Jira : https://testsigma.atlassian.net/browse/CUS-8510
Added support for tap and hold on element for duration on Android elements
Summary by CodeRabbit