Generic way to create meaningful and easy to use assertions for the Robot Framework libraries.
Project description
Generic way to create meaningful and easy to use assertions for the Robot Framework libraries. This tools is spin off from Browser library project, where the Assertion Engine was developed as part of the of library.
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 |
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. |
re.search(expected, value) |
|
validate |
Checks if given Python expression evaluates to True. |
||
evaluate |
then |
When using this operator, the keyword does return 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 wants to do an assertion inline with the keyword call, then AssertionEngine provides automatic validation within single keyword call. Keyword method should get value, example from page, database or from anything which the library interacts and then use verify_assertion method from AssertionEngine to perform the validation. The verify_assertion methods needs three things to perform the assertion: value from the system, assertion_operator how the validation is performed and assertion_expected which represent the expected value. It is also possible to provide custom error message and prefix the default error message.
Example library can contain keyword:
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 libraries has examples how interface can be implemented in practice.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file robotframework_assertion_engine-3.0.3.tar.gz
.
File metadata
- Download URL: robotframework_assertion_engine-3.0.3.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c608d4c69d96520986a1ddc6def0fc7f7e849520f1e6882a633b51dbb98fd88 |
|
MD5 | 7b367ddf2652a0f781e5380884b70737 |
|
BLAKE2b-256 | 826a64caaaff181a6f56847124a98e029bd91e3479c56f2db2803e3f5e19a8d8 |
File details
Details for the file robotframework_assertion_engine-3.0.3-py3-none-any.whl
.
File metadata
- Download URL: robotframework_assertion_engine-3.0.3-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cd8962744ea4f307feadd596266c1d563e87b586ed61803c9445295ab15a0cd |
|
MD5 | dd2e6d8af83037b345f2022500947782 |
|
BLAKE2b-256 | 515db160d9a55db18f9847e0cc680012dfab03e9efcebae0a09280d57ae8a6ee |