def test_match_floating_region():
    regions = get_regions_from_("floating", 5, [By.NAME, "name"])
    assert regions[0].floating_bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._by == By.NAME
    assert regions[0]._value == "name"

    regions = get_regions_from_("floating", 5, "name")
    assert regions[0].floating_bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._by == By.CSS_SELECTOR
    assert regions[0]._value == "name"

    element = MagicMock(SeleniumWebElement)
    regions = get_regions_from_("floating", 5, element)
    assert regions[0].floating_bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._element == element
Пример #2
0
def test_coded_layout_regions_passed_to_match_window_request(
        driver, fake_connector_class, vg_runner, spy):
    eyes = Eyes(vg_runner)
    eyes.server_connector = fake_connector_class()
    driver.get(
        "https://applitools.github.io/demo/TestPages/SimpleTestPage/index.html"
    )
    eyes.open(driver, "Test Visual Grid",
              "Test regions are passed to render request")

    eyes.check(Target.window().fully().layout(Region(1, 2, 3, 4)).floating(
        5, Region(6, 7, 8,
                  9)).accessibility(Region(10, 11, 12, 13),
                                    AccessibilityRegionType.LargeText))

    eyes.close_async()
    server_connector = vg_runner._get_all_running_tests(
    )[0].eyes.server_connector
    vg_runner.get_all_test_results(False)
    _, match_data = server_connector.input_calls["match_window"][0]
    ims = match_data.options.image_match_settings

    assert len(server_connector.input_calls["match_window"]) == 1
    assert ims.layout_regions == [Region(1, 2, 3, 4)]
    assert ims.floating_match_settings == [
        FloatingMatchSettings(Region(6, 7, 8, 9), FloatingBounds(5, 5, 5, 5))
    ]
    assert ims.accessibility == [
        AccessibilityRegion(10, 11, 12, 13, AccessibilityRegionType.LargeText)
    ]
def test_match_floating_region():
    regions = get_regions_from_("floating", 5, [By.NAME, "name"])
    assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._target_path == TargetPath.region(By.NAME, "name")

    regions = get_regions_from_("floating", 5, "name")
    assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._target_path == TargetPath.region("name")

    regions = get_regions_from_("floating", 5, TargetPath.region("name"))
    assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._target_path == TargetPath.region("name")

    element = MagicMock(SeleniumWebElement)
    regions = get_regions_from_("floating", 5, element)
    assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5)
    assert regions[0]._element == element
    def floating_region(
            self,
            arg1,  # type: Union[REGION_VALUES, int]
            arg2,  # type: Union[REGION_VALUES, int]
            arg3=None,  # type: Optional[int]
            arg4=None,  # type: Optional[int]
            arg5=None,  # type: Optional[int]
    ):
        # type: (...) -> CheckSettings
        """
        Adds a floating region. Region and max_offset or [max_up_offset, max_down_offset, "
                "max_left_offset, max_right_offset] are required parameters.

        :param arg1: max_offset | Region
        :param arg2: Region     | max_up_offset
        :param arg3: None       | max_down_offset
        :param arg4: None       | max_left_offset
        :param arg5: None       | max_right_offset
        """
        if isinstance(arg1, int) and isinstance(arg2, Region):
            max_offset = arg1  # type: int
            region = arg2  # type: Region
            bounds = FloatingBounds(
                max_up_offset=max_offset,
                max_down_offset=max_offset,
                max_left_offset=max_offset,
                max_right_offset=max_offset,
            )
        elif (isinstance(arg2, int) and isinstance(arg3, int)
              and isinstance(arg4, int) and isinstance(arg5, int)):
            region = arg1
            bounds = FloatingBounds(
                max_up_offset=arg2,
                max_down_offset=arg3,
                max_left_offset=arg4,
                max_right_offset=arg5,
            )
        else:
            raise TypeError("Unsupported parameters")
        logger.info("Adding Region {} with FloatingBounds {}".format(
            region, bounds))
        region_or_container = self._floating_provider_from(region, bounds)
        self.values.floating_regions.append(region_or_container)
        return self
