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_test_results_deserialization(): tr = json_utils.attr_from_json(get_resource("unit/testResultsData.json"), TestResults) # type: TestResults assert tr.status == TestResultsStatus.Passed assert ( tr.app_urls.batch == "https://eyes.applitools.com/app/test-results/111?accountIdPczBANNug~~" ) assert tr.accessibility_status == SessionAccessibilityStatus( AccessibilityStatus.Failed, AccessibilityLevel.AA, AccessibilityGuidelinesVersion.WCAG_2_0, ) assert tr.host_display_size == RectangleSize(800, 800) assert tr.default_match_settings.ignore_regions == [ Region(300, 300, 300, 300) ] assert tr.default_match_settings.accessibility == [ AccessibilityRegion(300, 300, 300, 300, AccessibilityRegionType.BoldText) ] assert tr.steps_info[0].name == "Login Window" assert ( tr.steps_info[0].app_urls.step == "https://eyes.applitools.com/app/test-results/00000215/steps/1?accountId=~" )
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 get_regions(self, eyes, screenshot): # type:(SeleniumEyes,EyesWebDriverScreenshot)->List[AccessibilityRegion] elements = self._fetch_elements(eyes.driver) regions = (_region_from_element(el, screenshot) for el in elements) return [ AccessibilityRegion.from_(region, self.accessibility_type) for region in regions ]
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 collect_regions_from_selectors(image_match_settings, regions, region_selectors): # type:(ImageMatchSettings,List[Region],List[List[VisualGridSelector]])->ImageMatchSettings if not regions: return image_match_settings logger.debug(""" start collect_regions_from_selectors() regions: {} region_selectors: {} """.format(regions, region_selectors)) mutable_regions = [ [], # Ignore Regions [], # Layout Regions [], # Strict Regions [], # Content Regions [], # Floating Regions [], # Accessibility Regions [], # Target Element Location ] r_selector_counts = [len(r) for r in region_selectors] # mapping of prev_count = 0 for i, (selectors_count, m_specific_regions) in enumerate( zip(r_selector_counts, mutable_regions)): if selectors_count == 0: continue next_count = prev_count + selectors_count for region_selector, region in zip(region_selectors[i], regions[prev_count:next_count]): padding = getattr(region_selector.category, "padding", None) if padding: region = region.padding(padding) m_specific_regions.append(region) prev_count = next_count location = Point.ZERO() # If target element location available selector_regions_index = len(mutable_regions) - 1 if mutable_regions[selector_regions_index]: location = mutable_regions[selector_regions_index][0].location image_match_settings.ignore_regions = filter_empty_entries( mutable_regions[0], location) image_match_settings.layout_regions = filter_empty_entries( mutable_regions[1], location) image_match_settings.strict_regions = filter_empty_entries( mutable_regions[2], location) image_match_settings.content_regions = filter_empty_entries( mutable_regions[3], location) image_match_settings.floating_match_settings = [ FloatingMatchSettings(reg, gfr.floating_bounds) for (reg, gfr) in filter_empty_entries_and_combine( mutable_regions[4], location, region_selectors[4]) if isinstance(gfr, GetFloatingRegion) ] image_match_settings.accessibility = [ AccessibilityRegion.from_(reg, gfr.accessibility_type) for (reg, gfr) in filter_empty_entries_and_combine( mutable_regions[5], location, region_selectors[5]) if isinstance(gfr, GetAccessibilityRegion) ] logger.debug(""" finish collect_regions_from_selectors() image_match_settings: {} """.format(image_match_settings)) return image_match_settings
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 get_regions(self, eyes, screenshot): # type: (EyesBase, EyesScreenshot) -> List[AccessibilityRegion] return [AccessibilityRegion.from_(self._rect, self.accessibility_type)]
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) ]