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.执行步骤


UIAutomator的API 学习小例子_第1张图片
 

你可能感兴趣的:(auto)