Skip to content

Commit

Permalink
Feat/TE-17157: Image Actions to support the right click, left click, …
Browse files Browse the repository at this point in the history
…double right click, double left click action and corrected the android nlps margin value (#51)

* 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

* Feat[TE-17157]: Changed the pom xml version.
  • Loading branch information
SunilGembali authored Mar 11, 2024
1 parent 56f9606 commit 13cc99e
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 7 deletions.
2 changes: 1 addition & 1 deletion image_based_actions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testsigma.addons</groupId>
<artifactId>image_based_actions</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OCRTextPoint> 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<OCRTextPoint> textPoints) {
if(textPoints == null) {
return null;
}
for(OCRTextPoint textPoint: textPoints) {
if(text.getValue().equals(textPoint.getText())) {
return textPoint;

}
}
return null;
}

private void printAllCoordinates(List<OCRTextPoint> 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();
}


}
Original file line number Diff line number Diff line change
@@ -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<OCRTextPoint> 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<OCRTextPoint> textPoints) {
if(textPoints == null) {
return null;
}
for(OCRTextPoint textPoint: textPoints) {
if(text.getValue().equals(textPoint.getText())) {
return textPoint;

}
}
return null;
}

private void printAllCoordinates(List<OCRTextPoint> 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();
}


}
Original file line number Diff line number Diff line change
@@ -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<OCRTextPoint> 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<OCRTextPoint> textPoints) {
if(textPoints == null) {
return null;
}
for(OCRTextPoint textPoint: textPoints) {
if(text.getValue().equals(textPoint.getText())) {
return textPoint;

}
}
return null;
}

private void printAllCoordinates(List<OCRTextPoint> 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();
}


}

0 comments on commit 13cc99e

Please sign in to comment.