Skip to content

Commit be2b76c

Browse files
committed
Scroll to Element for APK/IPA : Change the behavior : stop scrolling when the element is in the middle of the screen
1 parent 38ca936 commit be2b76c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

source/src/main/java/org/cerberus/core/service/appium/impl/AppiumService.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,16 @@ private boolean scrollDown(TestCaseExecution testCaseExecution, By element, int
447447
do {
448448
boolean isPresent = driver.findElements(element).size() > 0;
449449
if (isPresent && driver.findElement(element).isDisplayed()) {
450-
//Element found, perform another scroll to offset from middle of screen
451-
int pressOffsetX = driver.manage().window().getSize().width / 2;
452-
int pressOffsetY = driver.manage().window().getSize().height / 2;
453-
if (hOffset!=0 && vOffset!=0){
454-
scroll(driver, pressOffsetX, pressOffsetY, pressOffsetX - hOffset, pressOffsetY - vOffset);
455-
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" displayed. Applied the offset ("+hOffset+";"+vOffset+") scrolling from the coord("+pressOffsetX+";"+pressOffsetY+")");
456-
} else {
457-
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" displayed. No offset defined.");
450+
451+
//Element found, perform another scroll to put the element at the middle of the screen at the defined offset.
452+
int distanceFromMiddleOfTheScreen = (driver.manage().window().getSize().height / 2) - driver.findElement(element).getLocation().getY();
453+
454+
if (distanceFromMiddleOfTheScreen > 0) {
455+
scroll(driver, pressX, topY, pressX, topY + distanceFromMiddleOfTheScreen + vOffset);
456+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element " + element + " displayed. Perform another scroll to get it at the middle of the screen after applied the offset (" + hOffset + ";" + vOffset + ") scrolling from coord("+pressX+";"+topY+") to coord("+pressX+";"+topY + distanceFromMiddleOfTheScreen + vOffset+")");
457+
} else if (distanceFromMiddleOfTheScreen < 0 ){
458+
scroll(driver, pressX, bottomY, pressX, bottomY + distanceFromMiddleOfTheScreen + vOffset);
459+
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element " + element + " displayed. Perform another scroll to get it at the middle of the screen after applied the offset (" + hOffset + ";" + vOffset + ") scrolling from coord("+pressX+";"+bottomY+") to coord("+pressX+";"+bottomY + distanceFromMiddleOfTheScreen + vOffset+")");
458460
}
459461

460462
return true;

0 commit comments

Comments
 (0)