Skip to main content

Generic way to create meaningful and easy to use assertions for the Robot Framework libraries.

Project description

Assertion Engine

Generic way to create meaningful and easy to use assertions for the Robot Framework libraries. This tool is a spin off from the Browser library project, where the Assertion Engine was developed as part of that library.

CI License

Supported Assertions

Currently supported assertion operators are:

Operator Alternative Operators Description Validate Equivalent
== equal, equals, should be Checks if returned value is equal to expected value. value == expected
!= inequal, should not be Checks if returned value is not equal to expected value. value != expected
> greater than Checks if returned value is greater than expected value. value > expected
>= Checks if returned value is greater than or equal to expected value. value >= expected
< less than Checks if returned value is less than expected value. value < expected
<= Checks if returned value is less than or equal to expected value. value <= expected
*= contains Checks if returned value contains expected value as substring. expected in value
(no operator) not contains Checks if returned value does not contain expected value as substring. expected not in value
^= should start with, starts Checks if returned value starts with expected value. re.search(f"^{expected}", value)
$= should end with, ends Checks if returned value ends with expected value. re.search(f"{expected}$", value)
matches Checks if given RegEx matches minimum once in returned value (supports Python Regex inline flags). re.search(expected, value)
validate Checks if given Python expression evaluates to True.
evaluate / then When using this operator, the keyword returns the evaluated Python expression.

Supported formatters

Formatter Description
normalize spaces Substitutes multiple spaces to single space from the value
strip Removes spaces from the beginning and end of the value
apply to expected Applies rules also for the expected value
case insensitive Converts value to lower case

Usage

When library developers want to do an assertion inline with the keyword call, AssertionEngine provides automatic validation within a single keyword call. The keyword method should get the value (for example from a page, database or any other source) and then use verify_assertion from AssertionEngine to perform the validation. The verify_assertion method needs three things to perform the assertion: the value from the system, an assertion_operator describing how the validation is performed and assertion_expected which represents the expected value. It is also possible to provide a custom error message and prefix the default error message.

Example:

def keyword(
    arg_to_get_value: str,
    assertion_operator: Optional[AssertionOperator] = None,
    assertion_expected: Any = None,
    message: str = None,
):
    value = method_to_get_value(arg_to_get_value)
    return verify_assertion(
        value,
        assertion_operator,
        assertion_expected,
        "Prefix message",
        message,
    )

AssertionEngine provides an interface to define scope for the formatters, but because scoping is a library-specific implementation, it is up to the library to decide how scoping is actually implemented. AssertionEngine Formatter class is an ABC which provides get_formatter and set_formatter interface methods for library developers. The AssertionEngine atest directory has examples how the interface can be implemented in practice: https://github.com/MarketSquare/AssertionEngine/tree/main/atest


For more information about Robot Framework see: http://robotframework.org For Browser library see: https://robotframework-browser.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework_assertion_engine-3.1.3.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

robotframework_assertion_engine-3.1.3-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file robotframework_assertion_engine-3.1.3.tar.gz.

File metadata

File hashes

Hashes for robotframework_assertion_engine-3.1.3.tar.gz
Algorithm Hash digest
SHA256 b37553e23bf06d56581632758f4ac5ec88bcb649741f260111b091e2cf48a5e6
MD5 c621c216647df6debee04b98e0bb338b
BLAKE2b-256 08f99c995d7111a6089214c4bfedbdd44ab74c66c04b94fc4e056942fd4fbaec

See more details on using hashes here.

File details

Details for the file robotframework_assertion_engine-3.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_assertion_engine-3.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 05ec3196129217d9fccda9c89ddc909c6037712f9507abbac527a37e9b80808f
MD5 20a84b6fe02b6a0b3cbf0e58b3445d61
BLAKE2b-256 03d569e4bd9b8ccd88d9e13bcb28e5e701db34493d77249237e1ad04b7dff039

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page