def _grab_screenshots(self): """Captures screenshots that are created by the UIAutomator tests.""" for screenshot in arc.adb_shell('find /sdcard/*.png').splitlines(): logging.debug('Screenshot is %s.', screenshot) arc.adb_cmd('pull %s %s' % (screenshot, self.resultsdir), ignore_status=True) arc.adb_shell('rm -r %s' % screenshot, ignore_status=True)
def run_once(self, retries=3): self._increase_logcat_buffer() self._copy_resources_to_dut() self._grant_storage_permission() for trial in range(retries): logging.info('Iteration %d: Trying to launch play store' % trial) # Bring Play Store to front. arc.adb_shell('am start %s' % self._PLAY_STORE_ACTIVITY) self._take_screenshot('test_start') self._start_test() logging.info('Iteration %d: Test finished' % trial) self._take_screenshot('test_end') self._get_app_version() self._capture_bugreport() self._grab_screenshots() self._save_logcat(trial) passed, result = self._parse_results() if passed: return elif trial + 1 >= retries: raise error.TestFail(result) # Kill playstore and clear logcat for next iteration. arc.adb_shell('am force-stop %s' % self._PLAY_STORE_ACTIVITY) self._clear_logcat_buffer()
def _stop_app(self): """Stops microphone app. Stops the microphone app process. """ arc.adb_shell( 'am force-stop %s' % pipes.quote(self._MICROPHONE_PACKAGE))
def _start_app(self, dest_path): """Starts Play Video app playing a video file. @param dest_path: Path to the file to play in container. """ arc.adb_shell('am start --activity-clear-top ' '--es PATH {} {}'.format( pipes.quote(dest_path), self._PLAYVIDEO_ACTIVITY))
def cleanup(self): arc.adb_cmd('uninstall com.hcl.actframework') arc.adb_cmd('uninstall com.hcl.actframework.test') arc.adb_cmd('uninstall %s' % self._pkg_name) arc.adb_shell('rm -f /sdcard/autresources.xml > /dev/null') arc.adb_shell('rm -f /sdcard/touchView.txt > /dev/null', ignore_status=True) utils.run('rm -rf %s' % self._TMP_LOCATION) super(cheets_AppCompatTest, self).cleanup()
def _start_test(self): """Kick off the UIAutomator tests.""" arc.adb_shell('am instrument -w -r -e debug false -e ' '"device_model" "Google~Pixelbook" -e ' '"app_packagename" %s -e "app_version" "TBD" -e ' '"device_os_build_version" 7.1.1 -e ' '"clear_recents" "N" -e "check_wifi_connection" ' '"N" -e "check_location_on" "N" -e ' '"check_auto_rotate_off" "N" ' 'com.hcl.actframework.test/android.support.test' '.runner.AndroidJUnitRunner' % self._pkg_name)
def _start_app(self, dest_path): """Starts Play Music app playing an audio file. @param dest_path: Path to the file to play in container. """ ext = os.path.splitext(dest_path)[1] command = ('am start -a android.intent.action.VIEW' ' -d "file://%s" -t "audio/%s"' ' -n "%s/%s"' % (pipes.quote(dest_path), pipes.quote(ext), pipes.quote(self._PLAYMUSIC_PACKAGE), pipes.quote(self._PLAYMUSIC_ACTIVITY))) logging.debug(command) arc.adb_shell(command)
def run_clouddpc_test(self): """ Run clouddpc end-to-end test and fail this test if it fails. Assumes start_arc() was run with use_clouddpc_test. Determines the policy values to pass to the test from those set in Chrome OS. @raises error.TestFail if the test does not pass. """ policy_blob = self._get_clouddpc_policies() policy_blob_str = json.dumps(policy_blob, separators=(',', ':')) cmd = ('am instrument -w -e policy "%s" ' 'com.google.android.apps.work.clouddpc.e2etests/' '.ArcInstrumentationTestRunner') % policy_blob_str # Run the command as a shell script so that its length is not capped. temp_shell_script_path = '/sdcard/tmp.sh' arc.write_android_file(temp_shell_script_path, cmd) logging.info('Running clouddpc test with policy: %s', policy_blob_str) results = arc.adb_shell('sh ' + temp_shell_script_path).strip() arc.remove_android_file(temp_shell_script_path) if results.find('FAILURES!!!') >= 0: logging.info('CloudDPC E2E Results:\n%s', results) err_msg = results.splitlines()[-1] raise error.TestFail('CloudDPC E2E failure: %s' % err_msg) logging.debug(results) logging.info('CloudDPC E2E test passed!')
def _copy_resources_to_dut(self): """Copy the apks & xml file needed for the UIAutomator tests.""" if not os.path.exists(self._TMP_LOCATION): os.mkdir(self._TMP_LOCATION) for test_file in self._TEST_FILES: uri = self._TEST_FILES_LOCATION + test_file utils.run('wget -O %s %s' % (os.path.join(self._TMP_LOCATION, test_file), uri)) for test_file in os.listdir(self._TMP_LOCATION): if test_file == 'app-debug.apk': arc.adb_cmd('push %s /data/local/tmp/com.hcl.actframework' % os.path.join(self._TMP_LOCATION, test_file)) arc.adb_shell('pm install -t -r ' '"/data/local/tmp/com.hcl.actframework"') elif test_file == 'app-debug-androidTest.apk': arc.adb_cmd('push %s ' '/data/local/tmp/com.hcl.actframework.test' % os.path.join(self._TMP_LOCATION, test_file)) arc.adb_shell('pm install -t -r ' '"/data/local/tmp/com.hcl.actframework.test"') else: arc.adb_cmd('push %s /sdcard/' % os.path.join(self._TMP_LOCATION, test_file)) if self._touch_view_mode: arc.adb_shell('touch /sdcard/touchView.txt')
def cleanup(self): """Removes the files to play in container.""" for path in self._files_pushed: arc.adb_shell('rm %s' % pipes.quote(path)) self._files_pushed = []
def _set_permission(self): """Grants permissions to Play Music app.""" for permission in self._PLAYMUSIC_PERMISSIONS: arc.adb_shell('pm grant %s android.permission.%s' % ( pipes.quote(self._PLAYMUSIC_PACKAGE), pipes.quote(permission)))
def _delete_file(self): """Removes the recorded file in container.""" arc.adb_shell('rm %s' % pipes.quote(self._MICROPHONE_RECORD_PATH))
def _set_permission(self): """Grants permissions to microphone app.""" for permission in self._MICROPHONE_PERMISSIONS: arc.adb_shell('pm grant %s android.permission.%s' % ( pipes.quote(self._MICROPHONE_PACKAGE), pipes.quote(permission)))
def _grant_storage_permission(self): """Grant the UIAutomator tests storage permission.""" arc.adb_shell('am instrument -w -r -e debug false -e ' '"grant_permissions_only" "Y" ' 'com.hcl.actframework.test/android.support.test.runner' '.AndroidJUnitRunner')
def _get_app_version(self): """Grab the version of the application we are testing.""" self._app_version = arc.adb_shell('dumpsys package %s | grep ' 'versionName| cut -d"=" -f2' % self._pkg_name)
def _launch_Arc_Cam(self): """Grant the Camera location permission, and launch the Camera app.""" arc.adb_shell('pm grant com.google.android.GoogleCameraArc android.permission.ACCESS_COARSE_LOCATION') arc.adb_shell('am start -a android.media.action.IMAGE_CAPTURE')
def _check_cam_status(self): """Returns the specified section from loggcat.""" return [arc.adb_shell("logcat -d | grep 'Camera device'"), arc.adb_shell("logcat -d | grep 'CAMERA_DISABLED'")]
def _start_app(self): """Starts microphone app.""" arc.adb_shell('am start -W %s' % pipes.quote(self._MICROPHONE_ACTIVITY))