-1

I have the following layout in my fragment and activity:

enter image description here

As you can see, Robotium fills in the text for the EditText views. It also scrolls to and fills in the "Team" field which follows the "Player Name". However, there is a Spinner after that, with an appropriate label in a textView, and solo.searchForText() doesn't scroll down to put it into view. Is this because of the split Action Bar? What can I do to remedy this problem in my tests?

The relevant code that attempts to access the Spinner:

        Spinner playerPositionSpinner = (Spinner) solo.getView(R.id.player_position_text);
        @SuppressWarnings("unchecked")
        ArrayAdapter<CharSequence> playerPositionAdapter = (ArrayAdapter<CharSequence>) playerPositionSpinner
                .getAdapter();
        int newIndex = playerPositionAdapter.getPosition(card
                .getPlayerPosition());
        int currIndex = playerPositionSpinner.getSelectedItemPosition();

        boolean isPositionVisible = solo.searchText(
                solo.getString(R.string.player_position_label), true);
        solo.waitForView(R.id.player_position_text);

        boolean isConditionVisible = solo.searchText(solo.getString(R.string.condition_label),
                false);
        int index = -1;
        if (!isConditionVisible && isPositionVisible) {
            index = 0;
        }
        if (isPositionVisible && isConditionVisible) {
            index = 1;
        }

        Assert.assertFalse("Invalid index", index == -1);
        solo.pressSpinnerItem(index, newIndex - currIndex);

The XML layout for the form fragment:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/scroll_card_details"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1" >

        <TableRow>

            <CheckBox
                android:id="@id/autograph"
                android:text="@string/autograph_label"
                android:layout_span="2" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/condition_label"
                android:textStyle="bold" />

            <Spinner
                android:id="@id/condition"
                android:hint="@string/condition_hint"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/brand_label"
                android:textStyle="bold" />

            <AutoCompleteTextView
                android:id="@id/brand_text"
                android:completionThreshold="1"
                android:hint="@string/brand_hint"
                android:inputType="textCapWords"
                android:selectAllOnFocus="true"
                android:singleLine="true" >

                <requestFocus />
            </AutoCompleteTextView>
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/year_label"
                android:textStyle="bold" />

            <EditText
                android:id="@id/year_text"
                android:hint="@string/year_hint"
                android:inputType="number"
                android:selectAllOnFocus="true"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/number_label"
                android:textStyle="bold" />

            <EditText
                android:id="@id/number_text"
                android:hint="@string/number_hint"
                android:inputType="number"
                android:selectAllOnFocus="true"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/value_label"
                android:textStyle="bold" />

            <EditText
                android:id="@id/value_text"
                android:hint="@string/value_hint"
                android:inputType="numberDecimal"
                android:selectAllOnFocus="true"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/count_label"
                android:textStyle="bold" />

            <EditText
                android:id="@id/count_text"
                android:hint="@string/count_hint"
                android:inputType="number"
                android:selectAllOnFocus="true"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/player_name_label"
                android:textStyle="bold" />

            <AutoCompleteTextView
                android:id="@id/player_name_text"
                android:completionThreshold="1"
                android:hint="@string/player_name_hint"
                android:inputType="textCapWords"
                android:selectAllOnFocus="true"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/team_label"
                android:textStyle="bold" />

            <AutoCompleteTextView
                android:id="@id/team_text"
                android:completionThreshold="1"
                android:hint="@string/team_hint"
                android:inputType="textCapWords"
                android:selectAllOnFocus="true"
                android:singleLine="true" />
        </TableRow>

        <TableRow>

            <TextView
                android:text="@string/player_position_label"
                android:textStyle="bold" />

            <Spinner
                android:id="@id/player_position_text"
                android:hint="@string/player_position_hint"
                android:singleLine="true" />
        </TableRow>

    </TableLayout>

</ScrollView>
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

2 Answers2

0

Apparently Robotium finds the Ad, instead of the ScrollView. Robotium doesn't know how to deal with it and just ignores it instead of causing any error.

I ending up writing my own function to do the scrolling:

public static void scrollDown(final ScrollView scrollView) {
    scrollView.post(new Runnable() {
        @Override
        public void run() {
            scrollView.arrowScroll(ScrollView.FOCUS_DOWN);
        }
    });
}
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
0

Have you tried:

solo.pressSpinnerItem(0, 1);

The first parameter is the index of the spinner to use and the second parameter is the item in the spinner to select.

psionicNinja
  • 111
  • 3
  • A static index doesn't work because I want my test to be flexible for many screen sizes. On larger screens, there may two visible spinners. – Code-Apprentice Jul 08 '14 at 21:51
  • On smaller screens, the spinner I want to click on may be hidden. When I do `pressSpinnerItem(1, x)`, I get "Two Spinners not found!" – Code-Apprentice Jul 08 '14 at 22:08