robotium源码分析 ClickView
来源:互联网 发布:杜兰特本赛季数据统计 编辑:程序博客网 时间:2024/05/16 09:15
robotium关于Click的方法有 ClickOnView()、ClickLongOnView()、ClickInList()、ClickonSceen()clickOnActionBarItem()这几个大类。
而ClickonScreen(float x,float y)源码为:
public void clickOnScreen(float x, float y) {
boolean successfull = false;
Instrumentation inst;
int retry = 0;
while(!successfull && retry < 10) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN, x, y, 0);
MotionEvent event2 = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_UP, x, y, 0);
try{
inst.sendPointerSync(event);
inst.sendPointerSync(event2);
successfull = true;
sleeper.sleep(MINISLEEP);
}catch(SecurityException e){
dialogUtils.hideSoftKeyboard(null, false, true);
retry++;
}
}
if(!successfull) {
Assert.assertTrue("Click can not be completed!", false);
}
}
通过源码我们知道Robotium点击View就是调用Instrumentation类方法中的sendPointSync(event)(模拟鼠标点击),而clickOnView则是通过view的id或者index获取到View,然后通过View的getLocationOnScreen()方法和View的宽和高得到该View的坐标,然后调用clickOnScreen()方法。View坐标获取的代码为:
view.getLocationOnScreen(xy);
final int viewWidth = view.getWidth();
final int viewHeight = view.getHeight();
final float x = xy[0] + (viewWidth / 2.0f);
float y = xy[1] + (viewHeight / 2.0f);
clickLongOnView则是在两个event之间加上间隔时间。
clickOnActionBarItem()则是调用Instrumentation类方法中的invokeMenuActionSync(Activity activity,int id);方法。
drag()方法也是类似于click 只是多了个move 事件;
sendCharacterSync(int keyCode) //用于发送指定KeyCode的按键
sendKeyDownUpSync(int key) //用于发送指定KeyCode的按键
sendPointerSync(MotionEvent event) //用于模拟Touch
sendStringSync(String text) //用于发送字符串
- robotium源码分析 ClickView
- robotium源码分析 ClickView
- robotium源码分析 ClickView
- Robotium searchText源码分析
- Robotium中webview源码分析
- Robotium源码分析之Instrumentation进阶
- Robotium源码分析之运行原理
- Robotium源码分析之Instrumentation进阶
- Robotium源码分析之运行原理
- Robotium源码分析之Instrumentation进阶
- Robotium源码分析之运行原理
- Robotium源码分析之运行原理
- Robotium源码分析之Instrumentation进阶
- Robotium源码分析之Instrumentation进阶
- robotium 源码网
- robotium导入源码学习
- robotium关键源码解释
- robotium有源码
- Ajax jsp指定提交
- 修改chrome的背景色
- 承接java项目
- 山之魂
- HDU3113(工科数学分析之分解)
- robotium源码分析 ClickView
- 2013年就要结束了,留下这一年所有的感动
- OpenGL ES2.0 的三种变量类型(uniform,attribute和varying)
- hadoop2.2编译
- HDOJ-2159 FATE
- 韩顺平网页设计第四十四讲
- C++中类的多态与虚函数的使用
- 删除
- ubuntu12.04创建快捷方式