uiautomator特殊场景

1.自定义参数

运行时指定-e:adb shell uiautomator runtest Demo.jar --no-hup -c com.demo.TestDemo -e phone 10086

Bundle d=getParams();

String phone=(String)b.get("phone");

 

 

2.send key的方式清除

UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_END);

UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_DEL);

this.getUiDevice().pressKeyCode(1); 键盘按键

 

3.Configurator(间隔) 功能

1)可调节两个模拟动作之间的默认间隔  setActionAcknowledgmentTimeout(5);

2)可调节输入文本的输入时间间隔   setKeyInjectionDelay(long delay)

3)可调节每次滚动的时间间隔  setScrollAcknowledgmentTimeout(long timeout)

4)可调节等待系统空闲的默认时间  setWaitForIdleTimeout(long timeout)

 Configurator.getInstance().setActionAcknowledgmentTimeout(5);

sleep(2000);

UiDevice.getInstance().swipe(x-50,y/2,50,y/2,10);

UiDevice.getInstance().swipe(x-50,y/2,50,y/2,10);//在屏幕上滑动

 

 4.API:

System.out.println( this.getUiDevice().isNaturalOrientation());  //是否竖屏

this.getUiDevice().setOrientationLeft();
System.out.println( this.getUiDevice().isNaturalOrientation());
System.out.println( this.getUiDevice().getDisplayRotation());  //显示角度  
 
 
 
5.滑动三种方式
          Point s=new Point();
          Point s1=new Point();
          Point[] t={s,s1};        
          this.swipe(t, 13);
 ShellUtil.exec("input swipe 500 1400 500 700 500");
 
UiScrollable aa=new UiScrollable(new UiSelector().resourceId("com.android.browser:id/title"));
     aa.flingBackward();
     aa.flingForward();      
     aa.scrollToEnd(10);
     aa.scrollIntoView(uiobject);
 
 
6.两指放大 
new UiObject(new UiSelector().resourceId(sp.UrlAddress)).pinchOut(50, 20);

performMultiPointGesture(PointerCoords.touches)

 

7.模拟按键,事件注入
http://www.cnblogs.com/by-dream/p/5195121.html
 
press.sh
 
#!/bin/sh
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 1
sendevent /dev/input/event6 0 0 0
echo "down"
sendevent /dev/input/event6 1 116 0
sendevent /dev/input/event6 0 0 0
echo "up"
posted @ 2016-04-07 22:04  q55091  阅读(344)  评论(0编辑  收藏  举报