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) | 获取父控件下指定类型的控件 |
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);
本文详细介绍了一种基于Native的UI自动化测试方法,包括如何通过控件ID、类型等获取控件,进行点击、输入等操作,并提供了滑动、搜索、等待等功能的使用示例。此外还介绍了针对Webview的操作和支持。

246

被折叠的 条评论
为什么被折叠?



