Exemple #1
0
    def ignore_region_by_coordinates(self, left, top, width, height, target=None):
        """
        Returns a Target object that ignores the region specified in the arguments.
        See `Defining Ignore and Floating Regions`.

            | =Arguments=     | =Description=                                                                                    |
            | Left (float)    | *Mandatory* - The left coordinate of the region to ignore e.g. 100                               |
            | Top (float)     | *Mandatory* - The top coordinate of the region to ignore e.g. 150                                |
            | Width (float)   | *Mandatory* - The width of the region to ignore e.g. 500                                         |
            | Height (float)  | *Mandatory* - The height of the region to ignore e.g. 120                                        |
            | Target (Target) | The previously existent Target, to be used if a ignore region or floating region was already set |
                
        *Example:*
            | ${target}=        | Ignore Region By Coordinates | 10               | 20 | 100 | 100 |
            | Check Eyes Window | Google Homepage              | target=${target} |

        """

        if target is None:
            target = Target()

        ignore_region = Region(float(left), float(top), float(width), float(height))
        target.ignore(ignore_region)

        return target
Exemple #2
0
    def _create_match_data_bytes(
            self,
            app_output,  # type: AppOutput
            user_inputs,  # type: UserInputs
            tag,  # type: tp.Text
            ignore_mismatch,  # type: bool
            screenshot,  # type: EyesScreenshot
            default_match_settings,  # type: ImageMatchSettings
            target,  # type: Target
            ignore=None,  # type: tp.Optional[tp.List]
            floating=None,  # type: tp.Optional[tp.List]
    ):
        # type: (...) -> bytes
        if ignore is None:
            ignore = []
        if floating is None:
            floating = []
        if target is None:
            from applitools.selenium.target import Target  # noqa
            target = Target()

        match_data = {
            "IgnoreMismatch": ignore_mismatch,
            "Options": {
                "Name": tag,
                "UserInputs": user_inputs,
                "ImageMatchSettings": {
                    "MatchLevel":
                    default_match_settings.match_level,
                    "IgnoreCaret":
                    target.get_ignore_caret(),
                    "Exact":
                    default_match_settings.exact_settings,
                    "Ignore":
                    ignore,
                    "Floating":
                    floating,
                    "UseDom":
                    self._eyes.use_dom or target._use_dom,
                    "EnablePatterns":
                    self._eyes.enable_patterns or target._enable_patterns
                },
                "IgnoreMismatch": ignore_mismatch,
                "Trim": {
                    "Enabled": False
                }
            },
            "UserInputs": user_inputs,
            "AppOutput": app_output,
            "tag": tag
        }
        match_data_json_bytes = general_utils.to_json(match_data).encode(
            'utf-8')
        match_data_size_bytes = pack(">L", len(match_data_json_bytes))
        screenshot_bytes = screenshot.get_bytes()
        body = match_data_size_bytes + match_data_json_bytes + screenshot_bytes
        return body
Exemple #3
0
    def floating_region_by_coordinates(
        self,
        left,
        top,
        width,
        height,
        max_left_offset=0,
        max_top_offset=0,
        max_right_offset=0,
        max_down_offset=0,
        target=None,
    ):
        """
        Returns a Target object that includes the floating region specified in the arguments.
        See `Defining Ignore and Floating Regions`

            | =Arguments=            | =Description=                                                                                    |
            | Left (float)           | *Mandatory* - The left coordinate of the floating region e.g. 100                                |
            | Top (float)            | *Mandatory* - The top coordinate of the floating region e.g. 150                                 |
            | Width (float)          | *Mandatory* - The width of the floating region e.g. 500                                          |
            | Height (float)         | *Mandatory* - The height of the floating region e.g. 120                                         |
            | Max Left Offset (int)  | The amount the floating region may move to the left. e.g. 10                                     |
            | Max Top Offset (int)   | The amount the floating region may moveupwards. e.g. 20                                          |
            | Max Right Offset (int) | The amount the floating region may move to the right. e.g. 10                                    |
            | Max Down Offset (int)  | The amount the floating region may move downwards. e.g. 50                                       |
            | Target (Target)        | The previously existent Target, to be used if a ignore region or floating region was already set |
                
        *Example:*
            | ${target}=    Floating Region By Coordinates |  10              | 10               | 200 | 150 | 10 | 0 | 50 | 50 | 
            | Check Eyes Window                            |  Google Homepage | target=${target} |
        """

        if target is None:
            target = Target()

        region = Region(float(left), float(top), float(width), float(height))
        floating_bounds = FloatingBounds(
            int(max_left_offset),
            int(max_top_offset),
            int(max_right_offset),
            int(max_down_offset),
        )
        floating_region = FloatingRegion(region, floating_bounds)
        target.floating(floating_region)

        return target
