예제 #1
0
    def get_scroll_position(
        self,
        selector: Optional[str] = None,
        key: AreaFields = AreaFields.ALL,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Gets elements or pages current scroll position as object ``{top: float, left: float, bottom: float, right: float}``.

        It describes the rectangle which is visible of the scrollable content of that element.
        all values are measured from position {top: 0, left: 0}.

        ``top`` uses js function scrollTop, ``left`` uses scrollLeft and
        ``bottom`` and ``right`` are calculated with the client size.

        ``selector`` Optional selector from which shall be retrieved.
        If no selector is given the client size of the page itself is used (``document.scrollingElement``).
        See the `Finding elements` section for details about the selectors.

        ``key`` Optionally filters the returned values.
        If keys is set to ``ALL`` (default) it will return the scroll position as dictionary,
        otherwise it will just return the single value selected by the key.

        ``message`` overrides the default error message.

        See `Assertions` for further details for the assertion arguments. Defaults to None.

        See `Get BoundingBox` or `Get Scroll Size` for examples.
        """
        scroll_position = dict()
        scroll_position["top"] = exec_scroll_function(self, "scrollTop",
                                                      selector)
        scroll_position["left"] = exec_scroll_function(self, "scrollLeft",
                                                       selector)
        client_size = self.get_client_size(selector)
        scroll_position[
            "bottom"] = scroll_position["top"] + client_size["height"]
        scroll_position[
            "right"] = scroll_position["left"] + client_size["width"]
        if key == AreaFields.ALL:
            return int_dict_verify_assertion(
                scroll_position,
                assertion_operator,
                assertion_expected,
                "Scroll position is",
                message,
            )
        else:
            logger.info(f"Value of '{key}'': {scroll_position[key.name]}")
            return float_str_verify_assertion(
                scroll_position[key.name],
                assertion_operator,
                assertion_expected,
                f"Scroll position {key.name} is",
                message,
            )
예제 #2
0
    def get_scroll_size(
        self,
        selector: Optional[str] = None,
        key: SizeFields = SizeFields.ALL,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Gets elements or pages scrollable size as object ``{width: float, height: float}``.

        ``selector`` Optional selector from which shall be retrieved.
        If no selector is given the scroll size of the page itself is used.
        See the `Finding elements` section for details about the selectors.

        ``key`` Optionally filters the returned values.
        If keys is set to ``ALL`` (default) it will return the scroll size as dictionary,
        otherwise it will just return the single value selected by the key.

        ``message`` overrides the default error message.

        See `Assertions` for further details for the assertion arguments. Defaults to None.

        See `Get BoundingBox` for more similar examples.

        Example use:
        | ${height}=         Get Scroll Size    height                          # filtered page by height
        | Log                Width: ${height}                                   # Height: 58425
        | ${scroll_size}=    Get Scroll Size    id=keyword-shortcuts-container  # unfiltered element
        | Log                ${scroll_size}                                     # {'width': 253, 'height': 3036}
        """
        scroll_size = dict()
        scroll_size["width"] = exec_scroll_function(self, "scrollWidth",
                                                    selector)
        scroll_size["height"] = exec_scroll_function(self, "scrollHeight",
                                                     selector)
        if key == SizeFields.ALL:
            return int_dict_verify_assertion(
                scroll_size,
                assertion_operator,
                assertion_expected,
                "Scroll size is",
                message,
            )
        else:
            logger.info(f"Value of '{key}'': {scroll_size[key.name]}")
            return float_str_verify_assertion(
                scroll_size[key.name],
                assertion_operator,
                assertion_expected,
                f"Scroll {key.name} is",
                message,
            )
예제 #3
0
    def get_boundingbox(
        self,
        selector: str,
        key: BoundingBoxFields = BoundingBoxFields.ALL,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Gets elements size and location as an object ``{x: float, y: float, width: float, height: float}``.

        ``selector`` Selector from which shall be retrieved.
        See the `Finding elements` section for details about the selectors.

        ``key`` Optionally filters the returned values.
        If keys is set to ``ALL`` (default) it will return the BoundingBox as Dictionary,
        otherwise it will just return the single value selected by the key.
        Note: If a single value is retrieved, an assertion does *not* need a ``validate``
        combined with a cast of ``value``.

        ``message`` overrides the default error message.

        See `Assertions` for further details for the assertion arguments. Defaults to None.

        Example use:
        | ${bounding_box}=    Get BoundingBox    id=element                 # unfiltered
        | Log                 ${bounding_box}                               # {'x': 559.09375, 'y': 75.5, 'width': 188.796875, 'height': 18}
        | ${x}=               Get BoundingBox    id=element    x            # filtered
        | Log                 X: ${x}                                       # X: 559.09375
        | # Assertions:
        | Get BoundingBox     id=element         width         >    180
        | Get BoundingBox     id=element         ALL           validate    value['x'] > value['y']*2
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetBoundingBox(
                Request.ElementSelector(selector=selector))
            parsed = json.loads(response.json)
            logger.debug(f"BoundingBox: {parsed}")
            if key == BoundingBoxFields.ALL:
                return int_dict_verify_assertion(parsed, assertion_operator,
                                                 assertion_expected,
                                                 "BoundingBox is")
            else:
                logger.info(f"Value of '{key}'': {parsed[key.name]}")
                return float_str_verify_assertion(
                    parsed[key.name],
                    assertion_operator,
                    assertion_expected,
                    f"BoundingBox {key.name} is",
                    message,
                )
예제 #4
0
    def get_viewport_size(
        self,
        key: SizeFields = SizeFields.ALL,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns the current viewport dimensions.

        Optionally asserts that the count matches the specified assertion.

        ``key`` Optionally filters the returned values.
        If keys is set to ``ALL`` (default) it will return the viewport size as dictionary,
        otherwise it will just return the single value selected by the key.
        Note: If a single value is retrieved, an assertion does *not* need a ``validate``
        combined with a cast of ``value``.

        ``message`` overrides the default error message.

        See `Assertions` for further details for the assertion arguments. Defaults to None.

        Example:
        | Get Viewport Size    ALL    ==    {'width':1280, 'height':720}
        | Get Viewport Size    width    >=    1200

        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetViewportSize(Request().Empty())
            logger.info(response.log)
            parsed = json.loads(response.json)
            logger.debug(parsed)
            if key == SizeFields.ALL:
                return int_dict_verify_assertion(
                    parsed,
                    assertion_operator,
                    assertion_expected,
                    "Viewport size is",
                    message,
                )
            else:
                logger.info(f"Value of '{key}'': {parsed[key.name]}")
                return float_str_verify_assertion(
                    parsed[key.name],
                    assertion_operator,
                    assertion_expected,
                    f"{key} is",
                    message,
                )
예제 #5
0
    def get_client_size(
        self,
        selector: Optional[str] = None,
        key: SizeFields = SizeFields.ALL,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Gets elements or pages client size (``clientHeight``, ``clientWidth``) as object {width: float, height: float}.

        ``selector`` Optional selector from which shall be retrieved.
        If no selector is given the client size of the page itself is used (``document.scrollingElement``).
        See the `Finding elements` section for details about the selectors.

        ``key`` Optionally filters the returned values.
        If keys is set to ``ALL`` (default) it will return the scroll size as dictionary,
        otherwise it will just return the single value selected by the key.

        ``message`` overrides the default error message.

        See `Assertions` for further details for the assertion arguments. Defaults to None.

        See `Get BoundingBox` or `Get Scroll Size` for examples.
        """
        client_size = dict()
        client_size["width"] = exec_scroll_function(self, "clientWidth",
                                                    selector)
        client_size["height"] = exec_scroll_function(self, "clientHeight",
                                                     selector)
        if key == SizeFields.ALL:
            return int_dict_verify_assertion(
                client_size,
                assertion_operator,
                assertion_expected,
                "Client size is",
                message,
            )
        else:
            logger.info(f"Value of '{key}'': {client_size[key.name]}")
            return float_str_verify_assertion(
                client_size[key.name],
                assertion_operator,
                assertion_expected,
                f"Client {key.name} is",
                message,
            )