I have the following layout in my fragment and activity:
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>