Пример #5
0
    def floating(self, *args):  # noqa
        """
        Adds a floating region. Region and max_offset or [max_up_offset, max_down_offset, "
                "max_left_offset, max_right_offset] are required parameters.

        :param arg1: max_offset | Region
        :param arg2: Region     | max_up_offset
        :param arg3: None       | max_down_offset
        :param arg4: None       | max_left_offset
        :param arg5: None       | max_right_offset
        """
        if len(args) < 2:
            raise TypeError("Not enough arguments")
        if isinstance(args[0], int) and not isinstance(args[1], int):
            max_offset = args[0]  # type: int
            region = args[1]  # type: ignore
            bounds = FloatingBounds(
                max_up_offset=max_offset,
                max_down_offset=max_offset,
                max_left_offset=max_offset,
                max_right_offset=max_offset,
            )
        elif (isinstance(args[1], int) and isinstance(args[2], int)
              and isinstance(args[3], int) and isinstance(args[4], int)):
            region = args[0]  # type: ignore
            bounds = FloatingBounds(
                max_up_offset=args[1],
                max_down_offset=args[2],
                max_left_offset=args[3],
                max_right_offset=args[4],
            )
        else:
            raise TypeError("No type match")
        logger.info("Adding Region {} with FloatingBounds {}".format(
            region, bounds))
        try:
            region_or_container = self._floating_provider_from(region, bounds)
        except TypeError as e:
            raise_from(TypeError("Wrong arguments in .floating()"), e)
        self.values.floating_regions.append(region_or_container)
        return self
Пример #6
0
    def floating(self, *args):  # noqa
        """
        Adds a floating region. Region and max_offset or [max_up_offset, max_down_offset, "
                "max_left_offset, max_right_offset] are required parameters.

        :param arg1: max_offset | Region
        :param arg2: Region     | max_up_offset
        :param arg3: None       | max_down_offset
        :param arg4: None       | max_left_offset
        :param arg5: None       | max_right_offset
        """
        if isinstance(args[0], int) and isinstance(args[1], Region):
            max_offset = args[0]  # type: int
            region = args[1]  # type: ignore
            bounds = FloatingBounds(
                max_up_offset=max_offset,
                max_down_offset=max_offset,
                max_left_offset=max_offset,
                max_right_offset=max_offset,
            )
        elif (isinstance(args[1], int) and isinstance(args[2], int)
              and isinstance(args[3], int) and isinstance(args[4], int)):
            region = args[0]  # type: ignore
            bounds = FloatingBounds(
                max_up_offset=args[1],
                max_down_offset=args[2],
                max_left_offset=args[3],
                max_right_offset=args[4],
            )
        else:
            raise TypeError("Unsupported parameters")
        logger.info("Adding Region {} with FloatingBounds {}".format(
            region, bounds))
        region_or_container = self._floating_provider_from(region, bounds)
        self.values.floating_regions.append(region_or_container)
        return self
Пример #7
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
Пример #8
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
def test_perform_match_collect_regions_from_screenshot(
        mwt, app_output_with_screenshot, eyes_base_mock):
    ignore_region = Region(5, 6, 7, 8)
    max_offset = 25
    floating_region = Region(0, 1, 2, 3)
    content_region = Region(1, 2, 2, 1)
    accessibility_region = AccessibilityRegion(
        1, 2, 1, 2, AccessibilityRegionType.GraphicalObject)
    check_settings = (CheckSettings().ignore(ignore_region).floating(
        max_offset, floating_region).content(content_region).accessibility(
            accessibility_region))
    image_match_settings = mwt.create_image_match_settings(
        check_settings, eyes_base_mock)
    with patch("applitools.core.server_connector.ServerConnector.match_window"
               ) as smw:
        mwt.perform_match(
            app_output_with_screenshot,
            "Name",
            False,
            image_match_settings,
            eyes_base_mock,
            check_settings=check_settings,
        )
        match_window_data = smw.call_args[0][1]  # type: MatchWindowData
        ims = match_window_data.options.image_match_settings

    assert ims.content_regions == [content_region]
    assert ims.ignore_regions == [ignore_region]

    assert ims.floating_match_settings == [
        FloatingMatchSettings(
            region=floating_region,
            bounds=FloatingBounds(
                max_up_offset=max_offset,
                max_down_offset=max_offset,
                max_left_offset=max_offset,
                max_right_offset=max_offset,
            ),
        )
    ]
    assert ims.accessibility == [accessibility_region]
