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[FloatingMatchSettings] elements = self._fetch_elements(eyes.driver) regions = (_region_from_element(el, screenshot) for el in elements) return [ FloatingMatchSettings(region, self.floating_bounds) for region in regions ]
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 current_counter = current_type_index = 0 current_type_region_count = len(region_selectors[0]) mutable_regions = [ [], # Ignore Regions [], # Layout Regions [], # Strict Regions [], # Content Regions [], # Floating Regions [], # Target Element Location ] for region in regions: can_add_region = False while not can_add_region: current_counter += 1 if current_counter > current_type_region_count: current_type_index += 1 current_type_region_count = len( region_selectors[current_type_index]) current_counter = 0 else: can_add_region = True mutable_regions[current_type_index].append(region) # location = Point.ZERO() # If target element location available # if mutable_regions[5]: # location = mutable_regions[5][0].location image_match_settings.ignore_regions = mutable_regions[0] image_match_settings.layout_regions = mutable_regions[1] image_match_settings.strict_regions = mutable_regions[2] image_match_settings.content_regions = mutable_regions[3] # TODO: Implement floating regions floating_match_settings = [] for i, reg in enumerate(mutable_regions[4]): if reg.area == 0: continue vgs = region_selectors[4][i] gfr = vgs.category if isinstance(gfr, GetFloatingRegion): fms = FloatingMatchSettings(reg, gfr.bounds) floating_match_settings.append(fms) image_match_settings.floating_match_settings = floating_match_settings return image_match_settings
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 mutable_regions = [ [], # Ignore Regions [], # Layout Regions [], # Strict Regions [], # Content Regions [], # Floating Regions [], # Target Element Location ] r_selector_counts = [len(r) for r in region_selectors] # mapping of prev_count = 0 for selectors_count, m_specific_regions in zip(r_selector_counts, mutable_regions): if selectors_count == 0: continue next_count = prev_count + selectors_count m_specific_regions.extend(regions[prev_count:next_count]) 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) floating_match_settings = [] for i, reg in enumerate(mutable_regions[4]): if reg.area == 0: continue vgs = region_selectors[4][i] gfr = vgs.category if isinstance(gfr, GetFloatingRegion): fms = FloatingMatchSettings(reg, gfr.bounds) floating_match_settings.append(fms) image_match_settings.floating_match_settings = floating_match_settings return image_match_settings
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: (SeleniumEyes, EyesWebDriverScreenshot) -> List[FloatingMatchSettings] element = self._element(eyes.driver) region = _region_from_element(element, screenshot) return [FloatingMatchSettings(region, self.bounds)]
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) ]