I am getting some Images from the API and i don't know the number and now i want to test the UI in Android through Appium and i want to scroll down to the Last image. How can I do this and also I don't know the what the title from the API is coming so that I can ScrollTo("Title") and also i am not able to swipe to the last. Is there anyway?
scrollTo(); and driver. ScrollToExact();
There is no way to know for sure whether you've scrolled to the last using appium because there is no UI reporting for the edges of a scrollview.
One way to know that you've reached the end of a scroll view without relying on devs is to compare the list of all children of the scrollview every time you swipe. If all children are exactly the same, you've reached the end. An example xpath for this would look like //android.widget.View[@content-desc="Your scrollview]//*
, which would grab all children and descendants. Once you have a list to compare, check the content of all children nodes. This will only work if there's something unique in these items. If all items are completely general, there will be nothing to compare and this won't be reliable. Ask devs to add content descriptions or accessibility data to the items if possible.
Another option would be to have the devs embed a uniquely id'd invisible view at the top and bottom of the scrollview. That way, if it can be found by the driver, you know that you've reached the very edge of the view. If there are already unique elements at the edges of your scrollview, you can use those.
In the end, the devs of the application can really help out the process of scrolling, but hopefully the trick of comparing the current scrollview's children can help you.
You can use the screen dimensions to scroll down:
public void scrollDown() {
Dimension size = driver.manage().window().getSize();
int x = size.getWidth() / 2;
int starty = (int) (size.getHeight() * 0.60);
int endy = (int) (size.getHeight() * 0.10);
driver.swipe(x, starty, x, endy, 2000);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With