sangmingming / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

waitForText with scroll set to true scrolls only first ListView it finds #151

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a tabbed activity with a ListView in each tab
2. In the second tab in the list, put "needle" at the end of the list
3. call solo.waitForText("needle", 1, 2000, true)

What is the expected output? 
list will scroll down until the match is found

What do you see instead?
list doesn't scroll, and we're stuck in an infinite loop in searchFor (timeout 
is ignored, opened another bug for that)

What version of the product are you using? On what operating system?
Robotium 2.5, Android 2.2 (Cyanogen 6).

Please provide any additional information below.

the reason for that is that the function: 
public boolean scroll(int direction)
gets a list of all ListViews on screen, but scrolls only the first.
It should enter a for loop which scrolls all ListViews on screen.

Original issue reported on code.google.com by gaz...@gmail.com on 6 Sep 2011 at 8:43

GoogleCodeExporter commented 9 years ago
A suggested fixed version of scroll:

public boolean scroll(int direction) {
    final ArrayList<View> viewList = viewFetcher.getViews(null, true);
    final ArrayList<ListView> listViews = RobotiumUtils.filterViews(ListView.class, viewList);

    boolean allFinished = true;
    boolean containsScrollViews = false;

    if (listViews.size() > 0) {
        containsScrollViews = true;
        for (int i = 0; i < listViews.size(); i++) {
            allFinished = allFinished && scrollList(ListView.class, i, direction, listViews);
        }
    } 

    final ArrayList<GridView> gridViews = RobotiumUtils.filterViews(GridView.class, viewList);

    if (gridViews.size() > 0) {
        containsScrollViews = true;
        allFinished = allFinished && scrollList(GridView.class, 0, direction, gridViews);
    } 

    final ArrayList<ScrollView> scrollViews = RobotiumUtils.filterViews(ScrollView.class, viewList);

    if (scrollViews.size() > 0) {
        containsScrollViews = true;
        allFinished = allFinished && scrollScrollView(direction, scrollViews);
    }

    return allFinished && containsScrollViews;
}

This works for me.

Original comment by gaz...@gmail.com on 6 Sep 2011 at 8:58

GoogleCodeExporter commented 9 years ago
Thanks for this. 

Original comment by renasr...@gmail.com on 13 Sep 2011 at 8:28

GoogleCodeExporter commented 9 years ago
This is a design choice. Making Robotium search multiple lists introduces 
issues with list rich applications. One needs to click the correct tab first 
and then use searchText to search that specific list. 

Original comment by renasr...@gmail.com on 14 Nov 2011 at 6:32