From b5faa32c1789aabf0d585862d69e6dfa0b6622f5 Mon Sep 17 00:00:00 2001 From: Sunil Gembali Date: Fri, 8 Mar 2024 10:14:59 +0530 Subject: [PATCH 1/2] Feat[17157]: Image Actions to support the right click, left click, double right click, double left click action and corrected the android nlps margin value --- .../addons/android/ClickOnImage.java | 2 +- .../android/ClickOnImageOccurrenceBased.java | 2 +- .../android/ClickOnImageWithThreshold.java | 2 +- ...ckOnImageWithThresholdOccurrenceBased.java | 2 +- .../testsigma/addons/android/ClickOnText.java | 2 +- .../android/ClickOnTextOccurrenceBased.java | 2 +- .../addons/web/DoubleClickOnText.java | 85 +++++++++++++++++++ .../addons/web/DoubleRightClickOnText.java | 85 +++++++++++++++++++ .../addons/web/RightClickOnText.java | 85 +++++++++++++++++++ 9 files changed, 261 insertions(+), 6 deletions(-) create mode 100644 image_based_actions/src/main/java/com/testsigma/addons/web/DoubleClickOnText.java create mode 100644 image_based_actions/src/main/java/com/testsigma/addons/web/DoubleRightClickOnText.java create mode 100644 image_based_actions/src/main/java/com/testsigma/addons/web/RightClickOnText.java diff --git a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImage.java b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImage.java index 9c90534b..e37e43d2 100644 --- a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImage.java +++ b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImage.java @@ -76,7 +76,7 @@ protected Result execute() throws NoSuchElementException { logger.info("Error ratios: x relative: "+xRelative+" y relative: "+yRelative); int clickLocationX; int clickLocationY; - if (Math.abs(imageWidth-screenWidth) > 5) { + if (Math.abs(imageWidth-screenWidth) > 20) { clickLocationX = (int) (xRelative * screenWidth); clickLocationY = (int) (yRelative * screenHeight); } else { diff --git a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageOccurrenceBased.java b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageOccurrenceBased.java index 2d3253e8..852b80fd 100644 --- a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageOccurrenceBased.java +++ b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageOccurrenceBased.java @@ -79,7 +79,7 @@ protected Result execute() throws NoSuchElementException { logger.info("Error ratios: x relative: "+xRelative+" y relative: "+yRelative); int clickLocationX; int clickLocationY; - if(Math.abs(imageWidth-screenWidth) > 5){ + if(Math.abs(imageWidth-screenWidth) > 20){ clickLocationX = (int) (xRelative * screenWidth); clickLocationY = (int) (yRelative * screenHeight); } else { diff --git a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThreshold.java b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThreshold.java index 22ddb596..df759eb8 100644 --- a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThreshold.java +++ b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThreshold.java @@ -79,7 +79,7 @@ protected Result execute() throws NoSuchElementException { logger.info("Error ratios: x relative: "+xRelative+" y relative: "+yRelative); int clickLocationX; int clickLocationY; - if(Math.abs(imageWidth-screenWidth) > 5){ + if(Math.abs(imageWidth-screenWidth) > 20){ clickLocationX = (int) (xRelative * screenWidth); clickLocationY = (int) (yRelative * screenHeight); } else { diff --git a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThresholdOccurrenceBased.java b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThresholdOccurrenceBased.java index 213a91b1..4a2dd23d 100644 --- a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThresholdOccurrenceBased.java +++ b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnImageWithThresholdOccurrenceBased.java @@ -84,7 +84,7 @@ protected Result execute() throws NoSuchElementException { logger.info("Error ratios: x relative: "+xRelative+" y relative: "+yRelative); int clickLocationX; int clickLocationY; - if(Math.abs(imageWidth-screenWidth) > 5){ + if(Math.abs(imageWidth-screenWidth) > 20){ clickLocationX = (int) (xRelative * screenWidth); clickLocationY = (int) (yRelative * screenHeight); } else { diff --git a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnText.java b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnText.java index f9034d56..4ccebb4f 100644 --- a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnText.java +++ b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnText.java @@ -75,7 +75,7 @@ protected Result execute() { logger.info("Error ratios: x relative: "+xRelative+" y relative: "+yRelative); int clickLocationX; int clickLocationY; - if(Math.abs(imageWidth-screenWidth) > 5){ + if(Math.abs(imageWidth-screenWidth) > 20){ clickLocationX = (int) (xRelative * screenWidth); clickLocationY = (int) (yRelative * screenHeight); } else { diff --git a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnTextOccurrenceBased.java b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnTextOccurrenceBased.java index beaeaf58..6b977003 100644 --- a/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnTextOccurrenceBased.java +++ b/image_based_actions/src/main/java/com/testsigma/addons/android/ClickOnTextOccurrenceBased.java @@ -79,7 +79,7 @@ protected Result execute() { logger.info("Error ratios: x relative: "+xRelative+" y relative: "+yRelative); int clickLocationX; int clickLocationY; - if(Math.abs(imageWidth-screenWidth) > 5){ + if(Math.abs(imageWidth-screenWidth) > 20){ clickLocationX = (int) (xRelative * screenWidth); clickLocationY = (int) (yRelative * screenHeight); } else { diff --git a/image_based_actions/src/main/java/com/testsigma/addons/web/DoubleClickOnText.java b/image_based_actions/src/main/java/com/testsigma/addons/web/DoubleClickOnText.java new file mode 100644 index 00000000..10f94027 --- /dev/null +++ b/image_based_actions/src/main/java/com/testsigma/addons/web/DoubleClickOnText.java @@ -0,0 +1,85 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.OCRTextPoint; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.OCR; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.interactions.Actions; + +import java.util.List; + +@Data +@Action(actionText = "Double click on text name", + description = "Double click on the text using the text coordinates", + applicationType = ApplicationType.WEB) + +public class DoubleClickOnText extends WebAction { + @OCR + private com.testsigma.sdk.OCR ocr; + + @TestData(reference = "name") + private com.testsigma.sdk.TestData text; + + @Override + protected Result execute() { + Result result = Result.SUCCESS; + List textPoints = ocr.extractTextFromPage(); + printAllCoordinates(textPoints); + OCRTextPoint textPoint = getTextPointFromText(textPoints); + if(textPoint == null) { + result = Result.FAILED; + setErrorMessage("Given text is not found"); + + } else { + logger.info("Found Textpoint with text = " + textPoint.getText() + ", x1 = " + textPoint.getX1() + + ", y1 = " + textPoint.getY1() + ", x2 = " + textPoint.getX2() + ", y2 = " + textPoint.getY2()); + clickOnCoordinates(textPoint); + setSuccessMessage("Click operation performed on the text " + + " Text coordinates :" + "x1-" + textPoint.getX1() + ", x2-" + textPoint.getX2() + ", y1-" + textPoint.getY1() + ", y2-" + textPoint.getY2()); + } + + return result; + } + private OCRTextPoint getTextPointFromText(List textPoints) { + if(textPoints == null) { + return null; + } + for(OCRTextPoint textPoint: textPoints) { + if(text.getValue().equals(textPoint.getText())) { + return textPoint; + + } + } + return null; + } + + private void printAllCoordinates(List textPoints) { + for(OCRTextPoint textPoint: textPoints) { + logger.info("text =" + textPoint.getText() + "x1 = " + textPoint.getX1() + ", y1 =" + textPoint.getY1() + ", x2 = " + textPoint.getX2() + ", y2 =" + textPoint.getY2() +"\n\n\n\n"); + } + } + public void clickOnCoordinates(OCRTextPoint textPoint) { + + int x1 = textPoint.getX1(); + int y1 = textPoint.getY1(); + int x2 = textPoint.getX2(); + int y2 = textPoint.getY2(); + +// int x = (x1 + x2) / 2; +// int y = (y1 + y2) / 2; + int x = x2; + int y = y2; + + logger.info("MEAN X coordinate: " + x + "\n"); + logger.info("MEAN Y coordinate: " + y + "\n"); + + Actions actions = new Actions(driver); + actions.moveToLocation(x, y).doubleClick().build().perform(); + } + + +} diff --git a/image_based_actions/src/main/java/com/testsigma/addons/web/DoubleRightClickOnText.java b/image_based_actions/src/main/java/com/testsigma/addons/web/DoubleRightClickOnText.java new file mode 100644 index 00000000..66dbe7c6 --- /dev/null +++ b/image_based_actions/src/main/java/com/testsigma/addons/web/DoubleRightClickOnText.java @@ -0,0 +1,85 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.OCRTextPoint; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.OCR; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.interactions.Actions; + +import java.util.List; + +@Data +@Action(actionText = "Double right click on text name", + description = "Double right click on the text using the text coordinates", + applicationType = ApplicationType.WEB) + +public class DoubleRightClickOnText extends WebAction { + @OCR + private com.testsigma.sdk.OCR ocr; + + @TestData(reference = "name") + private com.testsigma.sdk.TestData text; + + @Override + protected Result execute() { + Result result = Result.SUCCESS; + List textPoints = ocr.extractTextFromPage(); + printAllCoordinates(textPoints); + OCRTextPoint textPoint = getTextPointFromText(textPoints); + if(textPoint == null) { + result = Result.FAILED; + setErrorMessage("Given text is not found"); + + } else { + logger.info("Found Textpoint with text = " + textPoint.getText() + ", x1 = " + textPoint.getX1() + + ", y1 = " + textPoint.getY1() + ", x2 = " + textPoint.getX2() + ", y2 = " + textPoint.getY2()); + clickOnCoordinates(textPoint); + setSuccessMessage("Click operation performed on the text " + + " Text coordinates :" + "x1-" + textPoint.getX1() + ", x2-" + textPoint.getX2() + ", y1-" + textPoint.getY1() + ", y2-" + textPoint.getY2()); + } + + return result; + } + private OCRTextPoint getTextPointFromText(List textPoints) { + if(textPoints == null) { + return null; + } + for(OCRTextPoint textPoint: textPoints) { + if(text.getValue().equals(textPoint.getText())) { + return textPoint; + + } + } + return null; + } + + private void printAllCoordinates(List textPoints) { + for(OCRTextPoint textPoint: textPoints) { + logger.info("text =" + textPoint.getText() + "x1 = " + textPoint.getX1() + ", y1 =" + textPoint.getY1() + ", x2 = " + textPoint.getX2() + ", y2 =" + textPoint.getY2() +"\n\n\n\n"); + } + } + public void clickOnCoordinates(OCRTextPoint textPoint) { + + int x1 = textPoint.getX1(); + int y1 = textPoint.getY1(); + int x2 = textPoint.getX2(); + int y2 = textPoint.getY2(); + +// int x = (x1 + x2) / 2; +// int y = (y1 + y2) / 2; + int x = x2; + int y = y2; + + logger.info("MEAN X coordinate: " + x + "\n"); + logger.info("MEAN Y coordinate: " + y + "\n"); + + Actions actions = new Actions(driver); + actions.moveToLocation(x, y).contextClick().pause(100).contextClick().build().perform(); + } + + +} diff --git a/image_based_actions/src/main/java/com/testsigma/addons/web/RightClickOnText.java b/image_based_actions/src/main/java/com/testsigma/addons/web/RightClickOnText.java new file mode 100644 index 00000000..c83f72e3 --- /dev/null +++ b/image_based_actions/src/main/java/com/testsigma/addons/web/RightClickOnText.java @@ -0,0 +1,85 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.OCRTextPoint; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.OCR; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.interactions.Actions; + +import java.util.List; + +@Data +@Action(actionText = "Right click on text name", + description = "Right click on the text using the text coordinates", + applicationType = ApplicationType.WEB) + +public class RightClickOnText extends WebAction { + @OCR + private com.testsigma.sdk.OCR ocr; + + @TestData(reference = "name") + private com.testsigma.sdk.TestData text; + + @Override + protected Result execute() { + Result result = Result.SUCCESS; + List textPoints = ocr.extractTextFromPage(); + printAllCoordinates(textPoints); + OCRTextPoint textPoint = getTextPointFromText(textPoints); + if(textPoint == null) { + result = Result.FAILED; + setErrorMessage("Given text is not found"); + + } else { + logger.info("Found Textpoint with text = " + textPoint.getText() + ", x1 = " + textPoint.getX1() + + ", y1 = " + textPoint.getY1() + ", x2 = " + textPoint.getX2() + ", y2 = " + textPoint.getY2()); + clickOnCoordinates(textPoint); + setSuccessMessage("Click operation performed on the text " + + " Text coordinates :" + "x1-" + textPoint.getX1() + ", x2-" + textPoint.getX2() + ", y1-" + textPoint.getY1() + ", y2-" + textPoint.getY2()); + } + + return result; + } + private OCRTextPoint getTextPointFromText(List textPoints) { + if(textPoints == null) { + return null; + } + for(OCRTextPoint textPoint: textPoints) { + if(text.getValue().equals(textPoint.getText())) { + return textPoint; + + } + } + return null; + } + + private void printAllCoordinates(List textPoints) { + for(OCRTextPoint textPoint: textPoints) { + logger.info("text =" + textPoint.getText() + "x1 = " + textPoint.getX1() + ", y1 =" + textPoint.getY1() + ", x2 = " + textPoint.getX2() + ", y2 =" + textPoint.getY2() +"\n\n\n\n"); + } + } + public void clickOnCoordinates(OCRTextPoint textPoint) { + + int x1 = textPoint.getX1(); + int y1 = textPoint.getY1(); + int x2 = textPoint.getX2(); + int y2 = textPoint.getY2(); + +// int x = (x1 + x2) / 2; +// int y = (y1 + y2) / 2; + int x = x2; + int y = y2; + + logger.info("MEAN X coordinate: " + x + "\n"); + logger.info("MEAN Y coordinate: " + y + "\n"); + + Actions actions = new Actions(driver); + actions.moveToLocation(x, y).contextClick().build().perform(); + } + + +} From 57e4a46ef8444db932e59086bdabaeac1ff0fb5b Mon Sep 17 00:00:00 2001 From: Sunil Gembali Date: Fri, 8 Mar 2024 10:17:04 +0530 Subject: [PATCH 2/2] Feat[TE-17157]: Changed the pom xml version. --- image_based_actions/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image_based_actions/pom.xml b/image_based_actions/pom.xml index 177744db..ec7648d1 100644 --- a/image_based_actions/pom.xml +++ b/image_based_actions/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.testsigma.addons image_based_actions - 1.0.3 + 1.0.4 jar