Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Swipe and Scroll to the Last in Appium

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?

like image 807
FiXiT Avatar asked Feb 23 '16 09:02

FiXiT


People also ask

How do you scroll to the end of the page in Appium?

scrollTo(); and driver. ScrollToExact();


2 Answers

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.

like image 151
George Pantazes Avatar answered Oct 02 '22 23:10

George Pantazes


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);
}
like image 44
Gaurav Avatar answered Oct 03 '22 00:10

Gaurav