`
jerome_wang
  • 浏览: 148633 次
  • 性别: Icon_minigender_1
  • 来自: 云南
社区版块
存档分类
最新评论

UIAutomator的API 学习小例子

阅读更多

在模拟器上玩的

1.代码 

import com.android.uiautomator.core.UiDevice;

import com.android.uiautomator.core.UiObject;

import com.android.uiautomator.core.UiObjectNotFoundException;

import com.android.uiautomator.core.UiScrollable;

import com.android.uiautomator.core.UiSelector;

import com.android.uiautomator.testrunner.UiAutomatorTestCase;

 

public class GetDevice extends UiAutomatorTestCase {

 

public void test() {

 

try {

UiDevice testDevice = getUiDevice();

testDevice.pressHome();

UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));

allAppsButton.clickAndWaitForNewWindow();

     UiScrollable appViews = new UiScrollable( new UiSelector().className("android.view.View"));//获取apps这个控件

     appViews.setAsHorizontalList();//设置水平移动

     for (int i=0; i<appViews.getMaxSearchSwipes() - 1;i++) { //找到settings 并点击

 

     UiObject snapeaApp = new UiObject(new UiSelector().text("Settings"));

       if (snapeaApp.exists()) {

          snapeaApp.clickAndWaitForNewWindow();

          break;

     }

     }

} catch (UiObjectNotFoundException e) {

e.printStackTrace();

}

 

}

}

2.执行步骤



 

  • 大小: 33.5 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics