robotium常用API
robotium常用APIRobotium中最重要的类Solo类:其中提供了模拟用户活动的点击、搜索、拖拽等方法。英文api(经常断开连接打不开):http://www.jarvana.com/jarvana/view/com/jayway/android/robotium/robotium-solo/2.0.1/robotium-solo-2.0.1-javadoc.jar!/i
robotium常用API
Robotium中最重要的类Solo类:其中提供了模拟用户活动的点击、搜索、拖拽等方法。
英文api(经常断开连接打不开):http://www.jarvana.com/jarvana/view/com/jayway/android/robotium/robotium-solo/2.0.1/robotium-solo-2.0.1-javadoc.jar!/index-all.html
中文API: http://www.robotium.cn/archives/category/api/page/7
(源代码解析-Solo : http://www.robotium.cn/archives/1050)
典型方法:(更多方法及解释请查看以上api)
其中很多方法都是根据控件的索引值进行操作
① 点击:
clickOnButton(int)—Clickson a Button
with a givenindex.根据索引值点击Button.
clickOnButton(String)—Clickson a Button
with a giventext.根据文本点击Button.
clickOnCheckBox(int)—Clickson a CheckBox
with a givenindex.
clickOnView(View)—Clickson a given View.
clickOnText(String)—Clickson a View
displaying agiven text.
clickLongOnText(String)—Longclicks on a givenView
.
clickOnRadioButton(int)—Clickson a RadioButton
with a givenindex.
clickOnScreen(float, float)—Clickson a given coordinate on the screen.
② 取得:
getCurrentActivity()—Returnsthe current Activity.
getText(String)—Returnsa TextView which shows a given text.
getView(int)—Returnsa View with a given id.
getEditText(String)—Returnsan EditText which shows a given text.
getImage(int)—Returnsan ImageView with a given index.
③ 拖拽:
drag(float, float, float,float, int)—Simulate touching a given location anddragging it to a new location.
④ 搜索:
searchText(String)—Searchesfor a text string and returnstrue
if at least one item is found with the expected text.
searchEditText(String)—Searchesfor a text string in the EditText objects located in the current Activity.
searchButton(String, boolean)—Searchesfor a Button with the given text string and returns true if at least one Buttonis found.
断言:
具体请查看官网
断言方法assert(robotium特有的断言方式,实际项目中和Junit的assert方法配合使用)
void assertCurrentActivity (String message, Class activityClass [,booleanisNewInstance])
断言当前的activity是否是预期的
参数:message-如果运行失败打印的消息activityClass-预期的activityisNewInstance-可选项,实际activity是否是预期activity的继承,如果为true则只要是继承关系就通过,false则必须是当前activity
void assertCurrentActivity (String message, String name [,booleanisNewInstance])
断言当前的activity是否是预期的
参数:name-预期activity的名字
void assertMemoryNotLow()
断言目前系统可用内存是否过低,内存空间足够则通过
is方法
boolean isCheckBoxChecked (intindex | String text)
判断checkBox是否处于被选中的状态,可以通过index和text两种方法定位
参数:index-检查的checkBox的索引值,如果只有一个可用则为0;text-检查的checkBox的文字,可使用正则表达式.类似的有:
boolean isRadioButtonChecked(int index | String text)
boolean isToggleButtonChecked(int index | String text)
boolean isSpinnerTextSelected ( [intindex, ] String text)
boolean isTextChecked (Stringtext)
search方法
boolean searchButton (Stringtext [, int minimumNumberOfMatches, boolean onlyVisible])判断当前的屏幕中是否能找到指定的button
参数:text-查找的button的文字minimumNumberOfMatches-最小指定多少才算是通过,0表示1个或者多个onlyVisible-只记录可见的
boolean searchText (String text[, int minimumNumberOfMatches, boolean scroll, boolean onlyVisible])判断当前的屏幕中是否能找到指定的text,即文本
参数:text-查找的Text的文字minimumNumberOfMatches-最小指定多少才算是通过,0表示1个或者多个scroll-是否允许滚动搜索,true表示支持,false表示只能在当前屏幕内查找onlyVisible-只记录可见的
boolean searchToggleButton(String text [, int minimumNumberOfMatches])
boolean searchEditText (Stringtext)判断当前的屏幕中是否能找到指定的EditText
更多推荐
所有评论(0)