Skip to content

Commit

Permalink
Scroll to Element for APK/IPA : Change the behavior : stop scrolling …
Browse files Browse the repository at this point in the history
…when the element is in the middle of the screen
  • Loading branch information
bcivel committed Jan 22, 2025
1 parent 38ca936 commit be2b76c
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,16 @@ private boolean scrollDown(TestCaseExecution testCaseExecution, By element, int
do {
boolean isPresent = driver.findElements(element).size() > 0;
if (isPresent && driver.findElement(element).isDisplayed()) {
//Element found, perform another scroll to offset from middle of screen
int pressOffsetX = driver.manage().window().getSize().width / 2;
int pressOffsetY = driver.manage().window().getSize().height / 2;
if (hOffset!=0 && vOffset!=0){
scroll(driver, pressOffsetX, pressOffsetY, pressOffsetX - hOffset, pressOffsetY - vOffset);
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" displayed. Applied the offset ("+hOffset+";"+vOffset+") scrolling from the coord("+pressOffsetX+";"+pressOffsetY+")");
} else {
testCaseExecution.addExecutionLog(ExecutionLog.STATUS_INFO, "[Action:ScrollTo] : Element "+element+" displayed. No offset defined.");

//Element found, perform another scroll to put the element at the middle of the screen at the defined offset.
int distanceFromMiddleOfTheScreen = (driver.manage().window().getSize().height / 2) - driver.findElement(element).getLocation().getY();

if (distanceFromMiddleOfTheScreen > 0) {
scroll(driver, pressX, topY, pressX, topY + distanceFromMiddleOfTheScreen + vOffset);
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+")");
} else if (distanceFromMiddleOfTheScreen < 0 ){
scroll(driver, pressX, bottomY, pressX, bottomY + distanceFromMiddleOfTheScreen + vOffset);
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+")");
}

return true;
Expand Down

0 comments on commit be2b76c

Please sign in to comment.