Assertions
Since v2.30.0
Assertion Modes
Assertion modes only apply to steps that perform actual assertions.
Hard assertions (default)
With hard assertions, the first assertion error to be detected will be reported as a failure and execution will halt.
Since v3.43.0, the
@Hard
annotation can be used on any assertion step to make it fail hard.
Then @Hard the page title should contain "xGwen automation"
Soft assertions
With soft assertions, every assertion error that is detected is collected and reported as a failure without halting execution.
Since v3.43.0, the
@Soft
annotation can be used on any assertion step to make it fail soft.
Then @Soft the page title should contain "xGwen automation"
Sustained assertions
With sustained assertions, every assertion error that is detected is collected and reported as a sustained error without halting execution or raising failure.
Since v3.43.0, the
@Sustained
annotation can be used on any assertion step to make it sustained.
Then @Sustained the page title should contain "xGwen automation"
Default mode
Hard, soft, or sustained assertions can be configured as the default through the following setting:
gwen.assertion.mode
- This setting controls whether or not hard, soft or sustained assertions are enabled by default. Valid values include:
hard
to halt execution on first assertion error and report failure (default)soft
to collect all assertion errors and continue execution whilst reporting them as failuressustained
to collect all assertion errors and continue execution without reporting them as failures
- This setting controls whether or not hard, soft or sustained assertions are enabled by default. Valid values include:
Mode annotations
The @Hard
, @Soft
and @Sustained
annotations introduced in v3.43.0 can be used on individiual steps to override the default assertion mode setting.
For example, if the gwen.assertion.mode
setting is set to hard
, the following would perform a hard assertion since no overriding annotation is specified.
Then the page title should contain "xGwen automation"
The following would also perform a hard assertion since the @Hard
annotatation is explicitly specified (although redundant).
Then @Hard the page title should contain "xGwen automation"
The following however, would perform a soft assertion since the @Soft
annotatation is specified.
Then @Soft the page title should contain "xGwen automation"
Similarly, the following would perform a sustained assertion since the @Sustained
annotatation is specified.
Then @Sustained the page title should contain "xGwen automation"
Message Annotation
Since v3.29.0
@Message
annotations can be used to override default error messages reported by failed assertions with custom messages to provide better meaning and context.
Example
Consider the following which checks that a form error should not be displayed on a page.
Given form error can be located by css `.form-error`
Then form error should not be displayed
The assertion on line 2 will fail and report the following message if the error is displayed:
assertion failed: form error should not be displayed
The default message suggests that an error was displayed but it does not explain what the error was. To override this and provide a more informative message, add a @Message
annotation to the assertion as follows:
Given form error can be located by css `.form-error`
Then form error should not be displayed @Message("Form error was: ${form error}")
This will now output a more meaninful error and include the contents of the form error in it too.
- Example:
Form error was: Please provide all mandatory fields