The Android for Work (AfW) Test Harness is a test suite for validating the
AfW compatibility of Android devices. It includes support apps, test cases,
configuration files, and a test runner (afw-test-tradefed
) built on
cts-tradefed
. You should setup and run the AfW Test Harness after
completing Provisioning
for Device Administration.
Note: Building and running the AfW Test Harness is similar to building and running the Android Compatibility Test Suite (CTS).
The development environment for the AfW Test Harness is similar to Android OS. Follow the steps in Requirements to set up a development machine.
Download the AfW Test Harness source code using the steps in
Downloading the Source. The AfW
Test Harness source code is in the ./test/AfwTestHarness
project.
The branch name determines the version of AfW Test Harness to download (each
Android platform has a separate version of AfW Test Harness). For Android 7.0,
the branch name is afw-test-harness-nougat-dev
. To initialize
the repo and download source code for this branch, use:
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
repo init -u https://android.googlesource.com/platform/manifest -b afw-test-harness-nougat-dev
repo sync -j24
To check out the source code for a different version, specify the branch with the corresponding tag. Available branches include:
Branch Name | Supported Android Platform |
---|---|
afw-test-harness-nougat-dev | Android 7.0 |
afw-test-harness-2.1 | Android 7.0 |
afw-test-harness-marshmallow-dev | Android 6.0 |
afw-test-harness-1.5 | Android 6.0 |
Other dependency projects required to build the harness are also downloaded with the source code.
To view and edit AfW source code in Android Studio:
make idegen
development/tools/idegen/idegen.sh
android.ipr
.The AfW Test Harness source code is in test/AfwTestHarness
.
You can customize the harness by configuring
test/AfwTestHarness/afw-test.props
. To run the harness
successfully, complete the following steps:
afw-test.props
with the
following properties:
wifi_ssid wifi_password (optional) wifi_security_type (optional, available options are: NONE, WEP or WPA)
afw-test.props
with the following properties:
work_account_username work_account_password
The AfW Test Harness uses Test DPC to test provisioning flows, so accounts must bind to Test DPC to run the test harness.
Initialize the build configuration using:
source build/envsetup.sh
lunch
Select a device type and press Enter.
Build the harness using:
make afw-test-harness -j32
This creates a directory (out/host/linux-x86/afw-th/android-cts
)
with all necessary binaries, configuration files, and tools to run the test
harness. This directory is also zipped into a file
(out/host/linux-x86/afw-th/android-afw-test-harness.zip
)
for distribution.
Use the following steps to run the AfW Test Harness:
afw-test-tradefedThis starts the
cts-tf
console, loads test plans, test cases,
and afw-test.props
from
out/host/linux-x86/afw-th/android-cts
.android-afw-test-harness.zip
,
launch the test runner using:
cts-tf> ./android‐cts/tools/afw-test‐tradefedThis loads test plans, test cases, and
afw-test.props
from
android-cts
directory. Ensure
./android‐cts/repository/testcases/afw-test.props
has the work
account and Wi-Fi configuration.AfwTestHarness/tests
test package directory.
Common plans include:
afw-userdebug-build
. Contains all test
packages that require a userdebug build.afw-user-build
. Runs on a user build but
requires the test device to be set up properly, including completing the initial
setup and enabling USB debugging.afw-userdebug-build
, use:
cts-tf> run cts --plan afw-userdebug-buildTo see all test plans, use the command
list plans
. To view plan
definitions, refer to
out/host/linux-x86/afw-th/android-cts/repository/plans
.
cts-tf> run cts --package com.android.afwtest.NfcProvisioningTo view all packages, use the command
list packages
. For more
options, use the command run cts --help
.Run all commands in the afw-test-tradefed console (cts-tf
),
which you can launch by running afw-test-tradefed
.
-l INFO
or -l
DEBUG
flags. Example:
cts-tf> run cts ‐‐plan afw-userdebug-build -l DEBUG
-s
flag.
Example:
cts-tf> run cts ‐‐plan afw-userdebug-build -l DEBUG -s device_sn
--all-devices
flag. Example:
cts-tf> run cts ‐‐plan afw-userdebug-build -l DEBUG --all-devices
list invocations
or
l i
.list results
or
l r
.list
commands using help list
.afwtest
, then open
another terminal and start logcat using: adb logcat | grep afwtest
.
After a test completes:
out/host/linux-x86/afw-th/android-cts/repository/logs/start-time
.
The full device logcat and host log (afw-test-tradefed
logs) are
saved in separate zip files.zless
out/host/linux-x86/afw-th/android-cts/repository/logs/start-time/device_logcat_random-number.zip
| grep afwtest
zless
out/host/linux-x86/afw-th/android-cts/repository/logs/start-time/host_log_random-number.zip
afwtest.AutomationDriver:
Navigating:com.android.afwtest.uiautomator.pages.gms.AddAccountPage
com.android.afwtest.NfcProvisioning
include:com.android.afwtest.uiautomator.pages.managedprovisioning.NfcProvisioningPage
com.android.afwtest.uiautomator.pages.PageSkipper
com.android.afwtest.uiautomator.pages.LandingPage
TestRunner: java.lang.RuntimeException: Failed to load page: com.android.afwtest.uiautomator.pages.packageinstaller.DeviceAccessPageThis is typically caused by errors in a previous UI page or the page that failed to load, so try to find other error messages in logcat before this error, then try to reproduce it manually following the provisioning flow.
out/host/linux-x86/afw-th/android-cts/repository/logs/start-time
using the following syntax:
screenshot-test_test_class_full_name_test_case_name-random_number.png
.
This information is also logged in the host log.out/host/linux-x86/afw-th/android-cts/repository/logs/start-time
as:
bug-test_class_full_name_test_case_name-random_number.zip
.
out/host/linux-x86/afw-th/android-cts/repository/logs/start-time
as: screenshot-random_number.png
.
This information is also logged in the host log.For help with questions not answered below, contact afw-testharness-support@google.com.
Can I run test plan afw-userdebug-build
on a device
flashed with user build?
No. Test packages in the afw-userdebug-build
plan factory
reset the testing device before running the actual test flow and require
adb
debugging to be auto-enabled. With a user build,
adb
debugging can be enabled only by manually changing the
setting in Developer options.
Can I run test plan afw-user-build
on a device flashed
with userdebug build?
Yes, but we recommend that you run this test plan on a user build.
Sometimes my test fails because UI loading takes too much time. How can I fix this?
Configure the timeout_size
setting
in ./android-cts/repository/testcases/afw-test.props
. Valid
settings are: S, M, L, XL, XXL.
The test package
com.android.afwtest.NfcProvisioning
(or
SuwDoProvisioning
) fails on my device because the installed initial
setup (i.e. Setup Wizard) shows customized UI (such as Term & Conditions)
after provisioning is complete. How can I skip this customized UI?
There should be minimal UI after the provisioning process. The test
harness will automatically skip such UI if the UI has a button that has
meaningful text or content description that contains any of the following words:
Skip, Finish, Done, Accept, Agree, Next, Continue, or Proceed. Alternatively,
you can define a button in afw-test.props
to configure the test
harness to skip your UI. Example:
oem_widgets=your_btn your_btn.text=your_customized_text your_btn.package=your_package your_btn.action=click
To define multiple widgets, separate using commas.
The test package
com.android.afwtest.NfcProvisioning
(or
SuwDoProvisioning
) failed and the last UI screen is "Verify your
account." Why does this happen and how can I recover the testing device?
This failure occurs because the previous test package failed to clear Factory Reset Protection at the end of the test. You must manually enter the account to unlock the device.
My device needs more time to factory reset. Can I extend the factory reset timeout?
Yes. Configure the factory_reset_timeout_min
setting in
afw-test.props
. Valid settings are in minutes; you can set to any
number of minutes that works with your device.