Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions swipe_inside_element_with_direction/pom.xml
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>
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Wrong NoSuchElementException import — Selenium's exception will never be caught by the dedicated handler.

java.util.NoSuchElementException is not the same as org.openqa.selenium.NoSuchElementException. The catch block on line 69 targets the java.util variant, so Selenium's "element not found" exception will bypass it and fall into the generic Exception catch instead, losing the specific error message.

Proposed fix
-import java.util.NoSuchElementException;
+import org.openqa.selenium.NoSuchElementException;
📝 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.

Suggested change
import java.util.NoSuchElementException;
import org.openqa.selenium.NoSuchElementException;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@swipe_inside_element_with_direction/src/main/java/com/testsigma/addons/web/SwipeWithInElement.java`
at line 13, The import of java.util.NoSuchElementException is incorrect for
Selenium handling; update the import to
org.openqa.selenium.NoSuchElementException (and remove the java.util import) so
the catch in SwipeWithInElement that currently intends to handle
element-not-found exceptions will actually catch Selenium's exception type;
ensure any catch blocks referencing NoSuchElementException (in methods like the
swipe/execute logic) remain unchanged so they now reference the Selenium
exception class.


@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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjU5NjUiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.aJfWmLh21f9jqvpmFI_tT_4w7CaSddCKCtvByJRhPGt9aUPqlEBTfkxwTEkqkEfe7rhQ2dOmsQz2FVSHQLPI1Q
Loading