robotium3.6与4.0以后的区别

本文介绍了Robotium自动化测试库在3.6版本和4.0及以后版本的区别,主要关注于`getCurrentViews()`方法的变化。在4.0版本中,虽然方法数量减少,但通过传入特定类参数,如`ImageView.class`,依然能实现类似3.6版本的功能,如获取当前屏幕上的ImageView列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        因为下载的直接是最新版本的robotium4.1版,这次碰到gridView问题时,发现网上有getCurrentListViews() 、getCurrentImageViews()等方法。而自己却没有,纳闷了,下载查看了下3.6版本,果然有。

3.6版本中的方法:

 ArrayList<android.widget.Button>getCurrentButtons() 
          Returns an ArrayList of the Button objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.CheckBox>getCurrentCheckBoxes() 
          Returns an ArrayList of the CheckBox objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.DatePicker>getCurrentDatePickers() 
          Returns an ArrayList of the DatePicker objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.EditText>getCurrentEditTexts() 
          Returns an ArrayList of the EditText objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.GridView>getCurrentGridViews() 
          Returns an ArrayList of the GridView objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ImageButton>getCurrentImageButtons() 
          Returns an ArrayList of the ImageButton objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ImageView>getCurrentImageViews() 
          Returns an ArrayList of the ImageView objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ImageView>getCurrentImageViews(android.view.View parent) 
          Returns an ArrayList of the ImageView objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ListView>getCurrentListViews() 
          Returns an ArrayList of the ListView objects currently shown in the focused Activity or Dialog.
<T extends android.widget.LinearLayout> 
ArrayList<T>
getCurrentNumberPickers() 
          Returns an ArrayList of the NumberPicker objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ProgressBar>getCurrentProgressBars() 
          Returns an ArrayList of the ProgressBar objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.RadioButton>getCurrentRadioButtons() 
          Returns an ArrayList of the RadioButton objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ScrollView>getCurrentScrollViews() 
          Returns an ArrayList of the ScrollView objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.SlidingDrawer>getCurrentSlidingDrawers() 
          Returns an ArrayList of the SlidingDrawer objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.Spinner>getCurrentSpinners() 
          Returns an ArrayList of the Spinner objects (drop-down menus) currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.TextView>getCurrentTextViews(android.view.View parent) 
          Returns an ArrayList of the TextView objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.TimePicker>getCurrentTimePickers() 
          Returns an ArrayList of the TimePicker objects currently shown in the focused Activity or Dialog.
 ArrayList<android.widget.ToggleButton>getCurrentToggleButtons() 
          Returns an ArrayList of the ToggleButton objects currently shown in the focused Activity or Dialog.
 ArrayList<android.view.View>getCurrentViews() 
          Returns an ArrayList of the View objects currently shown in the focused Activity or Dialog.

再仔细看了下4.0中的方法:

 java.util.ArrayList<android.view.View>getCurrentViews() 
          Returns an ArrayList of the Views currently displayed in the focused Activity or Dialog.
<T extends android.view.View> 
java.util.ArrayList<T>
getCurrentViews(java.lang.Class<T> classToFilterBy) 
          Returns an ArrayList of Views matching the specified class located in the focused Activity or Dialog.
<T extends android.view.View> 
java.util.ArrayList<T>
getCurrentViews(java.lang.Class<T> classToFilterBy, android.view.View parent) 
          Returns an ArrayList of Views matching the specified class located under the specified parent.

虽然只剩下了三个getCurrentViews()方法,但却可以替代3.6的众多方法

java.lang.Class<T> classToFilterBy参数传入相应的类即可

例如:ArrayList<ImageView> imageList=solo.getCurrentViews(ImageView.class);得到的即是ImageView

            ArrayList<ImageView> imageList=solo.getCurrentViews(ImageView.class,parentView);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值