Robotium 的控件获取、操作及断言

1. Native 

 根据被检测应用的控件ID获取

方法返回值
getView(int ID )
View
getView(String ID )
View
根据控件类型的索引、文本来获取
方法返回值
getButton(int index)Button
getButton(String text)Button
根据控件类型进行过滤
getCurrentViews()ArrayList<View>
getCurentViews(Class<T>  classToFilterBy)    例如:getCurentViews(TextView.class)    
getCurentViews(Class<T>  classToFilterBy,View parent) 获取父控件下指定类型的控件
2. Native 控件操作
 1)长按、点击

        clickOnView(View view)   clickLongOnView(View view)    点击指定控件

        clickOnScreen(float x, float y)     clickLongOnScreen(float x, float y)    根据坐标轴

2) 操作输入框

      enterText(EditerText editer, String text)   先获取输入框,然后给输入框赋值,不展示输入过程

      typeText(EditerText editer, String text)   先获取输入框,然后给输入框赋值,展示输入过程

     举例: EditerText editer = (EditerText) solo.getView("example_et_id");

                solo.enterText(editer, "user_name")  

3) 滑动、滚动

      drag(float fromX , float toX , float fromY , float toY, int stepCount)   从起始坐标到终点坐标,指定滑动的步长,可以触发上拉加载更多

      scrollToTop() / scrollToButtom()  滑动顶部、滚动底部

      scrollUp() / scrollDown ()  向上滚动一屏屏幕,向下滚动一屏屏幕,不能触发上拉加载更多

      scrollListToLine(AbsListView abslistview, int line) 滚动列表至第几行

4)搜索与等待

     sleep(int time)  单位毫秒

     search(String text) 

5) 截图与其他

    takeScreenShot(String name)  截图并且命名,保存在 /sdcard/Robotium-Screenshots/目录下

    finishOpenedActivities()  关闭当前打开的所有Activity

    goBack()  / goBackToActivity( String name) 

    hideSoftKeyboard()

    setActivityOrientation(int orientation)

    sendKey(int key)

3. Webview 支持

   getCurrentWebElements()

   getCurrentWebElements(By by)

   clickOnWebElement(WebElement webElement)

   clickOnWebElement(By by)     举例:  solo.clickOnWebElement(By.className("btn-block"))  ;

   enterTextInWebElement(By.name("passId"),"your passId") ====WebElement 输入

4. 断言

assertTrue( String message, boolean condition);

assertFalse( String message, boolean condition);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值