mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-31 07:04:17 +00:00 
			
		
		
		
	fw/execution: add record_ui_state() to context
Add a method to record UI state (take a screen shot, and, for Android devices, dump the UI tree structure) to ExecutionContext.
This commit is contained in:
		
				
					committed by
					
						 Marc Bonnici
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							c0049d0a86
						
					
				
				
					commit
					e93199a0a0
				
			| @@ -16,6 +16,8 @@ | ||||
| # pylint: disable=no-member | ||||
|  | ||||
| import logging | ||||
| import os | ||||
| import shutil | ||||
| from copy import copy | ||||
| from datetime import datetime | ||||
|  | ||||
| @@ -218,6 +220,24 @@ class ExecutionContext(object): | ||||
|     def add_event(self, message): | ||||
|         self.output.add_event(message) | ||||
|  | ||||
|     def take_screenshot(self, filename): | ||||
|         filepath = self._get_unique_filepath(filename) | ||||
|         self.tm.target.capture_screen(filepath) | ||||
|         self.add_artifact('screenshot', filepath, kind='log') | ||||
|  | ||||
|     def take_uiautomator_dump(self, filename): | ||||
|         filepath = self._get_unique_filepath(filename) | ||||
|         self.tm.target.capture_ui_hierarchy(filepath) | ||||
|         self.add_artifact('uitree', filepath, kind='log') | ||||
|  | ||||
|     def record_ui_state(self, basename): | ||||
|         self.logger.info('Recording screen state...') | ||||
|         self.take_screenshot('{}.png'.format(basename)) | ||||
|         target = self.tm.target | ||||
|         if target.os == 'android' or\ | ||||
|            (target.os == 'chromeos' and target.has('android_container')): | ||||
|             self.take_uiautomator_dump('{}.uix'.format(basename)) | ||||
|  | ||||
|     def initialize_jobs(self): | ||||
|         new_queue = [] | ||||
|         failed_ids = [] | ||||
| @@ -243,6 +263,24 @@ class ExecutionContext(object): | ||||
|  | ||||
|         self.job_queue = new_queue | ||||
|  | ||||
|     def _get_unique_filepath(self, filename): | ||||
|         filepath = os.path.join(self.output_directory, filename) | ||||
|         rest, ext = os.path.splitext(filepath) | ||||
|         i = 1 | ||||
|         new_filepath = '{}-{}{}'.format(rest, i, ext) | ||||
|  | ||||
|         if not os.path.exists(filepath) and not os.path.exists(new_filepath): | ||||
|             return filepath | ||||
|         elif not os.path.exists(new_filepath): | ||||
|             # new_filepath does not exit, thefore filepath must exit. | ||||
|             # this is the first collision | ||||
|             shutil.move(filepath, new_filepath) | ||||
|  | ||||
|         while os.path.exists(new_filepath): | ||||
|             i += 1 | ||||
|             new_filepath = '{}-{}{}'.format(rest, i, ext) | ||||
|         return new_filepath | ||||
|  | ||||
|  | ||||
| class Executor(object): | ||||
|     """ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user