Exemple #4
0
    def floating_region_by_selector(
        self,
        value,
        selector="id",
        max_left_offset=0,
        max_top_offset=0,
        max_right_offset=0,
        max_down_offset=0,
        target=None,
    ):
        """
        Returns a Target object that includes the floating region containing the element specified in the arguments by selector and value.
        See `Defining Ignore and Floating Regions` and `Using Selectors`.

            | =Arguments=            | =Description=                                                                                                |
            | Value (str)            | *Mandatory* - The specific value of the selector. e.g. a CSS SELECTOR value .first.expanded.dropdown         |
            | Selector (str)         | *Mandatory* - The strategy to locate the element. The supported selectors are specified in `Using Selectors` |
            | Max Left Offset (int)  | The amount the floating region may move to the left. e.g. 10                                                 |
            | Max Top Offset (int)   | The amount the floating region may moveupwards. e.g. 20                                                      |
            | Max Right Offset (int) | The amount the floating region may move to the right. e.g. 10                                                |
            | Max Down Offset (int)  | The amount the floating region may move downwards. e.g. 50                                                   |
            | Target (Target)        | The previously existent Target, to be used if a ignore region or floating region was already set             |
                
        *Example:*
            | ${target}=        | Floating Region By Selector | .first.expanded.dropdown | css selector | 20 | 10 | 20 | 10 |
            | Check Eyes Window | Google Homepage             | target=${target}         |
        """

        if target is None:
            target = Target()

        selector_strategy = utils.get_selector_strategy(selector)
        floating_bounds = FloatingBounds(
            int(max_left_offset),
            int(max_top_offset),
            int(max_right_offset),
            int(max_down_offset),
        )
        floating_region = FloatingRegionBySelector(
            selector_strategy, value, floating_bounds
        )
        target.floating(floating_region)

        return target
Exemple #5
0
    def ignore_caret(self, ignore=True, target=None):
        """
        Returns a Target object that determines whether a blinking cursor should be ignored or not.
        See `Defining Ignore and Floating Regions`.

            | =Arguments=            | =Description=                                                                                                |
            | Ignore (bool)          | If true, Eyes should detect mismatch artifacts caused by a blinking cursor and not report them as mismatches |
            | Target (Target)        | The previously existent Target, to be used if a ignore region or floating region was already set             |
                
        *Example:*
            | ${target}=        | Ignore Caret    | ${false}         |
            | Check Eyes Window | Google Homepage | target=${target} |
        """

        if target is None:
            target = Target()

        target.ignore_caret(ignore)
        return target
    def compare_image(self,
                      path,
                      imagename=None,
                      target=None,
                      ignore_mismatch=False,
                      includeEyesLog=False,
                      httpDebugLog=False):
        """
        Select an image and send it to Eyes for comparison. A name can be used in place of the image's file name.
        Arguments:
                |  Path                             | Path of the image to send to eyes for visual comparison.                                                                   |
                |  imagename (default=None)         | Can manually set the name desired for the image passed in. If no name is passed in it will default file name of the image. |
                |  Include Eyes Log (default=False) | The Eyes logs will not be included by default. To activate, pass 'True' in the variable.                                   |
                |  HTTP Debug Log (default=False)   | The HTTP Debug logs will not be included by default. To activate, pass 'True' in the variable.                             |
        Example:
        | *Keywords*         |  *Parameters*                                                                                                         |
        | Open Browser       |  http://www.navinet.net/   |  gc                   |                            |                    |        |       |
        | Open Eyes Session  |  http://www.navinet.net/   |  RobotAppEyes_Test    |  NaviNet_RobotAppEyes_Test |  YourApplitoolsKey |  1024  |  768  |
        | Compare Image      |  selenium-screenshot-1.png |  Image Name Example   |                            |                    |        |       |
        | Close Eyes Session |                            |                       |                            |                    |        |       |
        """
        if imagename is None:
            tag = os.path.basename(path)
        else:
            tag = imagename

        eyes._ensure_running_session()

        if includeEyesLog is True:
            logger.set_logger(StdoutLogger())
            logger.open_()
        if httpDebugLog is True:
            http.client.HTTPConnection.debuglevel = 1

        with open(path, 'rb') as image_file:
            screenshot64 = image_file.read().encode('base64')
            screenshot = image_utils.image_from_bytes(
                base64.b64decode(screenshot64))
            screenshotBytes = EyesWebDriverScreenshot.create_from_image(
                screenshot, eyes._driver)
        title = eyes._title
        app_output = {'title': title, 'screenshot64': None}
        user_inputs = []

        #TODO: Research this aspect
        if target is None:
            target = Target()

        prepare_match_data = eyes._match_window_task._create_match_data_bytes(
            app_output, user_inputs, tag, ignore_mismatch, screenshotBytes,
            eyes.default_match_settings, target)
        eyes._match_window_task._agent_connector.match_window(
            eyes._match_window_task._running_session, prepare_match_data)
