Appium-Drivers-UIAutomator2(Android)

经仔细对比,UIAutomator与UIAutomator2内容基本一致

The UiAutomator2 Driver for Android

          • Requirements and Support
          • Usage
          • Capabilities
          • Commands
          • Basic Setup
          • Emulator Setup
          • Real Device Setup

Appium’s flagship support for automating Android apps is via the UiAutomator2 driver. (New to Appium? Read our introduction to Appium drivers). This driver leverages Google’s UiAutomator2 technology to facilitate automation on a device or emulator.

Appium对Android应用程序自动化的旗舰支持是通过UiAutomator2驱动程序实现的

Development of the UiAutomator2 driver happens at the appium-uiautomator2-driver repo.

UiAutomator2 driver在appium-UiAutomator2-driver repo开发

Older Android-based drivers include: * The UiAutomator Driver

旧Android-based drivers包括UiAutomator Driver
Requirements and Support

In addition to Appium’s general requirements:

  • Java 8 installed and configured correctly for your platform
JAVA 8
  • Mac, Windows, or Linux OS with the ability to run the Android SDK
可以运行Android SDK的系统
  • The minimum required Android SDK Build Tools version is 24
Android SDK最低版本24

Further, the UiAutomator2 driver does not support Android versions below 5.0 (Lollipop, API level 21). If you are automating such versions, consider using the UiAutomator driver;

UiAutomator2不支持Android 5.0以下的版本(Lollipop, API level 21)
如果正在自动化这些版本,请考虑使用UiAutomator driver
Usage

The way to start a session using the UiAutomator2 driver is to include the automationName capability in your new session request, with the value UiAutomator2. Of course, you must also include appropriate platformName(=Android), platformVersion, deviceName, and app capabilities, at a minimum.

开始会话的方法是在新会话请求中包含automationName功能,
值为UIAutomator2.
当然,你必须至少包含合适的`platformName` (=`Android`), `platformVersion`, `deviceName`, 
and `app` capabilities

It is highly recommended to also set the appPackage and appActivity capabilities in order to let Appium know exactly which package and activity should be launched for your application. Otherwise, Appium will try to determine these automatically from your app manifest.

强烈建议还设置`appPackage`and`appActivity`,方便让Appium确切的知道应该为您的应用程序启动的包和项。
否则,Appium将尝试从应用程序清单中自动确定这些
Capabilities

The UiAutomator2 driver supports a number of standard Appium capabilities, but has an additional set of capabilities that modulate the behavior of the driver. These can be found currently at the Android section of the aforementioned doc.

UiAutomator2 driver支持多标准的Appium功能,但是有额外的功能来调节驱动程序的行为

For web tests, to automate Chrome instead of your own application, leave the app capability empty and instead set the browserName capability to Chrome. Note that you are responsible for ensuring that Chrome is on the emulator/device, and that it is of a version compatible with Chromedriver.

对于web测试,要自动执行Chrome而不是自己的应用程序,
请将`app`的功能清空,将'browserName'功能设置为`Chrome`.
注意你有责任确保为`Chrome`在模拟器/设备上,并且它的版本与`Chromedriver`兼容
Commands

To see the various commands Appium supports, and specifically for information on how the commands map to behaviors for the UiAutomator2 driver, see the API Reference.

要查看Appium支持的各种命令,特别是关于命令如何映射到UiAutomator2 driver行为
Basic Setup

1.Ensure that you have Appium’s general dependencies (e.g., Node & NPM) installed and configured.

Node/npm

2.Ensure that Java (the JDK, not just the JRE) is installed and Java binaries are added to your path. The instructions for this step differ for Mac/Linux and for Windows. Please consult platform-specific documentation, as this is a common task. An example of how to change the PATH on Windows is here.

JDK

3.Ensure that the JAVA_HOME environment variable is also set to the JDK path. For Mac/Linux, for example (the specifics of this path will vary greatly by system), put this in your login script:

