Home | History | Annotate | Download | only in admin
      1 page.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
     28 AfW compatibility of Android devices. It includes support apps, test cases,
     29 configuration 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
     31 completing <a href="{@docRoot}devices/tech/admin/provision.html">Provisioning
     32 for Device Administration</a>.</p>
     33 
     34 <p class=note><strong>Note:</strong> Building and running the AfW Test Harness
     35 is similar to building and running the Android
     36 <a href="http://source.android.com/compatibility/cts/index.html">Compatibility
     37 Test 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
     41 OS. Follow the steps in
     42 <a href="{@docRoot}source/requirements.html">Requirements</a> to set up a
     43 development 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
     48 Test Harness source code is in the <code>./test/AfwTestHarness</code> project.
     49 The branch name determines the version of AfW Test Harness to download (each
     50 Android platform has a separate version of AfW Test Harness). For Android 6.0,
     51 the branch name is <code>afw-test-harness-marshmallow-dev</code>. To initialize
     52 the 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 (a] 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
     64 the 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
     82 with 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
    101 successfully, complete the following steps:</p>
    102 <ol>
    103 <li>Configure the Wi-Fi network in <code>afw-test.props</code> with the
    104 following properties:
    105 <pre>wifi_ssid
    106 wifi_password (optional)
    107 wifi_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
    111 its device policy controller. Specify the details in <code>afw-test.props</code>
    112 with the following properties:
    113 <pre>
    114 work_account_username
    115 work_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>)
    134 with all necessary binaries, configuration files, and tools to run the test
    135 harness. This directory is also zipped into a file
    136 (<code>out/host/linux-x86/afw-th/android-afw-test-harness.zip</code>)
    137 for 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>
    144 This starts the <code>cts-tf</code> console, loads test plans, test cases,
    145 and <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>,
    148 launch the test runner using:
    149 <pre>$ cts-tf &gt; ./androidcts/tools/afw-testtradefed</pre>
    150 This loads test plans, test cases, and <code>afw-test.props</code> from
    151 <code>android-cts</code> directory. Ensure
    152 <code>./androidcts/repository/testcases/afw-test.props</code> has the work
    153 account 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
    156 packages from the <code>AfwTestHarness/tests</code> test package directory.
    157 Common plans include:
    158 
    159 <ul>
    160 <li><code><strong>afw-userdebug-build</code></strong>. Contains all test
    161 packages that require a userdebug build.</li>
    162 <li><code><strong>afw-user-build</code></strong>. Runs on a user build but
    163 requires the test device to be set up properly, including completing the initial
    164 setup 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 &gt; run cts --plan afw-userdebug-build</pre>
    169 To see all test plans, use the command <code>list plans</code>. To view plan
    170 definitions, 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 &gt; run cts --package com.android.afwtest.NfcProvisioning
    176 </pre>
    177 To view all packages, use the command <code>list packages</code>. For more
    178 options, 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>),
    183 which 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
    187 DEBUG</code> flags. Example:
    188 <pre>$ cts-tf &gt; 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.
    191 Example:
    192 <pre>$ cts-tf &gt; 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 &gt; 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
    209 another terminal and start logcat using: <code>adb logcat | grep afwtest</code>.
    210 After 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>.
    214 The full device logcat and host log (<code>afw-test-tradefed</code> logs) are
    215 saved in separate zip files.</li>
    216 
    217 <li>Find relevant information by searching the device logcat for
    218 <strong>afwtest</strong>. Example: <code>zless
    219 out/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
    223 out/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
    228 and recording a navigation log in the device logcat file for each page.
    229 Example: <code>afwtest.AutomationDriver:
    230 Navigating: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
    241 similar to:
    242 <pre>TestRunner: java.lang.RuntimeException: Failed to load page: com.android.afwtest.uiautomator.pages.packageinstaller.DeviceAccessPage
    243 </pre>
    244 This is typically caused by errors in a previous UI page or the page that
    245 failed to load, so try to find other error messages in logcat before this error,
    246 then 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>
    251 using the following syntax:
    252 <code>screenshot-test_<em>test_class_full_name</em>_<em>test_case_name</em>-<em>random_number</em>.png</code>.
    253 This 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>
    256 as:
    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>
    263 as: <code>screenshot-<em>random_number</em>.png</code>.
    264 This 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 (a] google.com">afw-testharness-support (a] google.com</a>.
    272 </p>
    273 
    274 <p><strong>Can I run test plan <code>afw-userdebug-build</code> on a device
    275 flashed with user build?</strong></p>
    276 <p><em>No. Test packages in the <code>afw-userdebug-build</code> plan factory
    277 reset 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
    280 setting in Developer options.</em></p>
    281 
    282 <p><strong>Can I run test plan <code>afw-user-build</code> on a device flashed
    283 with 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
    287 can I fix this?</strong></p><em>Configure the <code>timeout_size</code> setting
    288 in <code>./android-cts/repository/testcases/afw-test.props</code>. Valid
    289 settings 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
    294 setup (i.e. Setup Wizard) shows customized UI (such as Term &amp; Conditions)
    295 after 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
    297 harness will automatically skip such UI if the UI has a button that has
    298 meaningful text or content description that contains any of the following words:
    299 Skip, Finish, Done, Accept, Agree, Next, Continue, or Proceed. Alternatively,
    300 you can define a button in <code>afw-test.props</code> to configure the test
    301 harness to skip your UI. Example:</em></p>
    302 <pre>
    303 oem_widgets=your_btn
    304 your_btn.text=your_customized_text
    305 your_btn.package=your_package
    306 your_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
    313 account." 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
    316 Factory Reset Protection at the end of the test. You must manually enter the
    317 account to unlock the device.</em></p>
    318 
    319 <p><strong>My device needs more time to factory reset. Can I extend the factory
    320 reset 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
    323 number of minutes that works with your device.</em></p>
    324