Пример #10
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
Пример #11
0
def test_collect_regions_from_selectors(mwt, eyes_base_mock):
    REGIONS = [
        Region(1, 1, 1, 1),
        Region(2, 2, 2, 2),
        Region(3, 3, 3, 3),
        Region(4, 4, 4, 4),
        Region(5, 5, 5, 5),
        Region(6, 6, 6, 6),
        Region(6, 6, 6, 6),
        Region(7, 7, 7, 7),
    ]
    REGIONS_SELECTORS = [
        [
            VisualGridSelector(
                ".selector1",
                RegionBySelector(By.TAG_NAME, "html", padding=None))
        ],
        [],
        [
            VisualGridSelector(
                ".selector2",
                RegionByElement(mock.ANY, padding={
                    "top": 20,
                    "left": 100
                }),
            ),
            VisualGridSelector(".selector3",
                               RegionByRectangle(Region(3, 3, 3, 3))),
        ],
        [
            VisualGridSelector(".selector3",
                               RegionByRectangle(Region(4, 4, 4, 4))),
            VisualGridSelector(
                ".selector3",
                RegionBySelector(By.CLASS_NAME, "some-class", {
                    "right": 40,
                    "bottom": 10
                }),
            ),
            VisualGridSelector(".selector3",
                               RegionByElement(mock.ANY, padding={"left":
                                                                  10})),
        ],
        [
            VisualGridSelector(
                ".selector4",
                FloatingRegionByRectangle(Rectangle(6, 6, 6, 6),
                                          FloatingBounds(0, 2, 0, 0)),
            ),
        ],
        [
            VisualGridSelector(
                ".selector5",
                AccessibilityRegionByRectangle(
                    AccessibilityRegion(
                        7, 7, 7, 7, AccessibilityRegionType.GraphicalObject)),
            )
        ],
        [],
    ]
    check_settings = CheckSettings()
    image_match_settings = mwt.create_image_match_settings(
        check_settings, eyes_base_mock)
    img = collect_regions_from_selectors(image_match_settings, REGIONS,
                                         REGIONS_SELECTORS)
    assert img.ignore_regions == [Region(1, 1, 1, 1)]
    assert img.strict_regions == [Region(102, 22, 2, 2), Region(3, 3, 3, 3)]
    assert img.content_regions == [
        Region(4, 4, 4, 4),
        Region(5, 5, 45, 15),
        Region(16, 6, 6, 6),
    ]
    assert img.floating_match_settings == [
        FloatingMatchSettings(Region(6, 6, 6, 6), FloatingBounds(0, 2, 0, 0))
    ]
    assert img.accessibility == [
        AccessibilityRegion(7, 7, 7, 7,
                            AccessibilityRegionType.GraphicalObject)
    ]
def test_collect_regions_from_selectors(mwt, eyes_base_mock):
    REGIONS = [
        Region(1, 1, 1, 1),
        Region(2, 2, 2, 2),
        Region(3, 3, 3, 3),
        Region(4, 4, 4, 4),
        Region(5, 5, 5, 5),
        Region(6, 6, 6, 6),
        Region(6, 6, 6, 6),
        Region(7, 7, 7, 7),
    ]
    REGIONS_SELECTORS = [
        [
            VisualGridSelector(".selector1",
                               RegionByRectangle(Region(1, 1, 1, 1)))
        ],
        [],
        [
            VisualGridSelector(".selector2",
                               RegionByRectangle(Region(2, 2, 2, 2))),
            VisualGridSelector(".selector3",
                               RegionByRectangle(Region(3, 3, 3, 3))),
        ],
        [
            VisualGridSelector(".selector3",
                               RegionByRectangle(Region(4, 4, 4, 4))),
            VisualGridSelector(".selector3",
                               RegionByRectangle(Region(5, 5, 5, 5))),
            VisualGridSelector(".selector3",
                               RegionByRectangle(Region(6, 6, 6, 6))),
        ],
        [
            VisualGridSelector(
                ".selector4",
                FloatingRegionByRectangle(Rectangle(6, 6, 6, 6),
                                          FloatingBounds(0, 2, 0, 0)),
            ),
        ],
        [
            VisualGridSelector(
                ".selector5",
                AccessibilityRegionByRectangle(
                    AccessibilityRegion(
                        7, 7, 7, 7, AccessibilityRegionType.GraphicalObject)),
            )
        ],
        [],
    ]
    check_settings = CheckSettings()
    image_match_settings = mwt.create_image_match_settings(
        check_settings, eyes_base_mock)
    img = collect_regions_from_selectors(image_match_settings, REGIONS,
                                         REGIONS_SELECTORS)
    assert img.ignore_regions == [Region(1, 1, 1, 1)]
    assert img.strict_regions == [Region(2, 2, 2, 2), Region(3, 3, 3, 3)]
    assert img.content_regions == [
        Region(4, 4, 4, 4),
        Region(5, 5, 5, 5),
        Region(6, 6, 6, 6),
    ]
    assert img.floating_match_settings == [
        FloatingMatchSettings(Region(6, 6, 6, 6), FloatingBounds(0, 2, 0, 0))
    ]
    assert img.accessibility == [
        AccessibilityRegion(7, 7, 7, 7,
                            AccessibilityRegionType.GraphicalObject)
    ]