-
Notifications
You must be signed in to change notification settings - Fork 16
[CUS-9590] added action to swipe from left to right etc.. in element. #278
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| 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; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Remove unused import.
-import com.testsigma.sdk.WebAction;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| 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()); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused Android imports from iOS class. The file imports 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;
🤖 Prompt for AI Agents |
||
| 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; | ||
| } | ||
| } | ||
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
Remove unused import.
WebActionis imported but not used. This class extendsAndroidAction.-import com.testsigma.sdk.WebAction;📝 Committable suggestion
🤖 Prompt for AI Agents