예제 #1
0
    def _full_page_screenshot(self, scale_provider):
        # type: (ScaleProvider) -> EyesWebDriverScreenshot
        logger.info("Full page screenshot requested")
        original_fc = self.driver.frame_chain.clone()
        if original_fc.size > 0:
            original_frame_position = original_fc.default_content_scroll_position
        else:
            original_frame_position = Point.ZERO()

        with self.driver.switch_to.frames_and_back(self._original_fc):
            scroll_root_element = eyes_selenium_utils.curr_frame_scroll_root_element(
                self.driver)
            origin_provider = ScrollPositionProvider(self.driver,
                                                     scroll_root_element)
            origin_provider.set_position(Point.ZERO())
            logger.debug("resetting origin_provider location")

            location = self.scroll_root_element.location
            size_and_borders = self.scroll_root_element.size_and_borders
            region = Region(
                location["x"] + size_and_borders.borders["left"],
                location["y"] + size_and_borders.borders["top"],
                size_and_borders.size["width"],
                size_and_borders.size["height"],
            )

            algo = self._create_full_page_capture_algorithm(scale_provider)
            image = algo.get_stitched_region(region, Region.EMPTY(),
                                             self.position_provider)

            return EyesWebDriverScreenshot.create_full_page(
                self._driver, image, original_frame_position)
예제 #2
0
 def __init__(self, image, location=None):
     super(EyesImagesScreenshot, self).__init__(image)
     if location is None:
         location = Point.ZERO()
     argument_guard.is_a(location, Point)
     self._location = location
     self._bounds = Region.from_(location, self.image)
예제 #3
0
    def _ensure_frame_visible(self):
        logger.debug("scroll_root_element_: {}".format(self._scroll_root_element))
        current_fc = self.driver.frame_chain.clone()
        fc = self.driver.frame_chain.clone()
        self.driver.execute_script("window.scrollTo(0,0);")
        origin_driver = eyes_selenium_utils.get_underlying_driver(self.driver)

        while len(fc) > 0:
            logger.debug("fc count: {}".format(fc.size))
            self.driver.switch_to.parent_frame_static(origin_driver.switch_to, fc)
            self.driver.execute_script("window.scrollTo(0,0);")
            child_frame = fc.pop()
            parent_frame = fc.peek
            scroll_root_element = None
            if fc.size == self._original_fc.size:
                logger.debug("PositionProvider: {}".format(self.position_provider))
                self._position_memento = self.position_provider.get_state()
                scroll_root_element = self._scroll_root_element
            else:
                if parent_frame:
                    scroll_root_element = parent_frame.scroll_root_element
                if not scroll_root_element:
                    scroll_root_element = self.driver.find_element_by_tag_name("html")
            logger.debug("scroll_root_element {}".format(scroll_root_element))

            position_provider = self._element_position_provider_from(
                scroll_root_element
            )
            position_provider.set_position(child_frame.location)
            reg = Region.from_(Point.ZERO(), child_frame.inner_size)
            self._effective_viewport.intersect(reg)
        self.driver.switch_to.frames(current_fc)
        return current_fc
예제 #4
0
def collect_regions_from_selectors(image_match_settings, regions,
                                   region_selectors):
    # type:(ImageMatchSettings,List[Region],List[List[VisualGridSelector]])->ImageMatchSettings
    if not regions:
        return image_match_settings

    mutable_regions = [
        [],  # Ignore Regions
        [],  # Layout Regions
        [],  # Strict Regions
        [],  # Content Regions
        [],  # Floating Regions
        [],  # Target Element Location
    ]
    r_selector_counts = [len(r) for r in region_selectors]  # mapping of
    prev_count = 0
    for selectors_count, m_specific_regions in zip(r_selector_counts,
                                                   mutable_regions):
        if selectors_count == 0:
            continue
        next_count = prev_count + selectors_count
        m_specific_regions.extend(regions[prev_count:next_count])
        prev_count = next_count

    location = Point.ZERO()

    # If target element location available
    selector_regions_index = len(mutable_regions) - 1
    if mutable_regions[selector_regions_index]:
        location = mutable_regions[selector_regions_index][0].location

    image_match_settings.ignore_regions = filter_empty_entries(
        mutable_regions[0], location)
    image_match_settings.layout_regions = filter_empty_entries(
        mutable_regions[1], location)
    image_match_settings.strict_regions = filter_empty_entries(
        mutable_regions[2], location)
    image_match_settings.content_regions = filter_empty_entries(
        mutable_regions[3], location)

    floating_match_settings = []
    for i, reg in enumerate(mutable_regions[4]):
        if reg.area == 0:
            continue
        vgs = region_selectors[4][i]
        gfr = vgs.category
        if isinstance(gfr, GetFloatingRegion):
            fms = FloatingMatchSettings(reg, gfr.bounds)
            floating_match_settings.append(fms)
    image_match_settings.floating_match_settings = floating_match_settings
    return image_match_settings
def collect_regions_from_selectors(image_match_settings, regions,
                                   region_selectors):
    # type:(ImageMatchSettings,List[Region],List[List[VisualGridSelector]])->ImageMatchSettings
    if not regions:
        return image_match_settings
    logger.debug("""
    start collect_regions_from_selectors()

        regions: {}
        region_selectors: {}
    """.format(regions, region_selectors))
    mutable_regions = [
        [],  # Ignore Regions
        [],  # Layout Regions
        [],  # Strict Regions
        [],  # Content Regions
        [],  # Floating Regions
        [],  # Accessibility Regions
        [],  # Target Element Location
    ]
    r_selector_counts = [len(r) for r in region_selectors]  # mapping of
    prev_count = 0
    for i, (selectors_count, m_specific_regions) in enumerate(
            zip(r_selector_counts, mutable_regions)):
        if selectors_count == 0:
            continue
        next_count = prev_count + selectors_count
        for region_selector, region in zip(region_selectors[i],
                                           regions[prev_count:next_count]):
            padding = getattr(region_selector.category, "padding", None)
            if padding:
                region = region.padding(padding)
            m_specific_regions.append(region)
        prev_count = next_count

    location = Point.ZERO()

    # If target element location available
    selector_regions_index = len(mutable_regions) - 1
    if mutable_regions[selector_regions_index]:
        location = mutable_regions[selector_regions_index][0].location

    image_match_settings.ignore_regions = filter_empty_entries(
        mutable_regions[0], location)
    image_match_settings.layout_regions = filter_empty_entries(
        mutable_regions[1], location)
    image_match_settings.strict_regions = filter_empty_entries(
        mutable_regions[2], location)
    image_match_settings.content_regions = filter_empty_entries(
        mutable_regions[3], location)
    image_match_settings.floating_match_settings = [
        FloatingMatchSettings(reg, gfr.floating_bounds)
        for (reg, gfr) in filter_empty_entries_and_combine(
            mutable_regions[4], location, region_selectors[4])
        if isinstance(gfr, GetFloatingRegion)
    ]
    image_match_settings.accessibility = [
        AccessibilityRegion.from_(reg, gfr.accessibility_type)
        for (reg, gfr) in filter_empty_entries_and_combine(
            mutable_regions[5], location, region_selectors[5])
        if isinstance(gfr, GetAccessibilityRegion)
    ]
    logger.debug("""
    finish collect_regions_from_selectors()

        image_match_settings: {}
    """.format(image_match_settings))
    return image_match_settings