Beispiel #1
0
    def _check_full_frame_or_element(self, name, check_settings):
        self._check_frame_or_element = True

        def full_frame_or_element_region(check_settings):
            logger.debug("check_frame_or_element: {}".format(
                self._check_frame_or_element))
            if self._check_frame_or_element:
                fc = self._ensure_frame_visible()
                # FIXME - Scaling should be handled in a single place instead
                scale_factory = self._update_scaling_params()
                screenshot_image = self._image_provider.get_image()
                scale_factory.update_scale_ratio(screenshot_image.width)
                self.driver.switch_to.frames(fc)
                screenshot = EyesWebDriverScreenshot.create_viewport(
                    self.driver, screenshot_image)
                # TODO HERE
                logger.debug("replacing region_to_check")
                self._region_to_check = screenshot.frame_window
                self._full_region_to_check = Region.EMPTY()

            target_region = check_settings.values.target_region
            if target_region is None:
                target_region = Region.EMPTY()
            return target_region

        result = self._check_window_base(
            RegionProvider(
                lambda: full_frame_or_element_region(check_settings)),
            name,
            False,
            check_settings,
        )
        self._check_frame_or_element = False
        self._region_to_check = None
        return result
Beispiel #2
0
    def _check_region(self, name, check_settings):
        self._is_check_region = True

        def get_region():
            rect = check_settings.values.target_region
            if rect is None:
                if self.driver.is_mobile_platform:
                    bounds = self._target_element.rect
                else:
                    bounds = self._target_element.bounding_client_rect
                region = Region(
                    bounds["x"],
                    bounds["y"],
                    bounds["width"],
                    bounds["height"],
                    coordinates_type=CoordinatesType.CONTEXT_RELATIVE,
                )
            else:
                s = self._target_element.size_and_borders.size
                b = self._target_element.size_and_borders.borders
                p = Point.from_(self._target_element.location)
                p = p.offset(b["left"], b["top"])

                x = p.x + rect.left
                y = p.y + rect.top
                w = min(p.x + s["width"], rect.right) - x
                h = min(p.y + s["height"], rect.bottom) - y
                region = Region(x, y, w, h, CoordinatesType.CONTEXT_RELATIVE)
            return region

        result = self._check_window_base(RegionProvider(get_region), name,
                                         False, check_settings)
        self._is_check_region = False
        return result
 def _check_full_frame_or_element(self, name, check_settings):
     self._check_frame_or_element = True
     resutl = self._check_window_base(
         RegionProvider(self._full_frame_or_element_region),
         name,
         False,
         check_settings,
     )
     self._check_frame_or_element = False
     self._region_to_check = None
     return resutl
