2014-04-04 58 views
0

我有一個有viewpager的應用程序。 我想要這個測試。因此,我有一個測試循環:測試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) 

但沒有成功。

感謝塔塔

回答

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); 
      }