1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import os 6 7 from autotest_lib.client.cros.graphics import graphics_utils 8 from autotest_lib.client.cros.video import method_logger 9 10 11 class ImportScreenShotCapturer(object): 12 """ 13 Captures a screenshot with the required dimensions from a chromebook. 14 15 Uses utility capture but specifies the geometry/dimensions of final image. 16 17 We need this so that we can chop off things like browser address bar and 18 system task bar that are not only irrelevant to the test but would also add 19 noise to the test. 20 21 """ 22 23 24 @method_logger.log 25 def __init__(self, destination_dir, screen_height_resolution, 26 top_pixels_to_crop, bottom_pixels_to_crop): 27 self.destination_dir = destination_dir 28 self.screen_height_resolution = screen_height_resolution 29 self.top_pixels_to_crop = top_pixels_to_crop 30 self.bottom_pixels_to_crop = bottom_pixels_to_crop 31 32 33 def __enter__(self): 34 return self 35 36 37 @method_logger.log 38 def capture(self, filename): 39 """ 40 Capture the screenshot. 41 42 Use pre-configured information to create a geometry that specifies the 43 final dimension and position of the image. 44 45 @param filename: string, the screenshot filename. 46 47 @returns a complete path to the screenshot generated. 48 49 """ 50 fullpath = os.path.join(self.destination_dir, filename) 51 52 final_height = (self.screen_height_resolution - 53 self.top_pixels_to_crop - self.bottom_pixels_to_crop) 54 55 graphics_utils.take_screenshot_crop_by_height(fullpath, 56 final_height, 57 0, 58 self.top_pixels_to_crop) 59 60 return fullpath 61 62 63 def __exit__(self, exc_type, exc_val, exc_tb): 64 pass 65