1.1新建一个项目:

UiAutomator环境

1.2引入依赖:

UiAutomator环境

//引入Uiautomator
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'

1.3编写代码:

UiAutomator环境

在androidTest下编写代码,类需要继承自TestCase,方法函数必须以test开头 

1.4运行:

 UiAutomator环境

在方法体右击,选择Run'XXX' 

1.5方法体示例:

public void testA() {
    // 获取设备对象
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    UiDevice uiDevice = UiDevice.getInstance(instrumentation);
    //按下Back键
    uiDevice.pressBack();
}

系列文章:

《1.2---UI Automator Viewer的使用》

相关文章:

  • 2021-07-27
  • 2021-08-12
  • 2021-06-14
  • 2021-04-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-04
猜你喜欢
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案