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

 

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

       if (snapeaApp.exists()) {

          snapeaApp.clickAndWaitForNewWindow();

          break;

     }

     }

} catch (UiObjectNotFoundException e) {

e.printStackTrace();

}

 

}

}

2.执行步骤


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

  • UIAutomator的API 学习小例子_第2张图片
  • 大小: 33.5 KB
  • 查看图片附件

你可能感兴趣的:(UIAutomator的API 学习小例子)