在模拟器上玩的

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 学习小例子
 

相关文章:

  • 2022-02-26
  • 2021-06-24
  • 2021-05-27
  • 2021-12-06
  • 2022-01-11
  • 2021-09-02
  • 2021-12-03
  • 2021-12-17
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2021-11-29
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-11-06
相关资源
相似解决方案