Skip to content

Commit

Permalink
Handle inconsistent detection of elements compared to screen height.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrevarthen committed Mar 14, 2020
1 parent b7c19c8 commit 6aa6254
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.detroitlabs</groupId>
<artifactId>katalon-mobile-util</artifactId>
<version>1.14.0</version>
<version>1.14.1</version>
<packaging>jar</packaging>

<name>katalon-mobile-util</name>
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/com/detroitlabs/katalonmobileutil/touch/Scroll.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,29 @@ private static void scrollEntireList(String xpath, String elementText, ScrollFac
Point from = bottomElement.getLocation();
Point to = topElement.getLocation();

// It is possible that the detected element position is outside of the dimensions of the device
int maxScreenHeight = MobileBuiltInKeywords.getDeviceHeight();
if (from.y >= maxScreenHeight) {
// Start the scroll from the bottom of the screen, allowing for a buffer of the height of the element
from = new Point(from.x, maxScreenHeight - bottomElement.getSize().height);
Logger.debug("The detected element is outside of the device height. Resetting to: " + from.y);
}

// This simulates a swipe action, so releasing at the top of the screen will
// scroll the screen way further than we want. We may need to release the press
// further down the screen. Allowing the tester to set a scrollFactor will give them more control
// over how far the list scrolls.
int endY = from.y - (int)((from.y - to.y) * (double)scrollFactor.factor / 100.0);
Logger.debug("Scrolling from " + from.y + " to " + endY + " using scrollFactor " + scrollFactor);
touchAction.longPress(PointOption.point(from.x, from.y)).moveTo(PointOption.point(to.x, endY)).release().perform();


try {
touchAction.longPress(PointOption.point(from.x, from.y)).moveTo(PointOption.point(to.x, endY)).release().perform();
} catch (Exception ex) {
Logger.debug("Encountered an exception when attempting to scroll: " + ex.getMessage());
Logger.debug("Attempting to Swipe instead.");
Swipe.swipe(Swipe.SwipeDirection.BOTTOM_TO_TOP);
}

// Sometimes need a delay after scrolling before checking for the element
MobileBuiltInKeywords.delay(timeout);

Expand Down

0 comments on commit 6aa6254

Please sign in to comment.