Exemple #7
0
    def floating_region_by_element(
        self,
        element,
        max_left_offset=0,
        max_top_offset=0,
        max_right_offset=0,
        max_down_offset=0,
        target=None,
    ):
        """
        Returns a Target object that includes the floating region containing the element specified in the arguments.
        See `Defining Ignore and Floating Regions`.

            | =Arguments=            | =Description=                                                                                    |
            | Element (WebElement)   | *Mandatory* - The WebElement that determines the floating region                                 |
            | Max Left Offset (int)  | The amount the floating region may move to the left. e.g. 10                                     |
            | Max Top Offset (int)   | The amount the floating region may moveupwards. e.g. 20                                          |
            | Max Right Offset (int) | The amount the floating region may move to the right. e.g. 10                                    |
            | Max Down Offset (int)  | The amount the floating region may move downwards. e.g. 50                                       |
            | Target (Target)        | The previously existent Target, to be used if a ignore region or floating region was already set |
                
        *Example:*
            | ${element}=       | Get Element                | //*[@id="hplogo"] |
            | ${target}=        | Floating Region By Element | ${element}        | 10 | 20 | 0 | 10 |
            | Check Eyes Window | Google Homepage            | target={target}   |
        """

        if target is None:
            target = Target()

        floating_bounds = FloatingBounds(
            int(max_left_offset),
            int(max_top_offset),
            int(max_right_offset),
            int(max_down_offset),
        )
        floating_region = FloatingRegionByElement(element, floating_bounds)
        target.floating(floating_region)

        return target
Exemple #8
0
    def ignore_region_by_element(self, element, target=None):
        """
        Returns a Target object that ignores the region of the element specified in the arguments.
        See `Defining Ignore and Floating Regions`.

            | =Arguments=          | =Description=                                                                                    |
            | Element (WebElement) | *Mandatory* - The WebElement to ignore                                                           |
            | Target (Target)      | The previously existent Target, to be used if a ignore region or floating region was already set |
                
        *Example:*
            | ${element}=       | Get Webelement           | //*[@id="hplogo"] |
            | ${target}=        | Ignore Region By Element | ${element}        | 
            | Check Eyes Window | Google Homepage          | target=${target}  |
        """

        if target is None:
            target = Target()

        ignore_region = IgnoreRegionByElement(element)
        target.ignore(ignore_region)

        return target
Exemple #9
0
    def ignore_region_by_selector(self, value, selector="id", target=None):
        """
        Returns a Target object that ignores the region of the element specified in the arguments by selector and value.
        See `Defining Ignore and Floating Regions` and `Using Selectors`

            | =Arguments=     | =Description=                                                                                                |
            | Value (str)     | *Mandatory* - The specific value of the selector. e.g. a CSS SELECTOR value .first.expanded.dropdown         |
            | Selector (str)  | *Mandatory* - The strategy to locate the element. The supported selectors are specified in `Using Selectors` |
            | Target (Target) | The previously existent Target, to be used if a ignore region or floating region was already set             |
                
        *Example:*
            | ${target}=        | Ignore Region By Selector | .first.expanded.dropdown | css selector |
            | Check Eyes Window | Google Homepage           | target=${target}         |
        """

        if target is None:
            target = Target()

        selector_strategy = utils.get_selector_strategy(selector)
        ignore_region = IgnoreRegionBySelector(selector_strategy, value)
        target.ignore(ignore_region)

        return target