def create_entire_frame(cls, driver, image, entire_frame_size):
     # type: (EyesWebDriver, Image.Image, RectangleSize) -> EyesWebDriverScreenshot
     return cls(
         driver,
         image,
         ScreenshotType.ENTIRE_FRAME,
         frame_location_in_screenshot=Point(0, 0),
         current_frame_scroll_position=Point(0, 0),
         frame_window=Region.from_(Point(0, 0), entire_frame_size),
     )
def _region_from_element(element, screenshot):
    location = element.location
    size = element.size
    if screenshot:
        # Element's coordinates are context relative, so we need to convert them first.
        adjusted_location = screenshot.location_in_screenshot(
            Point(location["x"], location["y"]),
            CoordinatesType.CONTEXT_RELATIVE)
    else:
        adjusted_location = Point(location["x"], location["y"])
    region = Region.from_location_size(adjusted_location, size)
    return region
 def test_position_scrolled_to_origin_after_traversing(self):
     # Page must contain scrolling
     dom_json = dom_capture.get_full_window_dom(self.driver)  # noqa: F841
     current_scroll = eyes_selenium_utils.get_current_position(
         self.driver, self.driver.find_element_by_tag_name("html")
     )
     assert current_scroll == Point(0, 0)
Exemple #4
0
 def create_entire_element(
         cls,
         driver,  # type: EyesWebDriver
         image,  # type: Image.Image
         entire_element_size,  # type: RectangleSize
         frame_location_in_screenshot,  # type: Point
 ):
     # type: (...) -> EyesWebDriverScreenshot
     return cls(
         driver,
         image,
         ScreenshotType.ENTIRE_FRAME,
         frame_location_in_screenshot,
         current_frame_scroll_position=Point(0, 0),
         frame_window=Region.from_(Point(0, 0), entire_element_size),
     )
Exemple #5
0
def parse_location_string(position):
    # type: (Union[Text, Dict]) -> Point
    if isinstance(position, dict):
        return Point.from_(position)
    xy = position.split(";")
    if len(xy) != 2:
        raise WebDriverException("Could not get scroll position!")
    return Point(round(float(xy[0])), round(float(xy[1])))
Exemple #6
0
def find_pattern(image, pattern):
    # type: (Image, Pattern) -> Optional[Point]
    image = image.convert("RGB")
    for y in range(image.height //
                   2):  # Look for pattern in top left quadrant only
        for x in range(image.width // 2):
            if _is_pattern(image, x, y, pattern):
                return Point(x - pattern.offset, y - pattern.offset)
Exemple #7
0
def test_mobilesafariwebelement(eyes, driver_mock, eyes_element_mock):
    eyes.configure.is_simulator = True
    eyes_element_mock.element.location = Point(0, 10)
    eyes_element_mock.element.rect = dict(x=0, y=0, width=600, height=400)

    driver_mock.user_agent = UserAgent(os="iOS", browser="Mobile Safari")

    mobile_safari_element = adapt_element(eyes_element_mock)
    with patch(
            "applitools.selenium.webelement.eyes_selenium_utils.get_current_position",
            return_value=Point(0, 50),
    ):
        assert mobile_safari_element.location == Point(0, 60)
        assert mobile_safari_element.rect == dict(x=0,
                                                  y=60,
                                                  width=600,
                                                  height=400)
        assert mobile_safari_element.bounds == Region(
            0, 60, 1, 1, CoordinatesType.CONTEXT_RELATIVE)
 def get_current_position(self):
     # type: () -> Point
     """
     The scroll position of the current frame.
     """
     if self._driver.is_mobile_web:
         x, y = self._driver.execute_script(
             self._JS_GET_CURRENT_SCROLL_POSITION, self._scroll_root_element
         )
         if x is None or y is None:
             raise EyesError("Got None as scroll position! ({},{})".format(x, y))
         return Point(x, y)
     return self.get_current_position_static(self._driver, self._scroll_root_element)
def calc_frame_location_in_screenshot(driver, frame_chain, screenshot_type):
    window_scroll = eyes_selenium_utils.get_default_content_scroll_position(
        frame_chain, driver)
    logger.info("Getting first frame...")
    first_frame = frame_chain[0]
    location_in_screenshot = Point.from_(first_frame.location)

    # We only need to consider the scroll of the default content if the screenshot is a
    # viewport screenshot. If this is a full page screenshot, the frame location will
    # not change anyway.
    if screenshot_type == ScreenshotType.VIEWPORT:
        location_in_screenshot = location_in_screenshot.offset(
            Point(-window_scroll.x, 0))

    # For inner frames we must calculate the scroll
    inner_frames = frame_chain[1:]
    for frame in inner_frames:
        location_in_screenshot = location_in_screenshot.offset(
            frame.location - frame.parent_scroll_position)
    return location_in_screenshot
def test_paste_image_no_error_if_point_has_float_values(image):
    point = Point(0, 0)
    point.x = 3.4
    point.x = 5.6
    image_utils.paste_image(image, image, point)
Exemple #11
0
 def default_content_scroll_position(self):
     # type: () -> tp.Union[Point, EyesError]
     if len(self) == 0:
         raise EyesError("No frames in frame chain")
     result = self[0].parent_scroll_position
     return Point(result.x, result.y)
Exemple #12
0
 def get_current_position(self):
     position = Point(self._element.get_scroll_left(),
                      self._element.get_scroll_top())
     logger.debug("Current position: {}".format(position))
     return position
Exemple #13
0
def parse_location_string(position):
    # type: (Text) -> Point
    xy = position.split(";")
    if len(xy) != 2:
        raise WebDriverException("Could not get scroll position!")
    return Point(round(float(xy[0])), round(float(xy[1])))
Exemple #14
0
def test_point_creation(x, y, result):
    expect = Point(x, y)
    assert expect == result
Exemple #15
0
        ],
        [
            1,
            2.6,
            3.5,
            4.1,
            CoordinatesType.SCREENSHOT_AS_IS,
            Region(1, 3, 4, 4, CoordinatesType.SCREENSHOT_AS_IS),
        ],
    ],
)
def test_region_creation(left, top, width, height, coord_type, result):
    expect = Region(left, top, width, height, coord_type)
    assert expect == result


@pytest.mark.parametrize(
    "x,y,result", [[0, 0, Point(0, 0)], [1.6, 2.2, Point(2, 2)]])
def test_point_creation(x, y, result):
    expect = Point(x, y)
    assert expect == result


@pytest.mark.parametrize(
    "width,height,result",
    [[0, 0, RectangleSize(0, 0)], [1.6, 2.2, RectangleSize(2, 2)]],
)
def test_rectangle_size_creation(width, height, result):
    expect = RectangleSize(width, height)
    assert expect == result
            1,
            2.6,
            3.5,
            4.1,
            CoordinatesType.SCREENSHOT_AS_IS,
            Region(1, 3, 4, 4, CoordinatesType.SCREENSHOT_AS_IS),
        ],
    ],
)
def test_region_creation(left, top, width, height, coord_type, result):
    expect = Region(left, top, width, height, coord_type)
    assert expect == result


@pytest.mark.parametrize(
    "x,y,result",
    [[0, 0, Point(0, 0)], [1.6, 2.2, Point(2, 2)]],
)
def test_point_creation(x, y, result):
    expect = Point(x, y)
    assert expect == result


@pytest.mark.parametrize(
    "width,height,result",
    [[0, 0, RectangleSize(0, 0)], [1.6, 2.2, RectangleSize(2, 2)]],
)
def test_rectangle_size_creation(width, height, result):
    expect = RectangleSize(width, height)
    assert expect == result