VOOZH about

URL: https://deepwiki.com/Accenture/Ocaramba/2.6-verify:-soft-assertions

⇱ Verify: Soft Assertions | Accenture/Ocaramba | DeepWiki


Loading...
Last indexed: 6 June 2026 (fb3580)
Menu

Verify: Soft Assertions

The Verify class provides a mechanism for "soft assertions," allowing test execution to continue even after a validation failure. This is particularly useful for checking multiple independent conditions on a single page without the test aborting at the first error.

Purpose and Implementation

In standard unit testing frameworks, an assertion failure throws an exception that immediately halts the current test method. Ocaramba's Verify static class wraps these assertion calls in try-catch blocks OcarambaLite/Verify.cs89-111 When an assertion failure occurs, Verify captures the exception, logs the error via NLog, optionally triggers diagnostic captures (screenshots/page source), and stores the failure details in the DriverContext to be reported at the end of the test execution.

Data Flow and Failure Storage

  1. Execution: Verify.That() receives an Action delegate containing the assertion logic OcarambaLite/Verify.cs121-124
  2. Interception: The delegate is invoked within a try block OcarambaLite/Verify.cs91-94
  3. Collection: If an exception occurs, an ErrorDetail object is created and added to the DriverContext.VerifyMessages collection OcarambaLite/Verify.cs107
  4. Diagnostics: If enabled via parameters, the framework triggers driverContext.TakeAndSaveScreenshot() and driverContext.SavePageSource() OcarambaLite/Verify.cs97-105
  5. Logging: The failure is recorded in the logs using NLog with a specific <VERIFY FAILS> tag OcarambaLite/Verify.cs109

Sources: OcarambaLite/Verify.cs35-111 OcarambaLite/Logger/TestLogger.cs34-40

Code Entity Mapping

The following diagram illustrates the relationship between the Verify utility and the DriverContext which tracks the test state.

Soft Assertion Logic Flow


Sources: OcarambaLite/Verify.cs35-53 OcarambaLite/Verify.cs107-110

Key Methods and Parameters

The Verify class provides several overloads for That() to control diagnostic output and handle multiple assertions:

Method OverloadDescription
That(DriverContext, Action)Executes a single assertion. Does not capture screenshots on failure. OcarambaLite/Verify.cs121-124
That(DriverContext, params Action[])Executes multiple assertions sequentially, continuing even if one fails. OcarambaLite/Verify.cs50-53
That(DriverContext, bool, bool, params Action[])Executes assertions with explicit flags for enableScreenShot and enableSavePageSource. OcarambaLite/Verify.cs70-76

Sources: OcarambaLite/Verify.cs50-125

Diagnostic Capture

When enableScreenShot or enableSavePageSource is set to true, the Verify class interacts with DriverContext to persist the current state of the browser for debugging. This functionality leverages methods like TakeAndSaveScreenshot and SavePageSource defined within the driver lifecycle management OcarambaLite/Verify.cs97-105

Diagnostic Data Flow


Sources: OcarambaLite/Verify.cs89-111 OcarambaLite/Logger/TestLogger.cs114-118 Ocaramba.Tests.NUnit/Tests/SaveScreenShotsPageSourceTestsNUnit.cs35-57

Usage in Test Code

Soft assertions are typically used within test methods or Page Objects when multiple properties of a page need to be validated simultaneously without terminating the test early.

Example: Grouped Assertions OcarambaLite/Verify.cs44-49


Example: Assertion with Screenshots OcarambaLite/Verify.cs62-69


Integration with Logging

The Verify class uses a static NLog.Logger instance to report failures to the standard log output OcarambaLite/Verify.cs37 This is distinct from the TestLogger class, which provides high-level test lifecycle logging such as LogTestStarting and LogTestEnding OcarambaLite/Logger/TestLogger.cs50-67

When a soft assertion fails, the error is logged with the following format: Logger.Error(CultureInfo.CurrentCulture, "<VERIFY FAILS>\n{0}\n</VERIFY FAILS>", e); OcarambaLite/Verify.cs109

In addition to the Verify class's own logging, the TestLogger class can be used to manually log errors during test execution via LogError(Exception e), which captures the exception state and throws it OcarambaLite/Logger/TestLogger.cs123-127

Sources: OcarambaLite/Verify.cs109-110 OcarambaLite/Logger/TestLogger.cs34-40 OcarambaLite/Logger/TestLogger.cs123-127