1page.title=Testing Device Provisioning 2@jd:body 3 4<!-- 5 Copyright 2016 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18--> 19<div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"> 23 </ol> 24 </div> 25</div> 26 27<p>The Android for Work (AfW) Test Harness is a test suite for validating the 28AfW compatibility of Android devices. It includes support apps, test cases, 29configuration files, and a test runner (<code>afw-test-tradefed</code>) built on 30<code>cts-tradefed</code>. You should setup and run the AfW Test Harness after 31completing <a href="{@docRoot}devices/tech/admin/provision.html">Provisioning 32for Device Administration</a>.</p> 33 34<p class=note><strong>Note:</strong> Building and running the AfW Test Harness 35is similar to building and running the Android 36<a href="http://source.android.com/compatibility/cts/index.html">Compatibility 37Test Suite (CTS)</a>.</p> 38 39<h2 id=setup_env>Setting up a development environment</h2> 40<p>The development environment for the AfW Test Harness is similar to Android 41OS. Follow the steps in 42<a href="{@docRoot}source/requirements.html">Requirements</a> to set up a 43development machine.</p> 44 45<h2 id=download_source>Downloading source code</h2> 46<p>Download the AfW Test Harness source code using the steps in 47<a href="{@docRoot}source/downloading.html">Downloading the Source</a>. The AfW 48Test Harness source code is in the <code>./test/AfwTestHarness</code> project. 49The branch name determines the version of AfW Test Harness to download (each 50Android platform has a separate version of AfW Test Harness). For Android 6.0, 51the branch name is <code>afw-test-harness-marshmallow-dev</code>. To initialize 52the repo and download source code for this branch, use:</p> 53 54<pre> 55$ mkdir WORKING_DIRECTORY 56$ cd WORKING_DIRECTORY 57$ git config --global user.name "Your Name" 58$ git config --global user.email "you@example.com" 59$ repo init -u https://android.googlesource.com/platform/manifest -b afw-test-harness-marshmallow-dev 60$ repo sync -j24 61</pre> 62 63<p>To check out the source code for a different version, specify the branch with 64the corresponding tag. Available branches include:</p> 65 66<table> 67<tr> 68<th>Branch Name</td> 69<th>Supported Android Platform</td> 70</tr> 71<tr> 72<td>afw-test-harness-marshmallow-dev</td> 73<td>Android 6.0</td> 74</tr> 75<tr> 76<td>afw-test-harness-1.5</td> 77<td>Android 6.0</td> 78</tr> 79</table> 80 81<p>Other dependency projects required to build the harness are also downloaded 82with the source code.</p> 83 84<h3 id=view_studio>Viewing in Android Studio</h3> 85<p>To view and edit AfW source code in Android Studio:</p> 86<ol> 87<li>Run the following commands 88<pre> 89$ make idegen 90$ development/tools/idegen/idegen.sh 91</pre> 92</li> 93<li>In Android Studio, open <code>android.ipr</code>.</li> 94</ol> 95 96<p>The AfW Test Harness source code is in <code>test/AfwTestHarness</code>.</p> 97 98<h2 id=config_harness>Configuring the AfW Test Harness</h2> 99<p>You can customize the harness by configuring 100<code>test/AfwTestHarness/afw-test.props</code>. To run the harness 101successfully, complete the following steps:</p> 102<ol> 103<li>Configure the Wi-Fi network in <code>afw-test.props</code> with the 104following properties: 105<pre>wifi_ssid 106wifi_password (optional) 107wifi_security_type (optional, available options are: NONE, WEP or WPA) 108</pre> 109</li> 110<li>Obtain at least one account from a domain that is bound to Test DPC as 111its device policy controller. Specify the details in <code>afw-test.props</code> 112with the following properties: 113<pre> 114work_account_username 115work_account_password 116</pre> 117<p>The AfW Test Harness uses Test DPC to test provisioning flows, so accounts 118<strong>must</strong> bind to Test DPC to run the test harness.</p> 119</li> 120</ol> 121 122<h2 id=build_harness>Building the AfW Test Harness</h2> 123<p>Initialize the build configuration using:</p> 124<pre> 125$ source build/envsetup.sh 126$ lunch 127</pre> 128 129<p>Select a device type and press <strong>Enter</strong>.</p> 130 131<p>Build the harness using:</p> 132<pre>$ make afw-test-harness -j32</pre> 133<p>This creates a directory (<code>out/host/linux-x86/afw-th/android-cts</code>) 134with all necessary binaries, configuration files, and tools to run the test 135harness. This directory is also zipped into a file 136(<code>out/host/linux-x86/afw-th/android-afw-test-harness.zip</code>) 137for distribution.</p> 138 139<h2 id=run_harness>Running the AfW Test Harness</h2> 140<p>Use the following steps to run the AfW Test Harness:</p> 141<ol> 142<li>In your build environment, launch the test runner using: 143<pre>$ afw-test-tradefed</pre> 144This starts the <code>cts-tf</code> console, loads test plans, test cases, 145and <code>afw-test.props</code> from 146<code>out/host/linux-x86/afw-th/android-cts</code>.</li> 147<li>From the unzipped folder of <code>android-afw-test-harness.zip</code>, 148launch the test runner using: 149<pre>$ cts-tf > ./android‐cts/tools/afw-test‐tradefed</pre> 150This loads test plans, test cases, and <code>afw-test.props</code> from 151<code>android-cts</code> directory. Ensure 152<code>./android‐cts/repository/testcases/afw-test.props</code> has the work 153account and Wi-Fi configuration.</li> 154 155<li>Run a test plan. Each test plan is an XML file that contains a set of test 156packages from the <code>AfwTestHarness/tests</code> test package directory. 157Common plans include: 158 159<ul> 160<li><code><strong>afw-userdebug-build</code></strong>. Contains all test 161packages that require a userdebug build.</li> 162<li><code><strong>afw-user-build</code></strong>. Runs on a user build but 163requires the test device to be set up properly, including completing the initial 164setup and enabling USB debugging.</li> 165</ul> 166 167<br>To run the test plan <code>afw-userdebug-build</code>, use: 168<pre>$ cts-tf > run cts --plan afw-userdebug-build</pre> 169To see all test plans, use the command <code>list plans</code>. To view plan 170definitions, refer to 171<code>out/host/linux-x86/afw-th/android-cts/repository/plans</code>. 172<br> 173</li> 174<li>Run a test package. To run a single test package, use 175<pre>$ cts-tf > run cts --package com.android.afwtest.NfcProvisioning 176</pre> 177To view all packages, use the command <code>list packages</code>. For more 178options, use the command <code>run cts --help</code>.</li> 179</ol> 180 181<h2 id=debug_harness>Debugging the AfW Test Harness</h2> 182<p>Run all commands in the afw-test-tradefed console (<code>cts-tf</code>), 183which you can launch by running <code>afw-test-tradefed</code>.</p> 184<ul> 185 186<li>Display more information with the <code>-l INFO</code> or <code>-l 187DEBUG</code> flags. Example: 188<pre>$ cts-tf > run cts ‐‐plan afw-userdebug-build -l DEBUG</pre></li> 189 190<li>Run the test harness on a specific device with the <code>-s</code> flag. 191Example: 192<pre>$ cts-tf > run cts ‐‐plan afw-userdebug-build -l DEBUG -s device_sn</pre> 193</li> 194 195<li>Run test harness on all connected devices with the 196<code>--all-devices</code> flag. Example: 197<pre>$ cts-tf > run cts ‐‐plan afw-userdebug-build -l DEBUG --all-devices</pre> 198</li> 199 200<li>View current running executions using <code>list invocations</code> or 201<code>l i</code>.</li> 202 203<li>View summary of past test executions using <code>list results</code> or 204<code>l r</code>.</li> 205 206<li>View other <code>list</code> commands using <code>help list</code>.</li> 207 208<li>Monitor real-time logcat with filter using <code>afwtest</code>, then open 209another terminal and start logcat using: <code>adb logcat | grep afwtest</code>. 210After a test completes: 211<ul> 212<li>View logs in 213<code>out/host/linux-x86/afw-th/android-cts/repository/logs/<em>start-time</em></code>. 214The full device logcat and host log (<code>afw-test-tradefed</code> logs) are 215saved in separate zip files.</li> 216 217<li>Find relevant information by searching the device logcat for 218<strong>afwtest</strong>. Example: <code>zless 219out/host/linux-x86/afw-th/android-cts/repository/logs/<em>start-time</em>/device_logcat_<em>random-number</em>.zip 220| grep afwtest</code></li> 221 222<li>To view the full afw-test-tradefed log, use: <code>zless 223out/host/linux-x86/afw-th/android-cts/repository/logs/<em>start-time</em>/host_log_<em>random-number</em>.zip</code> 224</li> 225</ul> 226</li> 227<li>A test package automates an AfW provisioning flow by going through UI pages 228and recording a navigation log in the device logcat file for each page. 229Example: <code>afwtest.AutomationDriver: 230Navigating:com.android.afwtest.uiautomator.pages.gms.AddAccountPage</code> 231<br>UI pages for test package 232<code>com.android.afwtest.NfcProvisioning</code> include:<ul> 233<li> 234<code>com.android.afwtest.uiautomator.pages.managedprovisioning.NfcProvisioningPage</code> 235</li> 236<li><code>com.android.afwtest.uiautomator.pages.PageSkipper</code></li> 237<li><code>com.android.afwtest.uiautomator.pages.LandingPage</code></li> 238</ul> 239</li> 240<li>If a test failed during the provisioning process, logcat contains an error 241similar to: 242<pre>TestRunner: java.lang.RuntimeException: Failed to load page: com.android.afwtest.uiautomator.pages.packageinstaller.DeviceAccessPage 243</pre> 244This is typically caused by errors in a previous UI page or the page that 245failed to load, so try to find other error messages in logcat before this error, 246then try to reproduce it manually following the provisioning flow.</li> 247<li>If a test package fails: 248<ul> 249<li>A screenshot is saved to 250<code>out/host/linux-x86/afw-th/android-cts/repository/logs/<em>start-time</em></code> 251using the following syntax: 252<code>screenshot-test_<em>test_class_full_name</em>_<em>test_case_name</em>-<em>random_number</em>.png</code>. 253This information is also logged in the host log.</li> 254<li>A bug report is saved to 255<code>out/host/linux-x86/afw-th/android-cts/repository/logs/<em>start-time</em></code> 256as: 257<code>bug-<em>test_class_full_name</em>_<em>test_case_name</em>-<em>random_number</em>.zip</code>. 258</li> 259</ul> 260</li> 261<li>After all test packages execute, a screenshot is taken and saved to 262<code>out/host/linux-x86/afw-th/android-cts/repository/logs/<em>start-time</em></code> 263as: <code>screenshot-<em>random_number</em>.png</code>. 264This information is also logged in the host log.</li> 265</ul> 266</li> 267</ul> 268 269<h2 id=faq>FAQ</h2> 270<p>For help with questions not answered below, contact 271<a href="mailto:afw-testharness-support@google.com">afw-testharness-support@google.com</a>. 272</p> 273 274<p><strong>Can I run test plan <code>afw-userdebug-build</code> on a device 275flashed with user build?</strong></p> 276<p><em>No. Test packages in the <code>afw-userdebug-build</code> plan factory 277reset the testing device before running the actual test flow and require 278<code>adb</code> debugging to be auto-enabled. With a user build, 279<code>adb</code> debugging can be enabled only by manually changing the 280setting in Developer options.</em></p> 281 282<p><strong>Can I run test plan <code>afw-user-build</code> on a device flashed 283with userdebug build?</strong></p> 284<p><em>Yes, but we recommend that you run this test plan on a user build.</em></p> 285 286<p><strong>Sometimes my test fails because UI loading takes too much time. How 287can I fix this?</strong></p><em>Configure the <code>timeout_size</code> setting 288in <code>./android-cts/repository/testcases/afw-test.props</code>. Valid 289settings are: S, M, L, XL, XXL.</em></p> 290 291<p><strong>The test package 292<code>com.android.afwtest.NfcProvisioning</code> (or 293<code>SuwDoProvisioning</code>) fails on my device because the installed initial 294setup (i.e. Setup Wizard) shows customized UI (such as Term & Conditions) 295after provisioning is complete. How can I skip this customized UI?</strong></p> 296<p><em>There should be minimal UI after the provisioning process. The test 297harness will automatically skip such UI if the UI has a button that has 298meaningful text or content description that contains any of the following words: 299Skip, Finish, Done, Accept, Agree, Next, Continue, or Proceed. Alternatively, 300you can define a button in <code>afw-test.props</code> to configure the test 301harness to skip your UI. Example:</em></p> 302<pre> 303oem_widgets=your_btn 304your_btn.text=your_customized_text 305your_btn.package=your_package 306your_btn.action=click 307</pre> 308<em><p>To define multiple widgets, separate using commas.</em></p> 309 310<p><strong>The test package 311<code>com.android.afwtest.NfcProvisioning</code> (or 312<code>SuwDoProvisioning</code>) failed and the last UI screen is "Verify your 313account." Why does this happen and how can I recover the testing device? 314</strong></p> 315<p><em>This failure occurs because the previous test package failed to clear 316Factory Reset Protection at the end of the test. You must manually enter the 317account to unlock the device.</em></p> 318 319<p><strong>My device needs more time to factory reset. Can I extend the factory 320reset timeout?</strong></p> 321<p><em>Yes. Configure the <code>factory_reset_timeout_min</code> setting in 322<code>afw-test.props</code>. Valid settings are in minutes; you can set to any 323number of minutes that works with your device.</em></p> 324