コード例 #1
0
def test_then(with_suite):
    then_op = AssertionOperator["then"]
    results = [
        verify_assertion(8, then_op, "value + 3") == 11,
        verify_assertion(2, then_op, "value + 3") == 5,
        verify_assertion("René", then_op,
                         "'Hello ' + value + '!'") == "Hello René!",
    ]
    verify_all("then", results)
コード例 #2
0
    def session_storage_get_item(
        self,
        key: str,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
    ) -> Any:
        """Get saved data from from session storage.

        ``key`` Named key of the item in the storage.

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

        Example:
        | `SessionStorage Set Item`    key2    value2
        | ${item} =    `SessionStorage Get Item`    key1
        | Should Be Equal    ${item}    value2
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.ExecuteJavascript(Request().JavascriptCode(
                script=f'window.sessionStorage.getItem("{key}")'))
            logger.info(response.log)
            formatter = self.keyword_formatters.get(
                self.session_storage_get_item)
            return verify_assertion(
                json.loads(response.result),
                assertion_operator,
                assertion_expected,
                "sessionStorage ",
                formatter,
            )
コード例 #3
0
    def get_page_state(
        self,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns page model state object as a dictionary.

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

        ``message`` overrides the default error message.

        This must be given on the page to ``window.__SET_RFBROWSER_STATE__``

        For example:

        ``let mystate = {'login': true, 'name': 'George', 'age': 123};``

        ``window.__SET_RFBROWSER_STATE__ && window.__SET_RFBROWSER_STATE__(mystate);``
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetPageState(Request().Empty())
            logger.debug(response.log)
            value = json.loads(response.result)
            return verify_assertion(value, assertion_operator,
                                    assertion_expected, "State", message)
コード例 #4
0
    def local_storage_get_item(
        self,
        key: str,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """
        Get saved data from the local storage.

        ``key`` Named key of the item in the storage.

        See `Assertions` for further details for the assertion arguments. Defaults to None.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.ExecuteJavascript(Request().JavascriptCode(
                script=f'window.localStorage.getItem("{key}")'))
            logger.info(response.log)
            return verify_assertion(
                json.loads(response.result),
                assertion_operator,
                assertion_expected,
                "localStorage",
                message,
            )
コード例 #5
0
ファイル: TestLibrary.py プロジェクト: xylix/AssertionEngine
 def is_equal(
     self,
     value: str,
     assertion_operator: Optional[AssertionOperator] = None,
     assertion_expected: Any = None,
     message: str = None,
 ):
     return verify_assertion(value, assertion_operator, assertion_expected,
                             "Prefix message", message)
コード例 #6
0
def _validate_operator(operator: AssertionOperator,
                       actual,
                       expected,
                       message="",
                       custom_message=""):
    try:
        return verify_assertion(actual, operator, expected, message,
                                custom_message)
    except Exception as error:
        return error
