Esempio n. 1
0
    def _play(self):

        # Grant app all permissions
        grant_app_permissions(self._target, self.package)

        # Handle media file location
        if not self.from_device:
            remote_file = self._target.path.join(
                self._target.working_directory,
                os.path.basename(self.media_file)
            )

            self._log.info('Pushing media file to device...')
            self._target.push(
                self.media_file,
                remote_file,
                timeout = 60
            )
            self._log.info('Media file transfer complete')
        else:
            remote_file = self.media_file

        # Prepare logcat monitor
        monitor = self._target.get_logcat_monitor(REGEXPS.values())
        monitor.start()

        # Play media file
        play_cmd = 'am start -a "{}" -d "file://{}"'\
                   .format(self.action, remote_file)
        self._log.info(play_cmd)
        self._target.execute(play_cmd)

        monitor.wait_for(REGEXPS['start'])
        self.tracingStart()
        self._log.info('Playing media file')

        line = monitor.wait_for(REGEXPS['duration'])[0]
        media_duration_s = int(round(float(re.search(REGEXPS['duration'], line)
                                   .group('duration'))))

        self._log.info('Media duration is {}'.format(media_duration_s))

        if self.play_duration_s and self.play_duration_s < media_duration_s:
            self._log.info('Waiting {} seconds before ending playback'
                           .format(self.play_duration_s))
            sleep(self.play_duration_s)
        else:
            self._log.info('Waiting for playback completion ({} seconds)'
                           .format(media_duration_s))
            monitor.wait_for(REGEXPS['end'], timeout = media_duration_s + 30)

        self.tracingStop()
        monitor.stop()
        self._log.info('Media file playback completed')

        # Remove file if it was pushed
        if not self.from_device:
            self._target.remove(remote_file)
Esempio n. 2
0
    def _play(self):

        # Grant app all permissions
        grant_app_permissions(self._target, self.package)

        # Handle media file location
        if not self.from_device:
            remote_file = self._target.path.join(
                self._target.working_directory,
                os.path.basename(self.media_file)
            )

            self._log.info('Pushing media file to device...')
            self._target.push(
                self.media_file,
                remote_file,
                timeout = 60
            )
            self._log.info('Media file transfer complete')
        else:
            remote_file = self.media_file

        # Prepare logcat monitor
        monitor = self._target.get_logcat_monitor(REGEXPS.values())
        monitor.start()

        # Play media file
        play_cmd = 'am start -a "{}" -d "file://{}"'\
                   .format(self.action, remote_file)
        self._log.info(play_cmd)
        self._target.execute(play_cmd)

        monitor.wait_for(REGEXPS['start'])
        self.tracingStart()
        self._log.info('Playing media file')

        line = monitor.wait_for(REGEXPS['duration'])[0]
        media_duration_s = int(round(float(re.search(REGEXPS['duration'], line)
                                   .group('duration'))))

        self._log.info('Media duration is {}'.format(media_duration_s))

        if self.play_duration_s and self.play_duration_s < media_duration_s:
            self._log.info('Waiting {} seconds before ending playback'
                           .format(self.play_duration_s))
            sleep(self.play_duration_s)
        else:
            self._log.info('Waiting for playback completion ({} seconds)'
                           .format(media_duration_s))
            monitor.wait_for(REGEXPS['end'], timeout = media_duration_s + 30)

        self.tracingStop()
        monitor.stop()
        self._log.info('Media file playback completed')

        # Remove file if it was pushed
        if not self.from_device:
            self._target.remove(remote_file)
Esempio n. 3
0
    def setup(self, context):
        # Override the default setup method, as it calls
        # self.apk.start_activity. We dont want to do that.

        self.apk.initialize_package(context)
        self.target.execute('am kill-all')  # kill all *background* activities
        grant_app_permissions(self.target, self.package)

        self.target.clear_logcat()

        jclass = '{}.{}'.format(self.package, self.test)
        self.command = 'am instrument -e iterations 1 -e class {} -w {}'.format(
            jclass, self.package)
Esempio n. 4
0
    def setup(self, context):
        # Override the default setup method, as it calls
        # self.apk.start_activity. We dont want to do that.

        self.apk.initialize_package(context)
        self.target.execute('am kill-all')  # kill all *background* activities
        grant_app_permissions(self.target, self.package)

        self.target.clear_logcat()

        jclass = '{}.{}'.format(self.package, self.test)
        self.command = 'am instrument -e iterations 1 -e class {} -w {}'.format(
            jclass, self.package)
Esempio n. 5
0
    def setup(self, context):
        super(ExoPlayer, self).setup(context)

        grant_app_permissions(self.target, self.package)

        self.device_video_file = self.target.path.join(self.target.working_directory,
                                                       os.path.basename(self.host_video_file))
        if self.force_dependency_push or not self.target.file_exists(self.device_video_file):
            self.logger.info('Copying {} to device.'.format(self.host_video_file))
            self.target.push(self.host_video_file, self.device_video_file, timeout=120)

        self._original_orientation = self.target.get_rotation()
        self.target.set_rotation(1 if self.landscape else 0)

        self.play_cmd = 'am start -a {} -d "file://{}"'.format(self.action,
                                                               self.device_video_file)

        self.monitor = self.target.get_logcat_monitor(list(REGEXPS.values()))
        self.monitor.start()
Esempio n. 6
0
    def setup(self, context):
        super(ExoPlayer, self).setup(context)

        grant_app_permissions(self.target, self.package)

        self.device_video_file = self.target.path.join(
            self.target.working_directory,
            os.path.basename(self.host_video_file))
        if self.force_dependency_push or not self.target.file_exists(
                self.device_video_file):
            self.logger.info('Copying {} to device.'.format(
                self.host_video_file))
            self.target.push(self.host_video_file, self.device_video_file)

        self._original_orientation = self.target.get_rotation()
        self.target.set_rotation(1 if self.landscape else 0)

        self.play_cmd = 'am start -a {} -d "file://{}"'.format(
            self.action, self.device_video_file)

        self.monitor = self.target.get_logcat_monitor(list(REGEXPS.values()))
        self.monitor.start()