JDK路径放入脚本

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home"
On Windows, this will be done by setting the environment variable in the control panel, using the same strategy as for setting PATH above. Android Studio also has JDK in the path like /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home (Mac). You can specify the path, too.

在Windows中,这将在控制面板中的环境变量里设置来实现,设置路径的方法与以上相同。
Android Studio在path中也有JDK,(Mac样例)也可以指定路径

1.Install the Android SDK. The supported way of doing this nowadays is to use Android Studio. Use the provided GUI to install the Android SDK to a path of your choosing.

安装Android SDK
它现在的支持方式是使用Android Studio
使用提供的GUI安装Android SDK到你的指定路径上

2.Set the ANDROID_HOME environment variable to match this path. For example, if you installed the SDK to /usr/local/adt, then there will typically be a sdk folder inside of that which contains the SDK files. In that case, on Mac and Linux, add the following line to your login script (e.g., ~/.bashrc, ~/.bash_profile, etc…):

export ANDROID_HOME="/usr/local/adt/sdk"

设置与之匹配的路径/示例

On Windows, follow the same steps as before to set the environment variable in the control panel.

在Windows中,按照前面相同的步骤在控制面板中设置环境变量

1.Using the SDK manager, ensure you have installed the SDK for Android API levels you wish to automate (e.g., 24).

使用SDK manager确保安装了你所希望的Android API的SDK

2.On Windows, ensure that you always run Appium in Administrator mode.

Windows中,管理员模式运行Appium

At this point, your general system setup is done. Follow the steps below based on whether you want to automate an emulator or a real device. In addition you will need your app’s APK (preferably built in Debug mode), whose path or URL you will use as the value of the app capability when running your tests.

此时常规系统设置已完成。
根据你想使用的是仿真器还是真机Android Studio自带的AVD Manager或是SDK设置。
此外,您还需要app's APK(最好是调试模式下建立的)
测试时,将使用path or URL作为'app'的值
Emulator Setup

To run tests on emulators, use the AVD Manager included with Android Studio or the SDK. With this tool, create the emulator that matches your needs. With the emulator launched, Appium will automatically find and use it for its tests. Otherwise, if you specify the avd capability with the value matching the name of your emulator, then Appium will attempt to launch the emulator for you.

在模拟器上测试,使用Android Studio或AVD Manager自带的SDK。
使用此工具,你需要的模拟器。
模拟器启动后,Appium将自动查找并使用它进行测试。
否则,如果你指定avd功能值与模拟器的名称匹配,然后Appium将为你尝试启动模拟器

Additional tips for emulators:

其他提示
  • There exists a hardware accelerated emulator for Android, though it has its own limitations. It can be installed from Intel’s website, or through the Android SDK Manager. For more information, go here.
Android有一个硬件加速模拟器,尽管它有自己的局限性。
可以从Inel's网站上安装或通过Android SDK Manager.
  • Make sure that hw.battery=yes in your AVD’s config.ini, if you want to run any of the Appium tests, or use any of the power commands. (As of Android 5.0, this is the default.)
确保`hw.battery=yes`在你的AVD`S config.ini中,如果你想运行任何Appium测试,或用任何power 命令
(从Android 5.0以后,这是默认设置)
Real Device Setup

For Android automation, no additional setup is required for testing on real devices, other than these simple requirements:

对于Android automation,在真机上进行测试不需要额外的设置,
除以下简单要求:
  • Ensure that Developer mode is turned on for the device.开发者模式打开
  • Ensure that the device is connected via USB to the Appium host, and can be seen by ADB (run adb devices to make sure).USB链接到Appium host,并可以通过ADB识别(运行adb devices来确认)
  • Ensure that “Verify Apps” in settings is disabled, to allow Appium’s helper apps to function without manual intervention.
确认设置中的'Verify Apps'是禁用的,
以允许Appium's helper apps是无需手动干预可运行

(For some specific commands, the device might need to be rooted, though this is not the norm.)

(对于某些特定命令,设备可能需要根目录,这不是标准不变的)

你可能感兴趣的:(Appium,android,windows,ios,android,studio,测试类型)