mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-03-21 01:59:13 +00:00
Dump hierarchy view on error
Dump window hierarchy view from uiautomator to a file when WA fails during execution. Note: the xml file are pre-formatted after dump. Implementation specific to android.device.
This commit is contained in:
parent
6b65e9ac86
commit
d6afc6d3a1
@ -21,6 +21,7 @@ import time
|
|||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
import threading
|
import threading
|
||||||
|
import xml.dom.minidom
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
from wlauto.core.extension import Parameter
|
from wlauto.core.extension import Parameter
|
||||||
@ -597,12 +598,23 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
|
|||||||
raise DeviceError("Invalid swipe direction: {}".format(self.swipe_to_unlock))
|
raise DeviceError("Invalid swipe direction: {}".format(self.swipe_to_unlock))
|
||||||
|
|
||||||
def capture_screen(self, filepath):
|
def capture_screen(self, filepath):
|
||||||
"""Caputers the current device screen into the specified file in a PNG format."""
|
"""Captures the current device screen into the specified file in a PNG format."""
|
||||||
on_device_file = self.path.join(self.working_directory, 'screen_capture.png')
|
on_device_file = self.path.join(self.working_directory, 'screen_capture.png')
|
||||||
self.execute('screencap -p {}'.format(on_device_file))
|
self.execute('screencap -p {}'.format(on_device_file))
|
||||||
self.pull_file(on_device_file, filepath)
|
self.pull_file(on_device_file, filepath)
|
||||||
self.delete_file(on_device_file)
|
self.delete_file(on_device_file)
|
||||||
|
|
||||||
|
def capture_view_hierachy(self, filepath):
|
||||||
|
"""Captures the current view hierarchy into the specified file in a XML format."""
|
||||||
|
on_device_file = self.path.join(self.working_directory, 'screen_capture.xml')
|
||||||
|
self.execute('uiautomator dump {}'.format(on_device_file))
|
||||||
|
self.pull_file(on_device_file, filepath)
|
||||||
|
self.delete_file(on_device_file)
|
||||||
|
|
||||||
|
parsed_xml = xml.dom.minidom.parse(filepath)
|
||||||
|
with open(filepath, 'w') as f:
|
||||||
|
f.write(parsed_xml.toprettyxml())
|
||||||
|
|
||||||
def is_screen_on(self):
|
def is_screen_on(self):
|
||||||
"""Returns ``True`` if the device screen is currently on, ``False`` otherwise."""
|
"""Returns ``True`` if the device screen is currently on, ``False`` otherwise."""
|
||||||
output = self.execute('dumpsys power')
|
output = self.execute('dumpsys power')
|
||||||
|
@ -494,6 +494,9 @@ class BaseGem5Device(object):
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def capture_view_hierachy(self, filepath):
|
||||||
|
pass # TODO
|
||||||
|
|
||||||
# pylint: disable=W0613
|
# pylint: disable=W0613
|
||||||
def execute(self, command, timeout=1000, check_exit_code=True, background=False,
|
def execute(self, command, timeout=1000, check_exit_code=True, background=False,
|
||||||
as_root=False, busybox=False, **kwargs):
|
as_root=False, busybox=False, **kwargs):
|
||||||
|
@ -882,6 +882,9 @@ class LinuxDevice(BaseLinuxDevice):
|
|||||||
message = e.message.split('OUTPUT:', 1)[1].strip()
|
message = e.message.split('OUTPUT:', 1)[1].strip()
|
||||||
self.logger.debug('Could not take screenshot: {}'.format(message))
|
self.logger.debug('Could not take screenshot: {}'.format(message))
|
||||||
|
|
||||||
|
def capture_view_hierachy(self, filepath):
|
||||||
|
pass # TODO
|
||||||
|
|
||||||
def is_screen_on(self):
|
def is_screen_on(self):
|
||||||
pass # TODO
|
pass # TODO
|
||||||
|
|
||||||
|
@ -318,6 +318,10 @@ class Device(Extension):
|
|||||||
"""Captures the current device screen into the specified file in a PNG format."""
|
"""Captures the current device screen into the specified file in a PNG format."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def capture_view_hierachy(self, filepath):
|
||||||
|
"""Captures the current view hierarchy into the specified file in a XML format."""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def get_properties(self, output_path):
|
def get_properties(self, output_path):
|
||||||
"""Captures and saves the device configuration properties version and
|
"""Captures and saves the device configuration properties version and
|
||||||
any other relevant information. Return them in a dict"""
|
any other relevant information. Return them in a dict"""
|
||||||
|
@ -731,6 +731,13 @@ class Runner(object):
|
|||||||
filepath = os.path.join(settings.output_directory, filename)
|
filepath = os.path.join(settings.output_directory, filename)
|
||||||
self.device.capture_screen(filepath)
|
self.device.capture_screen(filepath)
|
||||||
|
|
||||||
|
def _take_uiautomator_dump(self, filename):
|
||||||
|
if self.context.output_directory:
|
||||||
|
filepath = os.path.join(self.context.output_directory, filename)
|
||||||
|
else:
|
||||||
|
filepath = os.path.join(settings.output_directory, filename)
|
||||||
|
self.device.capture_view_hierachy(filepath)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _handle_errors(self, action, on_error_status=IterationResult.FAILED):
|
def _handle_errors(self, action, on_error_status=IterationResult.FAILED):
|
||||||
try:
|
try:
|
||||||
@ -746,6 +753,7 @@ class Runner(object):
|
|||||||
self.current_job.result.add_event(str(we))
|
self.current_job.result.add_event(str(we))
|
||||||
try:
|
try:
|
||||||
self._take_screenshot('error.png')
|
self._take_screenshot('error.png')
|
||||||
|
self._take_uiautomator_dump('error.xml')
|
||||||
except Exception, e: # pylint: disable=W0703
|
except Exception, e: # pylint: disable=W0703
|
||||||
# We're already in error state, so the fact that taking a
|
# We're already in error state, so the fact that taking a
|
||||||
# screenshot failed is not surprising...
|
# screenshot failed is not surprising...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user