![]() |
VOOZH | about |
The Ocaramba logging subsystem provides a multi-layered approach to capturing test execution data. It combines high-level test lifecycle logging via TestLogger, detailed Selenium event interception via MyEventFiringWebDriver, and a robust backend powered by NLog. This system ensures that every interaction, from test start to browser navigation and element clicks, is recorded in both the console and persistent log files.
The logging system is integrated directly into the framework's operational flow. When a driver is initialized, Ocaramba wraps the standard IWebDriver in an EventFiringWebDriver (specifically the MyEventFiringWebDriver implementation) to hook into Selenium events OcarambaLite/Logger/MyEventFiringWebDriver.cs33-34 High-level test events are managed by TestLogger, which uses NLog.LogManager to obtain a logger instance OcarambaLite/Logger/TestLogger.cs39
This diagram illustrates how the logging entities interact within the Ocaramba framework.
Logging Entity Map
Sources: OcarambaLite/Logger/MyEventFiringWebDriver.cs33-36 OcarambaLite/Logger/TestLogger.cs39 OcarambaLite/nlog.config11-15 OcarambaLite/Verify.cs37
The TestLogger class acts as a wrapper around NLog to provide standardized logging for test boundaries OcarambaLite/Logger/TestLogger.cs34-39
TestTitle from the provided context OcarambaLite/Logger/TestLogger.cs50-55Error method and then using ExceptionDispatchInfo to rethrow the original exception while preserving the stack trace OcarambaLite/Logger/TestLogger.cs123-127Info, Debug, Trace, Warn, and Error methods that map directly to NLog levels using the current culture OcarambaLite/Logger/TestLogger.cs74-117Sources: OcarambaLite/Logger/TestLogger.cs34-128
The MyEventFiringWebDriver class extends Selenium's EventFiringWebDriver OcarambaLite/Logger/MyEventFiringWebDriver.cs33-34 It overrides specific event hooks to automatically log internal WebDriver actions at the Trace level OcarambaLite/Logger/MyEventFiringWebDriver.cs52
The class intercepts various lifecycle events to provide an audit log of browser interactions:
| Event Hook | Logged Information |
|---|---|
OnNavigating | The target URL OcarambaLite/Logger/MyEventFiringWebDriver.cs50-54 |
OnElementClicking | Detailed representation of the element being clicked OcarambaLite/Logger/MyEventFiringWebDriver.cs60-64 |
OnFindingElement | The FindMethod (By locator) used OcarambaLite/Logger/MyEventFiringWebDriver.cs90-94 |
OnScriptExecuting | The JavaScript code string OcarambaLite/Logger/MyEventFiringWebDriver.cs100-104 |
OnScriptExecuted | Confirmation of script execution OcarambaLite/Logger/MyEventFiringWebDriver.cs110-114 |
OnElementValueChanging | The element state before value modification OcarambaLite/Logger/MyEventFiringWebDriver.cs70-74 |
OnElementValueChanged | The element state after value modification OcarambaLite/Logger/MyEventFiringWebDriver.cs80-84 |
The helper method ToStringElement constructs a detailed string of an IWebElement by extracting its attributes: id, name, value, class, type, role, text, and href OcarambaLite/Logger/MyEventFiringWebDriver.cs121-135 The AppendAttribute method handles the logic for fetching these attributes or the element text using e.Element.Text or e.Element.GetAttribute(attribute) OcarambaLite/Logger/MyEventFiringWebDriver.cs143-147
Sources: OcarambaLite/Logger/MyEventFiringWebDriver.cs33-148
Logging behavior is controlled via nlog.config files. These files define targets (where to write) and rules (what to write) OcarambaLite/nlog.config9-23
The configuration typically defines two main targets:
allfile): Writes logs to a file located in ${basedir}/TestOutput/. It uses concurrentWrites="true" and keepFileOpen="true" for performance OcarambaLite/nlog.config11-12consolelog): Outputs logs to the standard console for real-time monitoring OcarambaLite/nlog.config13-14Logging Level Hierarchy and Routing
Sources: Ocaramba.Tests.NUnit/nlog.config18-22 Ocaramba.Tests.MsTest/nlog.config18-22 Ocaramba.Tests.Xunit/nlog.config18-22
The Verify class also interacts with the logging subsystem. When a soft assertion fails within Verify.That, the exception is caught and logged as an Error level message OcarambaLite/Verify.cs109 This ensures that even if a test continues after a failure, the error is recorded in the NLog targets.
Sources: OcarambaLite/Verify.cs89-111
Logs are written to the TestOutput folder relative to the execution directory. Each project specifies its own log file name:
| Project | Log File Name | Source |
|---|---|---|
| Ocaramba.Tests.NUnit | TestNUnit.log | Ocaramba.Tests.NUnit/nlog.config11 |
| Ocaramba.Tests.MsTest | TestMsTest.log | Ocaramba.Tests.MsTest/nlog.config11 |
| Ocaramba.Tests.Xunit | TestXunit.log | Ocaramba.Tests.Xunit/nlog.config11 |
| Ocaramba.Tests.Features | TestFeatures.log | Ocaramba.Tests.Features/nlog.config12 |
| Ocaramba.Tests.Angular | TestAngular.log | Ocaramba.Tests.Angular/nlog.config12 |
| Ocaramba.UnitTests | TestUnit.log | Ocaramba.UnitTests/nlog.config12 |
| CloudProvider | TestCloud.log | Ocaramba.Tests.CloudProviderCrossBrowser/nlog.config12 |
| NUnitExtentReports | TestNUnit.log | Ocaramba.Tests.NUnitExtentReports/nlog.config12 |
Sources: Ocaramba.Tests.NUnit/nlog.config11-15 Ocaramba.Tests.MsTest/nlog.config11-15 Ocaramba.Tests.Xunit/nlog.config11-15 Ocaramba.Tests.Angular/nlog.config12-15 Ocaramba.Tests.CloudProviderCrossBrowser/nlog.config12-15 Ocaramba.UnitTests/nlog.config12-15 Ocaramba.Tests.NUnitExtentReports/nlog.config12-15
Refresh this wiki