コード例 #7
0
    def get_attribute(
        self,
        selector: str,
        attribute: str,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns the HTML ``attribute`` of the element found by ``selector``.

        Optionally asserts that the attribute value matches the specified
        assertion.

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

        ``attribute`` Requested attribute name.

        When a attribute is selected that is not present and no assertion operator is set,
        the keyword fails. If an assertion operator is set and the attribute is not present,
        the returned value is ``None``.
        This can be used to assert check the presents or the absents of an attribute.

        ``message`` overrides the default error message.

        Example Element:
        | <button class="login button active" id="enabled_button" something>Login</button>

        Example Code:
        | Get Attribute   id=enabled_button    disabled                   # FAIL => "Attribute 'disabled' not found!"
        | Get Attribute   id=enabled_button    disabled     ==    None     # PASS => returns: None
        | Get Attribute   id=enabled_button    something    evaluate    value is not None    # PASS =>  returns: True
        | Get Attribute   id=enabled_button    disabled     evaluate    value is None        # PASS =>  returns: True


        See `Assertions` for further details for the assertion arguments. Defaults to None.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetElementAttribute(
                Request().ElementProperty(selector=selector, property=attribute)
            )
            logger.debug(response.log)
            value = json.loads(response.body)
            if assertion_operator is None and value is None:
                raise AttributeError(f"Attribute '{attribute}' not found!")
            logger.debug(f"Attribute is: {value}")
            return verify_assertion(
                value,
                assertion_operator,
                assertion_expected,
                f"Attribute {selector}",
                message,
            )
コード例 #8
0
 def get_textfield_value(
     self,
     selector: str,
     assertion_operator: Optional[AssertionOperator] = None,
     assertion_expected: Any = None,
     message: Optional[str] = None,
 ) -> Any:
     """*DEPRECATED!!* Use keyword `Get Text` instead."""
     return verify_assertion(
         self.get_property(selector, "value"),
         assertion_operator,
         assertion_expected,
         f"Value {selector}",
         message,
     )
コード例 #9
0
ファイル: TestLibrary.py プロジェクト: aaltat/AssertionEngine
 def is_equal(
     self,
     value: str,
     assertion_operator: Optional[AssertionOperator] = None,
     assertion_expected: Any = None,
     message: str = None,
 ):
     formatter = self._keyword_formatters.get(self.is_equal)
     return verify_assertion(
         value,
         assertion_operator,
         assertion_expected,
         "Prefix message",
         message,
         formatter,
     )
コード例 #10
0
ファイル: TestLibrary.py プロジェクト: aaltat/AssertionEngine
 def is_equal_as_number(
     self,
     integer: int,
     assertion_operator: Optional[AssertionOperator] = None,
     assertion_expected: Any = None,
     message: str = None,
 ):
     print(f"integer: '{integer}' and type: {type(integer)}")
     formatter = self._keyword_formatters.get(self.is_equal_as_number)
     return verify_assertion(
         integer,
         assertion_operator,
         assertion_expected,
         "Prefix message",
         message,
         formatter,
     )
コード例 #11
0
    def get_style(
        self,
        selector: str,
        key: str = "ALL",
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Gets the computed style properties of the element selected by ``selector``.

        Optionally matches with any sequence assertion operator.

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

        ``key`` Key of the requested CSS property. Retrieves "ALL" styles by default.

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

        ``message`` overrides the default error message.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetStyle(
                Request().ElementSelector(selector=selector))
            parsed = json.loads(response.json)

            if key == "ALL":
                return dict_verify_assertion(
                    parsed,
                    assertion_operator,
                    assertion_expected,
                    "Computed style is",
                    message,
                )
            else:
                item = parsed.get(key, "NOT_FOUND")
                logger.info(f"Value of key: {key}")
                logger.info(f"Value of selected property: {item}")
                return verify_assertion(
                    item,
                    assertion_operator,
                    assertion_expected,
                    f"Style value for {key} is",
                    message,
                )
コード例 #12
0
    def get_select_options(
        self,
        selector: str,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns attributes of options of a ``select`` element as a list of dictionaries.
        Returned dictionaries have the following keys and their values
        "index", "value", "label" and "selected".

        Optionally asserts that these match the specified assertion.

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

        ``assertion_operator`` See `Assertions` for further details. Defaults to None.

        Example:

        | `Get Select Options`     //select[2]    validate  [v["label"] for v in value] == ["Email", "Mobile"]
        | `Get Select Options`   select#names     validate  any(v["label"] == "Mikko" for v in value)
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetSelectContent(
                Request().ElementSelector(selector=selector)
            )
            logger.info(response)
            result = [
                {
                    "index": index,
                    "value": sel.value,
                    "label": sel.label,
                    "selected": bool(sel.selected),
                }
                for index, sel in enumerate(response.entry)
            ]
            return verify_assertion(
                result,
                assertion_operator,
                assertion_expected,
                "Select Options:",
                message,
            )
コード例 #13
0
    def get_property(
        self,
        selector: str,
        property: str,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns the ``property`` of the element found by ``selector``.

        Optionally asserts that the property value matches the specified
        assertion.

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

        ``property`` Requested property name.

        If ``assertion_operator`` is set and property is not found, ``value`` is ``None``
        and Keyword does not fail. See `Get Attribute` for examples.

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

        ``message`` overrides the default error message.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetDomProperty(
                Request().ElementProperty(selector=selector, property=property)
            )
            logger.debug(response.log)
            if response.body:
                value = json.loads(response.body)
            elif assertion_operator is not None:
                value = None
            else:
                raise AttributeError(f"Property '{property}' not found!")
            return verify_assertion(
                value,
                assertion_operator,
                assertion_expected,
                f"Property {property}",
                message,
            )
コード例 #14
0
    def get_page_source(
        self,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Gets pages HTML source as a string.

        ``message`` overrides the default error message.

        Optionally does a string assertion.

        See `Assertions` for further details for the assertion arguments. Defaults to None.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetPageSource(Request().Empty())
            logger.debug(response.log)
            value = json.loads(response.body)
            return verify_assertion(value, assertion_operator,
                                    assertion_expected, "HTML:", message)
コード例 #15
0
    def get_url(
        self,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns the current URL.

        Optionally asserts that it matches the specified assertion.

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

        ``message`` overrides the default error message.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetUrl(Request().Empty())
            logger.debug(response.log)
            value = response.body
            return verify_assertion(value, assertion_operator,
                                    assertion_expected, "URL", message)
コード例 #16
0
    def get_text(
        self,
        selector: str,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Any:
        """Returns text attribute of the element found by ``selector``.
        See the `Finding elements` section for details about the selectors.

        Optionally asserts that the text matches the specified assertion.

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

        ``message`` overrides the default error message.
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetText(Request().ElementSelector(selector=selector))
            logger.debug(response.log)
            return verify_assertion(
                response.body, assertion_operator, assertion_expected, "Text", message
            )
コード例 #17
0
    def get_browser_catalog(
        self,
        assertion_operator: Optional[AssertionOperator] = None,
        assertion_expected: Any = None,
        message: Optional[str] = None,
    ) -> Dict:
        """Returns all browsers, open contexts in them and open pages in these contexts.
        See `Browser, Context and Page` for more information about these concepts.

        ``message`` overrides the default error message.

        The data is parsed into a python list containing data representing the open Objects.

        On the root level the data contains a list of open browsers.

        Data can be manipulated also with ``assertion_operator`` for example to find
        a specific id based on index or page title with ``then`` operator.

        Return value can also be asserted against expected value.

        Sample:
        | [
        |   {
        |     "type": "chromium",
        |     "id": "browser=96207191-8147-44e7-b9ac-5e04f2709c1d",
        |     "contexts": [
        |       {
        |         "type": "context",
        |         "id": "context=525d8e5b-3c4e-4baa-bfd4-dfdbc6e86089",
        |         "activePage": "page=f90c97b8-eaaf-47f2-98b2-ccefd3450f12",
        |         "pages": [
        |           {
        |             "type": "page",
        |             "title": "Robocorp",
        |             "url": "https://robocorp.com/",
        |             "id": "page=7ac15782-22d2-48b4-8591-ff17663fa737",
        |             "timestamp": 1598607713.858
        |           },
        |           {
        |             "type": "page",
        |             "title": "Home - Reaktor",
        |             "url": "https://www.reaktor.com/",
        |             "id": "page=f90c97b8-eaaf-47f2-98b2-ccefd3450f12",
        |             "timestamp": 1598607714.702
        |           }
        |         ]
        |       }
        |     ],
        |     "activeContext": "context=525d8e5b-3c4e-4baa-bfd4-dfdbc6e86089",
        |     "activeBrowser": false
        |   },
        |   {
        |     "type": "firefox",
        |     "id": "browser=ad99abac-17a9-472b-ac7f-d6352630834e",
        |     "contexts": [
        |       {
        |         "type": "context",
        |         "id": "context=bc64f1ba-5e76-46dd-9735-4bd344afb9c0",
        |         "activePage": "page=8baf2991-5eaf-444d-a318-8045f914e96a",
        |         "pages": [
        |           {
        |             "type": "page",
        |             "title": "Software-Qualit\u00e4tssicherung und Softwaretest",
        |             "url": "https://www.imbus.de/",
        |             "id": "page=8baf2991-5eaf-444d-a318-8045f914e96a",
        |             "timestamp": 1598607716.828
        |           }
        |         ]
        |       }
        |     ],
        |     "activeContext": "context=bc64f1ba-5e76-46dd-9735-4bd344afb9c0",
        |     "activeBrowser": true
        |   }
        | ]
        """
        with self.playwright.grpc_channel() as stub:
            response = stub.GetBrowserCatalog(Request().Empty())
            parsed = json.loads(response.json)
            logger.info(json.dumps(parsed))
            return verify_assertion(
                parsed,
                assertion_operator,
                assertion_expected,
                "Browser Catalog",
                message,
            )