-
Notifications
You must be signed in to change notification settings - Fork 15
feat/CUS-10727-Added class to swipe based on directions #338
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
Merged
akhil-testsigma
merged 2 commits into
dev
from
feat/CUS-10727-Added-class-to-swipe-based-on-directions
Feb 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,97 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project | ||
| xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.testsigma.addons</groupId> | ||
| <artifactId>swipe_inside_element_with_direction</artifactId> | ||
| <version>1.0.0</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <maven.compiler.source>11</maven.compiler.source> | ||
| <maven.compiler.target>11</maven.compiler.target> | ||
| <testsigma.sdk.version>1.2.24_cloud</testsigma.sdk.version> | ||
| <junit.jupiter.version>5.8.0-M1</junit.jupiter.version> | ||
| <testsigma.addon.maven.plugin>1.0.0</testsigma.addon.maven.plugin> | ||
| <maven.source.plugin.version>3.2.1</maven.source.plugin.version> | ||
| <lombok.version>1.18.30</lombok.version> | ||
|
|
||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.testsigma</groupId> | ||
| <artifactId>testsigma-java-sdk</artifactId> | ||
| <version>${testsigma.sdk.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>${lombok.version}</version> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <version>${junit.jupiter.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.testng</groupId> | ||
| <artifactId>testng</artifactId> | ||
| <version>6.14.3</version> | ||
| </dependency> | ||
| <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> | ||
| <dependency> | ||
| <groupId>org.seleniumhq.selenium</groupId> | ||
| <artifactId>selenium-java</artifactId> | ||
| <version>4.33.0</version> | ||
| </dependency> | ||
| <!-- https://mvnrepository.com/artifact/io.appium/java-client --> | ||
| <dependency> | ||
| <groupId>io.appium</groupId> | ||
| <artifactId>java-client</artifactId> | ||
| <version>9.4.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-annotations</artifactId> | ||
| <version>2.13.0</version> | ||
| </dependency> | ||
|
|
||
| </dependencies> | ||
| <build> | ||
| <finalName>swipe_inside_element_with_direction</finalName> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-shade-plugin</artifactId> | ||
| <version>3.2.4</version> | ||
| <executions> | ||
| <execution> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>shade</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-source-plugin</artifactId> | ||
| <version>${maven.source.plugin.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-sources</id> | ||
| <goals> | ||
| <goal>jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
107 changes: 107 additions & 0 deletions
107
...ide_element_with_direction/src/main/java/com/testsigma/addons/web/SwipeWithInElement.java
This file contains hidden or 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,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 SwipeWithInElement 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); | ||
| } | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
swipe_inside_element_with_direction/src/main/resources/testsigma-sdk.properties
This file contains hidden or 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 @@ | ||
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjU5NjUiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.aJfWmLh21f9jqvpmFI_tT_4w7CaSddCKCtvByJRhPGt9aUPqlEBTfkxwTEkqkEfe7rhQ2dOmsQz2FVSHQLPI1Q |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wrong
NoSuchElementExceptionimport — Selenium's exception will never be caught by the dedicated handler.java.util.NoSuchElementExceptionis not the same asorg.openqa.selenium.NoSuchElementException. The catch block on line 69 targets thejava.utilvariant, so Selenium's "element not found" exception will bypass it and fall into the genericExceptioncatch instead, losing the specific error message.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents