예제 #1
0
 def configuration(self, new_conf):
     argument_guard.is_a(new_conf, SeleniumConfiguration)
     if self._configuration.api_key and not new_conf.api_key:
         new_conf.api_key = self._configuration.api_key
     if self._configuration.server_url and not new_conf.server_url:
         new_conf.server_url = self._configuration.server_url
     self._configuration = new_conf
예제 #2
0
    def check(self, name, check_settings):
        # type: (Text, SeleniumCheckSettings) -> None
        argument_guard.is_a(check_settings, CheckSettings)
        logger.debug("VisualGridEyes.check(%s, %s)" % (name, check_settings))
        self._try_set_target_selector(check_settings)

        self.configure.send_dom = check_settings.values.send_dom

        check_settings = self._update_check_settings(check_settings)
        logger.info("check('{}', check_settings) - begin".format(name))

        region_xpaths = self.get_region_xpaths(check_settings)
        logger.info("region_xpaths: {}".format(region_xpaths))
        script_result = self.get_script_result()
        try:
            for test in self.test_list:
                if self._test_uuid != test.test_uuid:
                    continue
                test.check(
                    tag=name,
                    check_settings=check_settings,
                    script_result=script_result,
                    visual_grid_manager=self.vg_manager,
                    region_selectors=region_xpaths,
                    region_to_check=check_settings.values.target_region,
                    script_hooks=check_settings.values.script_hooks,
                )
                if test.state == "new":
                    test.becomes_not_rendered()
        except Exception as e:
            logger.exception(e)
            self.abort()
            for test in self.test_list:
                test.becomes_tested()
        logger.info("added check tasks  {}".format(check_settings))
예제 #3
0
    def convert_location(self, location, from_, to):
        # type: (Point, CoordinatesType, CoordinatesType) -> Point
        argument_guard.not_none(location)
        argument_guard.not_none(from_)
        argument_guard.not_none(to)

        argument_guard.is_a(location, Point)

        result = location.clone()
        if from_ == to:
            return result

        if from_ == self.SCREENSHOT_AS_IS:
            if to == self.CONTEXT_RELATIVE:
                result = result.offset(self._bounds.left, self._bounds.top)
            else:
                raise CoordinatesTypeConversionError(from_, to)

        elif from_ == self.SCREENSHOT_AS_IS:
            if to == self.CONTEXT_RELATIVE:
                result = result.offset(-self._bounds.left, -self._bounds.top)
            else:
                raise CoordinatesTypeConversionError(from_, to)
        else:
            raise CoordinatesTypeConversionError(from_, to)

        return result
예제 #4
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)
예제 #5
0
 def language(self, language):
     # type: (Text) -> TextRegionSettings
     argument_guard.is_a(language, string_types)
     assert language not in ["eng"], "Unsupported language"
     cloned = self._clone()
     cloned._language = language
     return cloned
예제 #6
0
 def accessibility_validation(self, accessibility_settings):
     # type: (Self, Optional[AccessibilitySettings]) -> None
     if accessibility_settings is None:
         self.self.default_match_settings.accessibility_settings = None
         return
     argument_guard.is_a(accessibility_settings, AccessibilitySettings)
     self.default_match_settings.accessibility_settings = accessibility_settings
예제 #7
0
 def set_configuration(self, configuration):
     # type: (Configuration) -> None
     argument_guard.is_a(configuration, Configuration)
     if self._configuration.api_key and not configuration.api_key:
         configuration.api_key = self._configuration.api_key
     if self._configuration.server_url and not configuration.server_url:
         configuration.server_url = self._configuration.server_url
     self._configuration = configuration
예제 #8
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, dict(width=self._image.width, height=self._image.height)
     )
예제 #9
0
 def accessibility(self, region, type=None):  # noqa
     """Adds one accessibility region."""
     if type:
         argument_guard.is_a(type, AccessibilityRegionType)
     try:
         self.values.accessibility_regions.append(
             self._accessibility_provider_from(region, type))
     except TypeError as e:
         raise_from(TypeError("Wrong argument in .accessibility()"), e)
     return self
예제 #10
0
    def check(self, check_settings):
        # type: (SeleniumCheckSettings) -> None
        argument_guard.is_a(check_settings, CheckSettings)
        name = check_settings.values.name
        self.logger.debug("VisualGridEyes.check",
                          name=name,
                          check_settings=check_settings)
        self._try_set_target_selector(check_settings)

        self.configure.send_dom = check_settings.values.send_dom

        check_settings = self._update_check_settings(check_settings)
        self.logger.info("check begin", name=name)

        region_xpaths = self.get_region_xpaths(check_settings)
        self.logger.info("check region xpaths", region_xpaths=region_xpaths)
        dont_fetch_resources = self._effective_disable_browser_fetching(
            self.configure, check_settings)
        running_tests = [
            test for test in self.test_list
            if self._test_uuid == test.test_uuid
        ]

        try:
            script_result = self.get_script_result(dont_fetch_resources)
            self.logger.debug(
                "Got script result",
                cdt_len=len(script_result["cdt"]),
                blob_urls=[b["url"] for b in script_result["blobs"]],
                resource_urls=script_result["resourceUrls"],
            )
            source = eyes_selenium_utils.get_check_source(self.driver)
            checks = [
                test.check(
                    check_settings=check_settings,
                    region_selectors=region_xpaths,
                    source=source,
                ) for test in running_tests
            ]

            resource_collection_task = self._resource_collection_task(
                check_settings, region_xpaths, running_tests, script_result,
                checks)
            self.vg_manager.add_resource_collection_task(
                resource_collection_task)
        except Exception:
            self.logger.exception("Check failure")
            for test in running_tests:
                if test.state != TESTED:
                    # already aborted or closed
                    test.abort()
                    test.becomes_tested()
        self.logger.info("added check tasks", check_settings=check_settings)
예제 #11
0
    def check(self, check_settings):
        # type: (SeleniumCheckSettings) -> None
        argument_guard.is_a(check_settings, CheckSettings)
        name = check_settings.values.name
        logger.debug("VisualGridEyes.check(%s, %s)" % (name, check_settings))
        self._try_set_target_selector(check_settings)

        self.configure.send_dom = check_settings.values.send_dom

        check_settings = self._update_check_settings(check_settings)
        logger.info("check('{}', check_settings) - begin".format(name))

        region_xpaths = self.get_region_xpaths(check_settings)
        logger.info("region_xpaths: {}".format(region_xpaths))
        dont_fetch_resources = self._effective_disable_browser_fetching(
            self.configure, check_settings)
        running_tests = [
            test for test in self.test_list
            if self._test_uuid == test.test_uuid
        ]

        try:
            script_result = self.get_script_result(dont_fetch_resources)

            logger.debug("Cdt length: {}".format(len(script_result["cdt"])))
            logger.debug("Blobs urls: {}".format(
                [b["url"] for b in script_result["blobs"]]))
            logger.debug("Resources urls: {}".format(
                script_result["resourceUrls"]))
            source = eyes_selenium_utils.get_check_source(self.driver)

            for test in running_tests:
                test.check(
                    tag=name,
                    check_settings=check_settings,
                    script_result=script_result,
                    visual_grid_manager=self.vg_manager,
                    region_selectors=region_xpaths,
                    region_to_check=check_settings.values.target_region,
                    script_hooks=check_settings.values.script_hooks,
                    source=source,
                )
                if test.state == "new":
                    test.becomes_not_rendered()
        except Exception as e:
            logger.exception(e)
            for test in running_tests:
                if test.state != "tested":
                    # already aborted or closed
                    test.abort()
                    test.becomes_tested()
        logger.info("added check tasks  {}".format(check_settings))
    def check(self, name, check_settings):
        # type: (Text, SeleniumCheckSettings) -> bool
        if self.configuration.is_disabled:
            return False
        argument_guard.is_a(check_settings, CheckSettings)
        logger.debug("VisualGridEyes.check(%s, %s)" % (name, check_settings))
        self._try_set_target_selector(check_settings)

        self.configuration.send_dom = check_settings.values.send_dom

        size_mode = check_settings.values.size_mode
        if size_mode is None:
            if self.configuration.force_full_page_screenshot:
                check_settings.values.size_mode = "full-page"

        logger.info("check('{}', check_settings) - begin".format(name))

        # region_xpaths = self.get_region_xpaths(check_settings)
        region_xpaths = []
        self.region_to_check = None
        # logger.info("region_xpaths: {}".format(region_xpaths))
        script_result = self.get_script_result()
        try:
            for test in self.test_list:
                test.check(
                    tag=name,
                    check_settings=check_settings,
                    script_result=script_result,
                    visual_grid_manager=self.vg_manager,
                    region_selectors=region_xpaths,
                    size_mode=size_mode,
                    region_to_check=self.region_to_check,
                )
                if test.state == "new":
                    test.becomes_not_rendered()
        except Exception as e:
            logger.exception(e)
            for test in self.test_list:
                test.becomes_tested()
        logger.info("added check tasks  {}".format(check_settings))
예제 #13
0
    def check_frame_by_index(
            self,
            frame_index,  # type: int
            tag=None,  # type: Optional[Text]
            *check_settings_keywords  # type: tuple[Any]
    ):
        # type: (...) -> MatchResult
        """
         Check specified frame by index

            | =Arguments=     | =Description=                                                       |
            |  Frame Index    | *Mandatory* - Index of the frame to check. |

        *Example:*
            |  Eyes Check Frame By Index  |  2  |
        """
        argument_guard.is_a(frame_index, int)
        check_settings_keywords, tag = try_resolve_tag_and_keyword(
            tag, check_settings_keywords, self.defined_keywords)
        check_settings = collect_check_settings(Target.frame(frame_index),
                                                self.defined_keywords,
                                                *check_settings_keywords)
        return self.current_eyes.check(check_settings, tag)
예제 #14
0
    def check_frame_by_selector(
            self,
            selector,  # type: Text
            tag=None,  # type: Optional[Text]
            *check_settings_keywords  # type: tuple[Any]
    ):
        # type: (...) -> MatchResult
        """
         Check specified frame by name

            |  =Arguments=   | =Description=                                  |
            |  Selector     | *Mandatory* - Selector of the frame to check.   |

        *Example:*
            |  Eyes Check Frame By Selector  |  css:#selector   |
        """
        argument_guard.is_a(selector, basestring)
        check_settings_keywords, tag = try_resolve_tag_and_keyword(
            tag, check_settings_keywords, self.defined_keywords)
        check_settings = collect_check_settings(
            Target.frame(self.from_locator_to_supported_form(selector)),
            self.defined_keywords, *check_settings_keywords)
        return self.current_eyes.check(check_settings, tag)
예제 #15
0
    def check_frame_by_name(
            self,
            frame_name,  # type: Text
            tag=None,  # type: Optional[Text]
            *check_settings_keywords  # type: tuple[Any]
    ):
        # type: (...) -> MatchResult
        """
         Check specified frame by name

            |  =Arguments=   | =Description=                                   |
            |  Frame Name    | *Mandatory* - Name of the frame to check.      |

        *Example:*
            |  Eyes Check Frame By Name  |  frameName  |
        """
        argument_guard.is_a(frame_name, basestring)
        check_settings_keywords, tag = try_resolve_tag_and_keyword(
            tag, check_settings_keywords, self.defined_keywords)
        check_settings = collect_check_settings(Target.frame(frame_name),
                                                self.defined_keywords,
                                                *check_settings_keywords)
        return self.current_eyes.check(check_settings, tag)
예제 #16
0
    def normalize_rotation(driver, image, rotation):
        # type: (WebDriver, Image, Optional[int]) -> Image
        """
        Rotates the image as necessary. The rotation is either manually forced
        by passing a non-null rotation, or automatically inferred.

        :param driver: The underlying driver which produced the screenshot.
        :param image: The image to normalize.
        :param rotation: The degrees by which to rotate the image:
                         positive values = clockwise rotation,
                         negative values = counter-clockwise,
                         0 = force no rotation,
                         null = rotate automatically as needed.
        :return: A normalized image.
        """
        argument_guard.not_none(driver)
        argument_guard.not_none(image)
        normalized_image = image
        if rotation and rotation != 0:
            argument_guard.is_a(rotation, int)
            normalized_image = image_utils.rotate_image(image, rotation)
        else:  # Do automatic rotation if necessary
            try:
                logger.info("Trying to automatically normalize rotation...")
                if (eyes_selenium_utils.is_mobile_app(driver) and
                        eyes_selenium_utils.is_landscape_orientation(driver)
                        and image.height > image.width):
                    # For Android, we need to rotate images to the right,
                    # and for iOS to the left.
                    degree = 90 if eyes_selenium_utils.is_android(
                        driver) else -90
                    normalized_image = image_utils.rotate_image(image, degree)
            except Exception as e:
                logger.exception(e)
                logger.info("Skipped automatic rotation handling.")
        return normalized_image
예제 #17
0
 def name(name):
     # type: (Text) -> VisualLocatorSettings
     argument_guard.is_a(name, basestring)
     return VisualLocatorSettings(name)
예제 #18
0
 def name(self, name):
     # type: (Text) -> VisualLocatorSettings
     argument_guard.is_a(name, basestring)
     cloned = self.clone()
     cloned.values.names.append(name)
     return cloned
예제 #19
0
 def server_connector(self, server_connector):
     # type: (ServerConnector) -> None
     argument_guard.is_a(server_connector, ServerConnector)
     self._server_connector = server_connector
예제 #20
0
 def eyes_runner(self, runner):
     # type: (EyesRunner) -> None
     argument_guard.is_a(runner, (ClassicRunner, VisualGridRunner))
     self._eyes_runner = runner
예제 #21
0
 def rotation(self, rotation):
     # type: (int) -> None
     argument_guard.is_a(rotation, int)
     if self._selenium_eyes and self.driver:
         self.driver.rotation = rotation
예제 #22
0
 def locate(self, visual_locator_settings):
     # type: (VisualLocatorSettings) -> LOCATORS_TYPE
     argument_guard.is_a(visual_locator_settings, VisualLocatorSettings)
     logger.info("locate({})".format(visual_locator_settings))
     return self._visual_locators_provider.get_locators(
         visual_locator_settings)
예제 #23
0
 def set_batch(self, batch):
     # type: (Self, BatchInfo) -> Self
     argument_guard.is_a(batch, BatchInfo)
     self.batch = batch
     return self
예제 #24
0
 def set_proxy(self, proxy):
     # type: (ProxySettings) -> BatchClose
     argument_guard.is_a(proxy, ProxySettings)
     self.proxy = proxy
     return self
 def extract_text_regions(self, config):
     # type: (TextRegionSettings) -> PATTERN_TEXT_REGIONS
     argument_guard.not_none(self._extract_text_provider)
     argument_guard.is_a(config, TextRegionSettings)
     logger.info("extract_text_regions", config=config)
     return self._extract_text_provider.get_text_regions(config)
예제 #26
0
 def set_proxy(self, proxy):
     # type: (Optional[ProxySettings]) -> Self
     argument_guard.is_a(proxy, ProxySettings)
     self.proxy = proxy
     return self