Assertions¶
Purpose¶
An assert statement is a special Boolean condition that represents an assumption about program state at a particular point in test execution. When an assert is encountered, the condition is evaluated. A value of False indicates a program error. In some languages, execution will halt if an assertion evaluates to False. In Rapise, the result is logged to the report with failed status, and execution continues or not depending on StopOnError
test option.
There are explicit and implicit assertions (or checkpoints) generated during the script execution and reflected in the report. Each report line is produced by one of the following statements:
-
RVL Action - has an implicit assertion as a side-effect. Success means successful action execution.
-
JavaScript Action - has an implicit assertion as a side-effect. Success means successful action execution.
-
RVL Assertion - explicit comparison (checkpoint)
-
Code Assertion - explicit comparison (checkpoint)
-
Execution Error
-
Image Comparison (Checkpoint)
Soft Assertions¶
Default behavior of an Assertion statement is to stop test execution immediately (unless StopOnError set explicitly to false
). Sometimes it is preferable to have more fine grained control over test execution - so it stops or not stops.
This is when Soft assertion comes into play. Soft assertion has 2 features:
-
In case of failure it just reports it but does not stop the execution.
-
It is possible to stop execution based on previous set of Soft assertions by calling Tester.SoftAssertAll.
Every Assert*
method defined for the Tester has corresponding SoftAssert*
counterpart (i.e. Tester.AssertEquals
and Tester.SoftAssertEquals
etc).
Create a Checkpoint¶
To create a checkpoint using an assertion, you will have to manually alter the test script (another way is to use the Verify Object Properties dialog during Recording):
- Select a location in your script.
- Query for the application state. For object properties use Get<..> methods. For example:
var xx = SeS("OkButton").GetX(); // X position of the object
var image = SeS('Customer').GetBitmap(); // Image of the object
-
Save the state (optional). If you are creating an image checkpoint, you may want to save the image to a file.
-
Compare. Use the ImageWrapper class to compare images.
-
Write an Assert Statement. Make an appropriate call to one of Tester.Assert methods. Besides a Boolean condition, pass additional data to be placed in the Report. Read about Tester.Assert syntax in the Libraries documentation part.
Example: Simple Property Checkpoint¶
JavaScript
Tester.AssertEqual("Verify that: ColumnCount=11", SeS('DataGridView').GetColumnCount(), 11);
RVL
Failure Representation in Report
Example: Bitmap Checkpoint¶
JavaScript
Tester.AssertImage("Compare Customer bitmap to Images\\Checkpoint0001.png",
SeS('Customer').GetBitmap(), Global.GetFullPath("Images\\Checkpoint0001.png"));
RVL
Failure Representation in Report
See Also¶
- KB330 Compare two SpreadSheets in Rapise
- The test samples include a UsingImageCheckpoint test
- Verifying Object Properties
- Writing to the Report