From e5dfb9b68478739ed6e6c9085da7348c7e001f4c Mon Sep 17 00:00:00 2001 From: Akhil Appini Date: Tue, 17 Feb 2026 17:58:03 +0530 Subject: [PATCH 1/2] Added class to swipe based on directions --- swipe_within_element_with_offset/pom.xml | 97 ++++++++++++++++ .../addons/web/SwipeWithInElementOffset.java | 107 ++++++++++++++++++ .../main/resources/testsigma-sdk.properties | 1 + 3 files changed, 205 insertions(+) create mode 100644 swipe_within_element_with_offset/pom.xml create mode 100644 swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java create mode 100644 swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties diff --git a/swipe_within_element_with_offset/pom.xml b/swipe_within_element_with_offset/pom.xml new file mode 100644 index 00000000..920dc02d --- /dev/null +++ b/swipe_within_element_with_offset/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + com.testsigma.addons + swipe_within_element_with_offset + 1.0.5 + jar + + + UTF-8 + 11 + 11 + 1.2.24_cloud + 5.8.0-M1 + 1.0.0 + 3.2.1 + 1.18.30 + + + + + + com.testsigma + testsigma-java-sdk + ${testsigma.sdk.version} + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.testng + testng + 6.14.3 + + + + org.seleniumhq.selenium + selenium-java + 4.33.0 + + + + io.appium + java-client + 9.4.0 + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.0 + + + + + swipe_within_element_with_offset + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.plugin.version} + + + attach-sources + + jar + + + + + + + diff --git a/swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java b/swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java new file mode 100644 index 00000000..4c168f80 --- /dev/null +++ b/swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java @@ -0,0 +1,107 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.Element; +import com.testsigma.sdk.annotation.TestData; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import java.util.NoSuchElementException; + +@Action( + actionText = "Swipe direction within the element elementLocator", + description = "Swipes in the given direction within the bounds of the specified element (e.g. TOP TO BOTTOM, TOP TO MIDDLE).", + applicationType = ApplicationType.WEB, + useCustomScreenshot = false +) +public class SwipeWithInElementOffset extends WebAction { + + @TestData(reference = "direction", + allowedValues = { + "TOP TO BOTTOM", "BOTTOM TO TOP", + "TOP TO MIDDLE", "MIDDLE TO TOP", + "MIDDLE TO BOTTOM", "BOTTOM TO MIDDLE", + "LEFT TO RIGHT", "RIGHT TO LEFT", + "LEFT TO MIDDLE", "MIDDLE TO LEFT", + "MIDDLE TO RIGHT", "RIGHT TO MIDDLE" + }) + private com.testsigma.sdk.TestData directionData; + + @Element(reference = "elementLocator") + private com.testsigma.sdk.Element element; + + @Override + public Result execute() throws NoSuchElementException { + + Result result = Result.SUCCESS; + + try { + logger.info("Execution started"); + + WebElement webElement = element.getElement(); + logger.info("Located element: " + element.getBy()); + + String direction = directionData.getValue().toString().trim().toUpperCase(); + String[] parts = direction.split(" TO "); + if (parts.length != 2) { + throw new IllegalArgumentException("Direction must be in format 'X TO Y', e.g. TOP TO BOTTOM. Got: " + direction); + } + String fromPosition = parts[0].trim(); + String toPosition = parts[1].trim(); + + Point startPoint = getPointInElement(webElement, fromPosition); + Point endPoint = getPointInElement(webElement, toPosition); + + Actions actions = new Actions(driver); + actions.moveToLocation(startPoint.getX(), startPoint.getY()) + .clickAndHold() + .moveToLocation(endPoint.getX(), endPoint.getY()) + .release() + .perform(); + + setSuccessMessage("Successfully swiped " + direction + + " within element located by: " + element.getBy()); + + } catch (NoSuchElementException e) { + logger.info("Element not found: " + e.getMessage()); + setErrorMessage("Element not found: " + e.getMessage()); + result = Result.FAILED; + + } catch (Exception e) { + logger.info("Error occurred: " + e.getMessage()); + setErrorMessage("Error: " + e.getMessage()); + result = Result.FAILED; + } + + return result; + } + + + private Point getPointInElement(WebElement element, String position) { + Point location = element.getLocation(); + int elementWidth = element.getSize().getWidth(); + int elementHeight = element.getSize().getHeight(); + int x = location.getX(); + int y = location.getY(); + int inset = 10; + + switch (position) { + case "TOP": + return new Point(x + elementWidth / 2, y + inset); + case "MIDDLE": + return new Point(x + elementWidth / 2, y + elementHeight / 2); + case "BOTTOM": + return new Point(x + elementWidth / 2, y + elementHeight - inset); + case "LEFT": + return new Point(x + inset, y + elementHeight / 2); + case "RIGHT": + return new Point(x + elementWidth - inset, y + elementHeight / 2); + default: + throw new IllegalArgumentException("Invalid position: " + position); + } + } +} diff --git a/swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties b/swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties new file mode 100644 index 00000000..dd1f8c4b --- /dev/null +++ b/swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties @@ -0,0 +1 @@ +testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxM2M5YWYzOS0zMWIwLWM2NDUtMjdhMS0xNDVhMTRjMmFkMTUiLCJ1bmlxdWVJZCI6IjU5NjMiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiYWUwYzE3MDMtNzM4MC1kMjkzLTRiYjQtZDU3Y2ZmNzc1MWM0In0.Y8datKRXZHInIHWmDm9M9rWCZ7HSdRuIxKxW-MkTztarRV_6EFMqYO4yesYW0CGqQZ-HNYiWPvIRmWiVOEGfoA \ No newline at end of file From e812a8918cadda95e8860a2fb9a090f4e6ec9767 Mon Sep 17 00:00:00 2001 From: Akhil Appini Date: Tue, 17 Feb 2026 18:07:31 +0530 Subject: [PATCH 2/2] Made it as public --- .../pom.xml | 6 +++--- .../java/com/testsigma/addons/web/SwipeWithInElement.java | 2 +- .../src/main/resources/testsigma-sdk.properties | 1 + .../src/main/resources/testsigma-sdk.properties | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) rename {swipe_within_element_with_offset => swipe_inside_element_with_direction}/pom.xml (95%) rename swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java => swipe_inside_element_with_direction/src/main/java/com/testsigma/addons/web/SwipeWithInElement.java (98%) create mode 100644 swipe_inside_element_with_direction/src/main/resources/testsigma-sdk.properties delete mode 100644 swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties diff --git a/swipe_within_element_with_offset/pom.xml b/swipe_inside_element_with_direction/pom.xml similarity index 95% rename from swipe_within_element_with_offset/pom.xml rename to swipe_inside_element_with_direction/pom.xml index 920dc02d..83eb9a5c 100644 --- a/swipe_within_element_with_offset/pom.xml +++ b/swipe_inside_element_with_direction/pom.xml @@ -5,8 +5,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.testsigma.addons - swipe_within_element_with_offset - 1.0.5 + swipe_inside_element_with_direction + 1.0.0 jar @@ -64,7 +64,7 @@ - swipe_within_element_with_offset + swipe_inside_element_with_direction org.apache.maven.plugins diff --git a/swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java b/swipe_inside_element_with_direction/src/main/java/com/testsigma/addons/web/SwipeWithInElement.java similarity index 98% rename from swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java rename to swipe_inside_element_with_direction/src/main/java/com/testsigma/addons/web/SwipeWithInElement.java index 4c168f80..102891ef 100644 --- a/swipe_within_element_with_offset/src/main/java/com/testsigma/addons/web/SwipeWithInElementOffset.java +++ b/swipe_inside_element_with_direction/src/main/java/com/testsigma/addons/web/SwipeWithInElement.java @@ -18,7 +18,7 @@ applicationType = ApplicationType.WEB, useCustomScreenshot = false ) -public class SwipeWithInElementOffset extends WebAction { +public class SwipeWithInElement extends WebAction { @TestData(reference = "direction", allowedValues = { diff --git a/swipe_inside_element_with_direction/src/main/resources/testsigma-sdk.properties b/swipe_inside_element_with_direction/src/main/resources/testsigma-sdk.properties new file mode 100644 index 00000000..01b37303 --- /dev/null +++ b/swipe_inside_element_with_direction/src/main/resources/testsigma-sdk.properties @@ -0,0 +1 @@ +testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjU5NjUiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.aJfWmLh21f9jqvpmFI_tT_4w7CaSddCKCtvByJRhPGt9aUPqlEBTfkxwTEkqkEfe7rhQ2dOmsQz2FVSHQLPI1Q \ No newline at end of file diff --git a/swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties b/swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties deleted file mode 100644 index dd1f8c4b..00000000 --- a/swipe_within_element_with_offset/src/main/resources/testsigma-sdk.properties +++ /dev/null @@ -1 +0,0 @@ -testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxM2M5YWYzOS0zMWIwLWM2NDUtMjdhMS0xNDVhMTRjMmFkMTUiLCJ1bmlxdWVJZCI6IjU5NjMiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiYWUwYzE3MDMtNzM4MC1kMjkzLTRiYjQtZDU3Y2ZmNzc1MWM0In0.Y8datKRXZHInIHWmDm9M9rWCZ7HSdRuIxKxW-MkTztarRV_6EFMqYO4yesYW0CGqQZ-HNYiWPvIRmWiVOEGfoA \ No newline at end of file