我有一个有viewpager的应用程序。 我想要这个测试。因此我有一个测试循环:
public class MyActivityTest extends
ActivityInstrumentationTestCase2<MainActivity> {
public void testStartQuestionaryActivity() throws Exception {
Instrumentation.ActivityMonitor monitor =
getInstrumentation().
addMonitor(MainActivity.class.getName(), null, false);
while(notAtEnd()) {
CheckBox checkBox1 = (CheckBox) mActivity.findViewById(com.appical.R.id.checkBox1);
TouchUtils.tapView(this, checkBox1 );
getInstrumentation().invokeMenuActionSync(mActivity, com.appical.R.id.menu_forward, 0);
getInstrumentation().waitForIdleSync();
...
} //while
首次设置复选框有效 - 在进入下一页之前选中复选框。在第2页,我可以看到该对象已更新,但未进行检查。
(Checkbox)((ViewPager) mActivity.findViewById(...)).findViewById(... checkbox)
但没有成功。
谢谢Tata
答案 0 :(得分:0)
好吧归结为:
int current = viewPager.getCurrentItem();
int childCount = viewPager.getChildCount();
// If there's a single page or we're at the beginning, return the first view
if (childCount == 1 || current == 0) {
view = viewPager.getChildAt(0);
} else { //For any other case, we want the second child. This is either the last page or the page in the middle for any other case.
view = viewPager.getChildAt(1);
}