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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.WebAction;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove unused import.

WebAction is imported but not used. This class extends AndroidAction.

-import com.testsigma.sdk.WebAction;
📝 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 com.testsigma.sdk.WebAction;
🤖 Prompt for AI Agents
In
drag_actions/src/main/java/com/testsigma/addons/android/DragElementToReference.java
around line 5, remove the unused import statement for
com.testsigma.sdk.WebAction since this class extends AndroidAction and does not
reference WebAction; simply delete that import to clean up unused imports and
ensure no compile impacts.

import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import io.appium.java_client.android.AndroidDriver;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;


@Action(actionText = "Drag the element element-locator to the reference element reference-element",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class DragElementToReference extends AndroidAction {
@Element(reference = "element-locator")
private com.testsigma.sdk.Element element;
@Element(reference = "reference-element")
private com.testsigma.sdk.Element referenceElement;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("your awesome code starts here");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
try {
WebElement webElement = element.getElement();
AndroidDriver androidDriver = (AndroidDriver) driver;
Actions actions = new Actions(androidDriver);
actions.moveToElement(webElement)
.clickAndHold()
.moveToElement(referenceElement.getElement())
.release().build().perform();

setSuccessMessage("Successfully drag the element to reference element reference-element");
} catch (NoSuchElementException e){
setErrorMessage("Element not found : " + e.getMessage());
logger.info("Element not found : " + ExceptionUtils.getStackTrace(e));
result = com.testsigma.sdk.Result.FAILED;
} catch (Exception e) {
logger.info("Error : " + ExceptionUtils.getStackTrace(e));
setErrorMessage("Error : " + e.getMessage());
result = com.testsigma.sdk.Result.FAILED;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.testsigma.addons.android;


import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.WebAction;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove unused import.

WebAction is imported but not used. This class extends AndroidAction.

-import com.testsigma.sdk.WebAction;
📝 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 com.testsigma.sdk.WebAction;
🤖 Prompt for AI Agents
In
drag_actions/src/main/java/com/testsigma/addons/android/MoveElementRelativeToReference.java
around line 6, the import statement for com.testsigma.sdk.WebAction is unused
(this class extends AndroidAction); remove that import line and
reformat/organize the remaining imports to avoid unused-import warnings.

import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import com.testsigma.sdk.annotation.TestData;
import io.appium.java_client.android.AndroidDriver;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.MoveTargetOutOfBoundsException;

@Action(actionText = "Drag element elementLocator to the relativePosition of the referenceElement with " +
"offset x: xOffset , y: yOffset",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class MoveElementRelativeToReference extends AndroidAction {

@Element(reference = "elementLocator")
private com.testsigma.sdk.Element targetElement;

@Element(reference = "referenceElement")
private com.testsigma.sdk.Element referenceElement;

@TestData(reference = "xOffset")
private com.testsigma.sdk.TestData xOffsetData;

@TestData(reference = "yOffset")
private com.testsigma.sdk.TestData yOffsetData;

@TestData(reference = "relativePosition", allowedValues = {"right", "left", "top", "bottom","center"})
private com.testsigma.sdk.TestData relativePositionData;

@Override
public com.testsigma.sdk.Result execute() {
logger.info("Execution started");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;

int xOffset = Integer.parseInt(xOffsetData.getValue().toString());
int yOffset = Integer.parseInt(yOffsetData.getValue().toString());
logger.info("xOffset: " + xOffset + " yOffset: " + yOffset);
String relativePosition = relativePositionData.getValue().toString().toLowerCase();
logger.info("relativePosition: " + relativePosition);
int targetXOffset=-1; //initializing values so that we can use in error message
int targetYOffset=-1;
try {
WebElement referenceWebElement = referenceElement.getElement();
WebElement targetWebElement = targetElement.getElement();

targetXOffset = calculateXOffset(referenceWebElement, relativePosition, xOffset);
targetYOffset = calculateYOffset(referenceWebElement, relativePosition, yOffset);
logger.info("Target X Offset: " + targetXOffset + " Target Y Offset: " + targetYOffset);

AndroidDriver androidDriver = (AndroidDriver) driver;
Actions actions = new Actions(androidDriver);
actions.moveToElement(targetWebElement)
.clickAndHold()
.moveToLocation(targetXOffset, targetYOffset)
.release().build().perform();
logger.info("Moved element");
setSuccessMessage("Moved element to the " + relativePosition + " of the reference element");
} catch (NoSuchElementException e) {
setErrorMessage("Element not found: " + e.getMessage());
logger.info(ExceptionUtils.getStackTrace(e));
result = com.testsigma.sdk.Result.FAILED;
} catch (MoveTargetOutOfBoundsException e) {
setErrorMessage("Target location" + targetXOffset +"," + targetYOffset +"is out of bounds: " + e.getMessage());
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing space in error message.

Same formatting issue as the mobileWeb version.

-            setErrorMessage("Target location" + targetXOffset +"," + targetYOffset +"is out of bounds: " + e.getMessage());
+            setErrorMessage("Target location " + targetXOffset + "," + targetYOffset + " is out of bounds: " + e.getMessage());
📝 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
setErrorMessage("Target location" + targetXOffset +"," + targetYOffset +"is out of bounds: " + e.getMessage());
setErrorMessage("Target location " + targetXOffset + "," + targetYOffset + " is out of bounds: " + e.getMessage());
🤖 Prompt for AI Agents
In
drag_actions/src/main/java/com/testsigma/addons/android/MoveElementRelativeToReference.java
around line 71, the error message concatenation lacks spaces resulting in
"Target location10,20is out of bounds..."; update the string concatenation to
include spaces and a comma: build the message as "Target location " +
targetXOffset + ", " + targetYOffset + " is out of bounds: " + e.getMessage() so
spacing matches the mobileWeb version and the message reads correctly.

logger.info(ExceptionUtils.getStackTrace(e));
result = com.testsigma.sdk.Result.FAILED;
} catch (Exception e) {
setErrorMessage(e.getMessage());
logger.info(ExceptionUtils.getStackTrace(e));
result = com.testsigma.sdk.Result.FAILED;
}
return result;
}
private int calculateXOffset(WebElement referenceElement, String relativePosition, int xOffset) {
int referenceX = referenceElement.getLocation().getX();
int referenceWidth = referenceElement.getSize().getWidth();
logger.info("referenceX: " + referenceX + " referenceWidth: " + referenceWidth);
switch (relativePosition) {
case "center":
return referenceX + referenceWidth / 2 + xOffset;
case "right":
return referenceX + referenceWidth + xOffset;
case "left":
return referenceX - xOffset;
default:
return referenceX + xOffset; // Default for "top" and "bottom"
}
}

private int calculateYOffset(WebElement referenceElement, String relativePosition, int yOffset) {
int referenceY = referenceElement.getLocation().getY();
int referenceHeight = referenceElement.getSize().getHeight();
logger.info("referenceY: " + referenceY + " referenceHeight: " + referenceHeight);
switch (relativePosition) {
case "center":
return referenceY + referenceHeight / 2 + yOffset;
case "bottom":
return referenceY + referenceHeight + yOffset;
case "top":
return referenceY - yOffset;
default:
return referenceY + yOffset; // Default for "right" and "left"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.testsigma.addons.android;


import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import com.testsigma.sdk.annotation.TestData;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.util.NoSuchElementException;

@Action(actionText = "Swipe from direction1 to direction2 within the element elementLocator",
description = "Swipes from the given direction within the bounds of the specified element.",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class SwipeWithInElement extends AndroidAction {
@TestData(reference = "direction1", allowedValues = {"up", "down", "left", "right"})
private com.testsigma.sdk.TestData direction1Data;
@TestData(reference = "direction2", allowedValues = {"up", "down", "left", "right"})
private com.testsigma.sdk.TestData direction2Data;

@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().toString());
String firstDirection = direction1Data.getValue().toString().toLowerCase();
String secondDirection = direction2Data.getValue().toString().toLowerCase();
AndroidDriver androidDriver = (AndroidDriver) driver;

Point startLocation = getPointInElement(webElement, firstDirection);
Point endLocation = getPointInElement(webElement, secondDirection);
logger.info("Swiping from " + firstDirection + " to " + secondDirection +
" within element located by: " + element.getBy().toString());
Actions actions = new Actions(androidDriver);
actions.moveToLocation(startLocation.getX(), startLocation.getY())
.clickAndHold()
.moveToLocation(endLocation.getX(), endLocation.getY())
.release()
.perform();
setSuccessMessage("Successfully swiped from " + firstDirection + " to " + secondDirection +
" within the element located by: " + element.getBy().toString());
} catch (NoSuchElementException e) {
setErrorMessage("Element not found : " + e.getMessage());
logger.info("Element not found : " + e.getMessage());
result = Result.FAILED;
} catch (Exception e) {
logger.info("Error : " + e.getMessage());
setErrorMessage("Error : " + e.getMessage());
result = Result.FAILED;
}

return result;
}

private Point getPointInElement(WebElement element, String direction) {
Point location = element.getLocation();
int elementWidth = element.getSize().getWidth();
int elementHeight = element.getSize().getHeight();
int x = location.getX();
int y = location.getY();

switch (direction) {
case "up":
return new Point(x + elementWidth / 2, y + 10);
case "down":
return new Point(x + elementWidth / 2, y + elementHeight - 10);
case "left":
return new Point(x + 10, y + elementHeight / 2);
case "right":
return new Point(x + elementWidth - 10, y + elementHeight / 2);
default:
throw new IllegalArgumentException("Invalid direction: " + direction);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.testsigma.addons.ios;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.IOSAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.Element;
import io.appium.java_client.android.AndroidDriver;
Comment on lines +3 to +8
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove unused Android imports from iOS class.

The file imports AndroidAction (line 3) and AndroidDriver (line 8), which are not used in this iOS-specific action class. These appear to be copy-paste artifacts from an Android implementation.

Apply this diff to remove the unused imports:

-import com.testsigma.sdk.AndroidAction;
 import com.testsigma.sdk.ApplicationType;
 import com.testsigma.sdk.IOSAction;
 import com.testsigma.sdk.annotation.Action;
 import com.testsigma.sdk.annotation.Element;
-import io.appium.java_client.android.AndroidDriver;
 import io.appium.java_client.ios.IOSDriver;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
drag_actions/src/main/java/com/testsigma/addons/ios/DragElementToReference.java
around lines 3 to 8, remove the unused Android-specific imports (import
com.testsigma.sdk.AndroidAction; and import
io.appium.java_client.android.AndroidDriver;) which are copy-paste artifacts;
keep only the iOS-relevant imports (e.g., IOSAction, ApplicationType, annotation
imports) so the class compiles without unused import warnings.

import io.appium.java_client.ios.IOSDriver;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;


@Action(actionText = "Drag the element element-locator to the reference element reference-element",
applicationType = ApplicationType.IOS,
useCustomScreenshot = false)
public class DragElementToReference extends IOSAction {
@Element(reference = "element-locator")
private com.testsigma.sdk.Element element;
@Element(reference = "reference-element")
private com.testsigma.sdk.Element referenceElement;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("your awesome code starts here");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
try {
WebElement webElement = element.getElement();
IOSDriver iosDriver = (IOSDriver) driver;
Actions actions = new Actions(iosDriver);
actions.moveToElement(webElement)
.clickAndHold()
.moveToElement(referenceElement.getElement())
.release().build().perform();

setSuccessMessage("Successfully drag the element to reference element reference-element");
} catch (NoSuchElementException e){
setErrorMessage("Element not found : " + e.getMessage());
logger.info("Element not found : " + ExceptionUtils.getStackTrace(e));
result = com.testsigma.sdk.Result.FAILED;
} catch (Exception e) {
logger.info("Error : " + ExceptionUtils.getStackTrace(e));
setErrorMessage("Error : " + e.getMessage());
result = com.testsigma.sdk.Result.FAILED;
}
return result;
}
}
Loading
Loading