Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

robotframework-assertion-engine

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

robotframework-assertion-engine

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

pipPyPI
Version
3.0.2
Maintainers
3

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:

OperatorAlternative OperatorsDescriptionValidate Equivalent
==equal, equals, should beChecks if returned value is equal to expected value.value == expected
!=inequal, should not beChecks if returned value is not equal to expected value.value != expected
>greater thanChecks 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 thanChecks if returned value is less than expected value.value < expected
<=Checks if returned value is less than or equal to expected value.value <= expected
*=containsChecks if returned value contains expected value as substring.expected in value
(no operator)not containsChecks if returned value does not contain expected value as substring.expected not in value
^=should start with, startsChecks if returned value starts with expected value.re.search(f"^{expected}", value)
$=should end with, endsChecks if returned value ends with expected value.re.search(f"{expected}$", value)
matchesChecks if given RegEx matches minimum once in returned value (supports Python Regex inline flags).re.search(expected, value)
validateChecks if given Python expression evaluates to True.
evaluate / thenWhen using this operator, the keyword returns the evaluated Python expression.

Supported formatters

FormatterDescription
normalize spacesSubstitutes multiple spaces to single space from the value
stripRemoves spaces from the beginning and end of the value
apply to expectedApplies rules also for the expected value
case insensitiveConverts 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/

Keywords

Robot Framework

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts