我的片段和活动中有以下布局:
如您所见,Robotium填写EditText
视图的文本。它还会滚动并填写“玩家名称”后面的“团队”字段。但是,之后有一个Spinner
,textView
中有适当的标签,solo.searchForText()
不会向下滚动以将其置于视图中。这是因为拆分动作栏吗?在测试中,我该怎么做才能解决这个问题?
尝试访问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);
表单片段的XML布局:
<?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>
答案 0 :(得分:0)
显然,Robotium会找到广告,而不是ScrollView。 Robotium不知道如何处理它而只是忽略它而不是造成任何错误。
我最终编写了自己的函数来进行滚动:
public static void scrollDown(final ScrollView scrollView) {
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.arrowScroll(ScrollView.FOCUS_DOWN);
}
});
}
答案 1 :(得分:0)
你试过了吗?
solo.pressSpinnerItem(0, 1);
第一个参数是要使用的微调器的索引,第二个参数是微调器中要选择的项。