Beispiel #4
0
 def _check_result_flow(self, name, check_settings, source):
     target_region = check_settings.values.target_region
     result = None
     if target_region and self._switched_to_frame_count == 0:
         logger.debug("have target region")
         target_region = target_region.clone()
         target_region.coordinates_type = CoordinatesType.CONTEXT_RELATIVE
         result = self._check_window_base(
             RegionProvider(target_region), name, False, check_settings, source
         )
     elif check_settings:
         target_element = self._element_from(check_settings)
         total_frames = len(check_settings.values.frame_chain)
         if self.configure.is_feature_activated(
             Feature.TARGET_WINDOW_CAPTURES_SELECTED_FRAME
         ):
             total_frames += self.driver.frame_chain.size
         if target_element:
             logger.debug("have target element")
             self._target_element = target_element
             if self._stitch_content:
                 result = self._check_element(name, check_settings, source)
             else:
                 result = self._check_region(name, check_settings, source)
             self._target_element = None
         elif total_frames > 0:
             logger.debug("have frame chain")
             if self._stitch_content:
                 result = self._check_full_frame_or_element(
                     name, check_settings, source
                 )
             else:
                 result = self._check_frame_fluent(name, check_settings, source)
         else:
             logger.debug("default case")
             if not self.driver.is_mobile_app:
                 # required to prevent cut line on the last stitched part of the
                 # page on some browsers (like firefox).
                 self.driver.switch_to.default_content()
                 self._current_frame_position_provider = (
                     self._create_position_provider(
                         self.driver.find_element_by_tag_name("html")
                     )
                 )
             result = self._check_window_base(
                 NULL_REGION_PROVIDER,
                 name,
                 False,
                 check_settings,
                 source,
             )
     if result is None:
         result = MatchResult()
     return result
    def _check_region(self, name, check_settings):
        self._is_check_region = True

        def get_region():
            location = self._target_element.location
            size = self._target_element.size
            return Region(
                location["x"],
                location["y"],
                size["width"],
                size["height"],
                coordinates_type=CoordinatesType.CONTEXT_RELATIVE,
            )

        result = self._check_window_base(RegionProvider(get_region), name,
                                         False, check_settings)
        self._is_check_region = False
        return result
    def _check_result_flow(self, check_settings, source):
        target_region = check_settings.values.target_region
        result = None
        if target_region and self._switched_to_frame_count == 0:
            logger.debug("have target region")
            target_region = target_region.clone()
            target_region.coordinates_type = CoordinatesType.CONTEXT_RELATIVE
            result = self._check_window_base(RegionProvider(target_region),
                                             False, check_settings, source)
        elif check_settings:
            target_element = self._element_from(check_settings)
            total_frames = len(check_settings.values.frame_chain)
            if self.configure.is_feature_activated(
                    Feature.TARGET_WINDOW_CAPTURES_SELECTED_FRAME):
                total_frames += self.driver.frame_chain.size
            if target_element:
                logger.debug("have target element")
                self._target_element = target_element
                if self._stitch_content:
                    result = self._check_full_element(check_settings, source)
                else:
                    result = self._check_element(check_settings, source)
                self._target_element = None
            elif total_frames > 0:
                logger.debug("have frame chain")
                if self._stitch_content:
                    result = self._check_full_frame(check_settings, source)
                else:
                    logger.debug("Target.Frame(frame).Fully(false)")
                    logger.debug(
                        "WARNING: This shouldn't have been called, as it is covered "
                        "by `check_element(...)` ")
                    result = self._check_frame(check_settings, source)
            else:
                if self._stitch_content:
                    self._check_full_window(check_settings, source)
                else:
                    self._check_window(check_settings, source)

        if result is None:
            result = MatchResult()
        return result
 def _check_result_flow(self, name, check_settings):
     target_region = check_settings.values.target_region
     result = None
     if target_region:
         logger.debug("have target region")
         target_region = target_region.clone()
         target_region.coordinates_type = CoordinatesType.CONTEXT_RELATIVE
         result = self._check_window_base(RegionProvider(target_region),
                                          name, False, check_settings)
     elif check_settings:
         target_element = self._element_from(check_settings)
         if target_element:
             logger.debug("have target element")
             self._target_element = target_element
             if self._stitch_content:
                 result = self._check_element(name, check_settings)
             else:
                 result = self._check_region(name, check_settings)
             self._target_element = None
         elif len(check_settings.values.frame_chain) > 0:
             logger.debug("have frame chain")
             if self._stitch_content:
                 result = self._check_full_frame_or_element(
                     name, check_settings)
             else:
                 result = self._check_frame_fluent(name, check_settings)
         else:
             logger.debug("default case")
             if not self.driver.is_mobile_platform:
                 # required to prevent cut line on the last stitched part of the
                 # page on some browsers (like firefox).
                 self.driver.switch_to.default_content()
                 self.current_frame_position_provider = self._create_position_provider(
                     self.driver.find_element_by_tag_name("html"))
             result = self._check_window_base(NULL_REGION_PROVIDER, name,
                                              False, check_settings)
     if result is None:
         result = MatchResult()
     return result