Skip to content

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 assertion 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 stops depending on the 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 - includes an implicit assertion as a side effect. Success indicates successful action execution. RVL Action

  • JavaScript Action - includes an implicit assertion as a side effect. Success indicates successful action execution. Code Action

  • RVL Assertion - explicit comparison (checkpoint) RVL Assertion

  • Code Assertion - explicit comparison (checkpoint) Code Assertion

  • Execution Error Error

  • Image Comparison (Checkpoint) Image Checkpoint

Soft Assertions

By default, an assertion statement stops test execution immediately (unless StopOnError is explicitly set to false). Sometimes, it is preferable to have more fine-grained control over test execution, allowing it to continue or stop.

This is where soft assertions come into play. Soft assertions offer two key features:

  1. If a failure occurs, it is merely reported, and execution does not stop.

  2. It is possible to stop execution based on the results of previous soft assertions by calling Tester.SoftAssertAll.

Every Assert* method defined for the Tester has a corresponding SoftAssert* counterpart (e.g., Tester.AssertEquals and Tester.SoftAssertEquals).

Create a Checkpoint

To create a checkpoint using an assertion, you must manually alter the test script (another way is to use the Verify Object Properties dialog during Recording):

  1. Select a location in your script.
  2. 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
  1. Save the state (optional). If you are creating an image checkpoint, you might want to save the image to a file.

  2. Compare. Use the ImageWrapper class to compare images.

  3. Write an Assert Statement. Make an appropriate call to one of the Tester.Assert methods. In addition to a Boolean condition, pass any additional data to be included in the Report. Read about Tester.Assert syntax in the Libraries documentation.

Example: Simple Property Checkpoint

JavaScript

Tester.AssertEqual("Verify that: ColumnCount=11", SeS('DataGridView').GetColumnCount(), 11);

RVL

property rvl

Failure Representation in Report

property fail

Example: Bitmap Checkpoint

JavaScript

Tester.AssertImage("Compare Customer bitmap to Images\\Checkpoint0001.png",
    SeS('Customer').GetBitmap(), Global.GetFullPath("Images\\Checkpoint0001.png"));

RVL

bitmap rvl

Failure Representation in Report

bitmap fail

See Also