![]() |
VOOZH | about |
This page explains the base class hierarchy in Ocaramba, focusing on how ProjectTestBase manages the lifecycle of tests and how ProjectPageBase provides a foundation for Page Objects. These classes bridge the gap between the core OcarambaLite framework and specific test runner implementations (NUnit, MSTest, XUnit, and SpecFlow).
Ocaramba utilizes a multi-layered inheritance structure to separate framework-level logic from project-specific configurations.
The TestBase class is the root of the hierarchy, providing common utilities for saving test details like screenshots and page sources upon failure via the SaveTestDetailsIfTestFailed method.
ProjectTestBase is implemented within each test project (e.g., Ocaramba.Tests.NUnit, Ocaramba.Tests.Angular, Ocaramba.Tests.MsTest). It is responsible for:
DriverContext Ocaramba.Tests.NUnit/ProjectTestBase.cs39-40 and managing its Start() and Stop() cycles.[SetUp]/[TearDown] for NUnit Ocaramba.Tests.NUnit/ProjectTestBase.cs98-125 [TestInitialize]/[TestCleanup] for MsTest Ocaramba.Tests.MsTest/ProjectTestBase.cs81-111 or [Before]/[After] for SpecFlow Ocaramba.Tests.Features/ProjectTestBase.cs104-143LogTest property to record test progress Ocaramba.Tests.NUnit/ProjectTestBase.cs44-55VerifyMessages exist Ocaramba.Tests.NUnit/ProjectTestBase.cs111-114ProjectPageBase is the base class for all Page Objects. It receives the DriverContext via its constructor and exposes properties to allow interaction with web elements. For example, in the reference implementation, page objects like InternetPage take the DriverContext to initialize their state Ocaramba.Tests.MsTest/HerokuappTestsMsTest.cs42
The following diagram illustrates how these base classes interact with the DriverContext and the NUnit test runner.
Test Lifecycle and Context Flow
Sources: Ocaramba.Tests.NUnit/ProjectTestBase.cs37-125 Ocaramba.Tests.MsTest/ProjectTestBase.cs39-111 Ocaramba.Tests.Features/ProjectTestBase.cs39-143
Initialization varies by test runner. In NUnit, the driver starts once per class using OneTimeSetUp Ocaramba.Tests.NUnit/ProjectTestBase.cs71-82 In MsTest, the driver starts before every test method using TestInitialize Ocaramba.Tests.MsTest/ProjectTestBase.cs81-88
| Runner | Start Hook | Stop Hook | Context Class |
|---|---|---|---|
| NUnit | [OneTimeSetUp] | [OneTimeTearDown] | TestContext.CurrentContext |
| MsTest | [TestInitialize] | [TestCleanup] | Microsoft.VisualStudio.TestTools.UnitTesting.TestContext |
| SpecFlow | [Before] | [After] | ScenarioContext |
When a test fails, ProjectTestBase invokes SaveTestDetailsIfTestFailed. It checks both the runner's outcome and the VerifyMessages count in DriverContext Ocaramba.Tests.NUnit/ProjectTestBase.cs111-112
Data Flow: Failure Artifacts
Sources: Ocaramba.Tests.NUnit/ProjectTestBase.cs109-125 Ocaramba.Tests.MsTest/ProjectTestBase.cs94-111 Ocaramba.Tests.Features/ProjectTestBase.cs118-143
The Angular implementation of ProjectTestBase subscribes to the DriverOptionsSet event in its constructor Ocaramba.Tests.Angular/ProjectTestBase.cs49-52 This allows it to inject specific logging preferences for performance and browser logs before the driver is fully initialized Ocaramba.Tests.Angular/ProjectTestBase.cs140-149
In Ocaramba.Tests.Features, ProjectTestBase uses the [Binding] attribute Ocaramba.Tests.Features/ProjectTestBase.cs38 It injects the ScenarioContext and stores the DriverContext within the scenarioContext dictionary Ocaramba.Tests.Features/ProjectTestBase.cs111 This allows CommonSteps to retrieve the active driver session for step execution via the scenarioContext Ocaramba.Tests.Features/StepDefinition/CommonSteps.cs47
ProjectBaseConfiguration provides static access to project-specific settings by wrapping BaseConfiguration.Builder. It handles:
ASPNETCORE_ENVIRONMENT to load appsettings.{Env}.json Ocaramba.Tests.NUnit/ProjectBaseConfiguration.cs46-54FilesHelper.GetFolder Ocaramba.Tests.NUnit/ProjectBaseConfiguration.cs134-145Sources:
Refresh this wiki