def test_set_get_accessibility_regions():
    cs = CheckSettings().accessibility(
        AccessibilityRegion(1, 2, 3, 4, AccessibilityRegionType.LargeText))
    assert cs.values.accessibility_regions[0].get_regions(Mock(), Mock()) == [
        AccessibilityRegion(1, 2, 3, 4, AccessibilityRegionType.LargeText)
    ]
    cs = CheckSettings().accessibility(Region(1, 2, 3, 4),
                                       AccessibilityRegionType.LargeText)
    assert cs.values.accessibility_regions[0].get_regions(Mock(), Mock()) == [
        AccessibilityRegion(1, 2, 3, 4, AccessibilityRegionType.LargeText)
    ]
def test_give_incorrect_parameters_to_match_regions():
    with pytest.raises(TypeError) as exc_info:
        cs = CheckSettings().accessibility(1)
        assert exc_info.type == TypeError
    with pytest.raises(TypeError) as exc_info:
        cs = CheckSettings().layout(1)
        assert exc_info.type == TypeError
    with pytest.raises(TypeError) as exc_info:
        cs = CheckSettings().content(1)
        assert exc_info.type == TypeError
    with pytest.raises(TypeError) as exc_info:
        cs = CheckSettings().strict(1)
        assert exc_info.type == TypeError
    with pytest.raises(TypeError) as exc_info:
        cs = CheckSettings().floating(1)
        assert exc_info.type == TypeError
def test_perform_match_with_source(mwt, app_output_with_screenshot,
                                   image_match_settings, eyes_base_mock):
    check_settings = CheckSettings()
    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,
            source="tracking_source",
        )
        match_window_data = smw.call_args[0][1]  # type: MatchWindowData

    assert match_window_data.options.source == "tracking_source"
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]
def test_set_get_use_dom():
    cs = CheckSettings().use_dom(True)
    assert cs.values.use_dom
def test_set_match_regions_level():
    cs = CheckSettings().layout(Region.EMPTY())
    assert cs.values.match_level is None
    cs = cs.layout()
    assert cs.values.match_level == MatchLevel.LAYOUT

    cs = CheckSettings().content(Region.EMPTY())
    assert cs.values.match_level is None
    cs = cs.content()
    assert cs.values.match_level == MatchLevel.CONTENT

    cs = CheckSettings().strict(Region.EMPTY())
    assert cs.values.match_level is None
    cs = cs.strict()
    assert cs.values.match_level == MatchLevel.STRICT

    cs = CheckSettings().exact()
    assert cs.values.match_level == MatchLevel.EXACT
def test_set_get_ignore_displacements():
    cs = CheckSettings().ignore_displacements(True)
    assert cs.values.ignore_displacements
    cs = cs.layout().ignore_displacements(False)
    assert not cs.values.ignore_displacements
def test_set_get_enable_patterns():
    cs = CheckSettings().enable_patterns(True)
    assert cs.values.enable_patterns
def test_set_get_send_dom():
    cs = CheckSettings().send_dom(True)
    assert cs.values.send_dom
示例#10
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)
    ]