def _floating_provider_from(self, region, bounds): if isinstance(region, Region): logger.debug("floating: FloatingRegionByRectangle") return FloatingRegionByRectangle(Region.from_(region), bounds) raise TypeError( "Unsupported floating region: \n\ttype: {} \n\tvalue: {}".format( type(region), region))
def crop_image(image, region_to_crop): # type: (Image.Image, Region) -> Image.Image argument_guard.is_a(image, Image.Image) argument_guard.is_a(region_to_crop, Region) image_region = Region.from_(image) image_region = image_region.intersect(region_to_crop) if image_region.is_size_empty: logger.warning( "requested cropped area results in zero-size image! " "Cropped not performed. Returning original image." ) return image if image_region != region_to_crop: logger.warning("requested cropped area overflows image boundaries.") cropped_image = image.crop( box=( image_region.left, image_region.top, image_region.right, image_region.bottom, ) ) return cropped_image
def _update_bounds(self, region): # type: (Region) -> None if region.is_size_empty: if self._last_screenshot: self._last_screenshot_bounds = Region( 0, 0, self._last_screenshot.image.width, self._last_screenshot.image.height, ) else: # We set an "infinite" image size since we don't know what the # screenshot size is... self._last_screenshot_bounds = Region(0, 0, 999999999999, 999999999999) else: self._last_screenshot_bounds = region
def __init__(self, image, location=None): super(EyesImagesScreenshot, self).__init__(image) if location is None: location = Point.ZERO() argument_guard.is_a(location, Point) self._location = location self._bounds = Region.from_(location, self.image)
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 __init__(self, image, location=None): super(EyesImagesScreenshot, self).__init__(image) if location is None: location = Point.zero() argument_guard.is_a(location, Point) self._location = location self._bounds = Region.from_( location, dict(width=self._image.width, height=self._image.height) )
def _region_from_element(element, screenshot): # type: (AnyWebElement, EyesWebDriverScreenshot) -> Region location = element.location if screenshot: # Element's coordinates are context relative, so we need to convert them first. adjusted_location = screenshot.location_in_screenshot( Point.from_(location), CoordinatesType.CONTEXT_RELATIVE) else: adjusted_location = Point.from_(location) region = Region.from_(adjusted_location, element.size) return region
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 crop_to_specific_size_if_needed(image, max_image_height, max_image_area): # type: (Image, int, int) -> Image if (image.height <= max_image_height and image.width * image.height <= max_image_area): return image trimmed_height = min(max_image_area / image.width, max_image_height) new_region = Region(0, 0, image.width, trimmed_height) if new_region.is_size_empty: return image image = crop_image(image, new_region) return image
def bounds(self): # type: () -> Region # noinspection PyUnresolvedReferences location = self.location left, top = location["x"], location["y"] width = height = 0 # Default # noinspection PyBroadException try: size = self._element.size width, height = size["width"], size["height"] except Exception: # Not implemented on all platforms. pass if left < 0: left, width = 0, max(0, width + left) if top < 0: top, height = 0, max(0, height + top) return Region(left, top, width, height, CoordinatesType.CONTEXT_RELATIVE)
def intersected_region(self, region, coordinates_type): # type: (Region, CoordinatesType) -> Region argument_guard.not_none(region) argument_guard.not_none(coordinates_type) if region.is_size_empty: return Region.from_(region) intersected_region = self.convert_region_location( region, region.coordinates_type, self.CONTEXT_RELATIVE) intersected_region.intersect(self._bounds) if region.is_size_empty: return region intersected_region.location = self.convert_location( intersected_region.location, self.CONTEXT_RELATIVE, coordinates_type) return intersected_region
def to_region(self): return Region(self.x, self.y, self.width, self.height)
from appium import webdriver from applitools.selenium import Eyes, Target from applitools.common.geometry import Region from APIkeys import api_keys # Initialize the eyes SDK and set your private API key. eyes = Eyes() eyes.api_key = api_keys['eyes'] ignored_region = Region(0, 0, 355, 63) # Desired capabilities. desired_caps = dict( platformName='Android', deviceName='emulator-5554', platformVersion='11', automationName='UiAutomator2', app='https://applitools.bintray.com/Examples/eyes-hello-world.apk') # Open the app. wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps) wd.implicitly_wait(60) try: # Start the test. eyes.open(driver=wd, app_name='Contacts', test_name='My first Appium native Python test!') # Visual UI testing. # eyes.check_window('Contact list!')
def get_regions(self, eyes, screenshot): # type: (EyesBase, EyesScreenshot) -> List[Region] return [Region.from_(self._region)]