def check_region(self, region, tag=None, match_timeout=-1, target=None, stitch_content=False): # type: (Region, Optional[Text], int, Optional[Target], bool) -> None """ Takes a snapshot of the given region from the browser using the web driver and matches it with the expected output. If the current context is a frame, the region is offsetted relative to the frame. :param region: The region which will be visually validated. The coordinates are relative to the viewport of the current frame. :param tag: Description of the visual validation checkpoint. :param match_timeout: Timeout for the visual validation checkpoint (milliseconds). :param target: The target for the check_window call :return: None """ logger.info("check_region([%s], '%s')" % (region, tag)) if region.is_empty: raise EyesError("region cannot be empty!") if target is None: target = Target() self._screenshot_type = self._obtain_screenshot_type( is_element=False, inside_a_frame=bool(self._driver.frame_chain), stitch_content=stitch_content, force_fullpage=self.force_full_page_screenshot, is_region=True, ) self._region_to_check = region self._check_window_base(tag, match_timeout, target)
def get_image_part(image, region): # type: (Image.Image, Region) -> Image.Image """ Get a copy of the part of the image given by region. :return: The part of the image. """ if region.is_empty(): raise EyesError('region is empty!') return image.crop(box=(region.left, region.top, region.right, region.bottom))
def reset_origin(self): # type: () -> None """ Reset the origin position to (0, 0). :raise EyesError: Couldn't scroll to position (0, 0). """ self._origin_position_provider.push_state() self._origin_position_provider.set_position(Point(0, 0)) current_scroll_position = self._origin_position_provider.get_current_position() if current_scroll_position.x != 0 or current_scroll_position.y != 0: self._origin_position_provider.pop_state() raise EyesError("Couldn't scroll to the top/left part of the screen!")
def _get_screenshot(self): scale_provider = self._update_scaling_params() if self._screenshot_type == ScreenshotType.ENTIRE_ELEMENT_SCREENSHOT: self._last_screenshot = self._entire_element_screenshot(scale_provider) elif self._screenshot_type == ScreenshotType.FULLPAGE_SCREENSHOT: self._last_screenshot = self._full_page_screenshot(scale_provider) elif self._screenshot_type == ScreenshotType.VIEWPORT_SCREENSHOT: self._last_screenshot = self._viewport_screenshot(scale_provider) elif self._screenshot_type == ScreenshotType.REGION_OR_ELEMENT_SCREENSHOT: self._last_screenshot = self._region_or_screenshot(scale_provider) else: raise EyesError("No proper ScreenshotType obtained") return self._last_screenshot
def __setstate__(self, state): raise EyesError('Cannot create FloatingRegion instance from dict!')