def capture_screenshot(self, filepath): """ Take a screenshot of the App Launcher page. Implements the abstract method capture_screenshot @param filepath: string, Complete path to save the screenshot to. """ # Login and load the default apps with chrome.Chrome(disable_default_apps=False): # Setup the keyboard file's paths property_file = os.path.join(self.bindir, self._KEYBOARD_PROP) playback_file = os.path.join(self.bindir, self._KEYBOARD_PLAYBACK) # Setup and playback the keyboard commands to open the launcher with input_playback.InputPlayback() as player: player.emulate('keyboard', property_file) player.find_connected_inputs() player.blocking_playback(playback_file, 'keyboard') # Take a screenshot and crop to just the launcher w, h = graphics_utils.get_internal_resolution() upper_x = (w - self.launcher_width) / 2 upper_y = (h - self.launcher_height) / 2 box = (upper_x, upper_y, upper_x + self.launcher_width, upper_y + self.launcher_height) graphics_utils.take_screenshot_crop(filepath, box)
def take_screenshot_crtc(self, path, id): """Captures the DUT screenshot, use id for selecting screen. @param path: path to image file. @param id: The id of the crtc to screenshot. """ graphics_utils.take_screenshot_crop(path, crtc_id=id) return True
def capture_screenshot(self, filepath): """ Sets the portion of the screenshot to crop. Calls into take_screenshot_crop to take the screenshot and crop it. self.logged_in controls which logged-in state we are testing when we take the screenshot. if None, we don't login at all if True, we login as the test user if False, we login as guest For the logged in user we mask the profile photo so that the randomly generated profile pictures don't break the tests. @param filepath: path, fullpath to where the screenshot will be saved to """ w, h = graphics_utils.get_display_resolution() box = (w - self.width, h - self.height, w, h) if self.logged_in is None: graphics_utils.take_screenshot_crop(filepath, box) return with chrome.Chrome(logged_in=self.logged_in): # set up a pixel comparer image_name = os.path.splitext(filepath)[0] temp_file_path = '%s_temp.png' % image_name comparer = rgb_image_comparer.RGBImageComparer( rgb_pixel_threshold=0) def has_animation_stopped(): """ Takes two screenshots. Checks if they are identical to indicate the shelf has stop animating. """ graphics_utils.take_screenshot_crop(filepath, box) graphics_utils.take_screenshot_crop(temp_file_path, box) diff = comparer.compare(filepath, temp_file_path) logging.debug("Pixel diff count: %d", diff.diff_pixel_count) return diff.diff_pixel_count == 0 # crbug.com/476791 error when take screenshots too soon after login time.sleep(30) utils.poll_for_condition(has_animation_stopped, timeout=30, desc='end of system tray animation') if self.logged_in and self.mask_points is not None: self.draw_image_mask(filepath, self.mask_points)
def has_animation_stopped(): """ Takes two screenshots. Checks if they are identical to indicate the shelf has stop animating. """ graphics_utils.take_screenshot_crop(filepath, box) graphics_utils.take_screenshot_crop(temp_file_path, box) diff = comparer.compare(filepath, temp_file_path) logging.debug("Pixel diff count: %d", diff.diff_pixel_count) return diff.diff_pixel_count == 0