Class RealtimeReporter
java.lang.Object
com.shaft.tools.io.internal.RealtimeReporter
Real-time test execution dashboard server for SHAFT_ENGINE.
Hosts a local HTTP server that serves a Kanban-style dashboard reflecting live test execution state. The dashboard is automatically opened in the user's default browser at the start of the test run.
The server is only launched when all of the following conditions are met:
- The
reporting.realtimeReport.enabledproperty istrue. - Execution is not inside a CI/CD environment.
Only one instance of the server runs at a time. Starting a new test run tears down the previous server and starts a fresh one.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents an attachment (screenshot, API response, etc.) associated with a test.static classRepresents a single step within a test execution.static classRepresents a single test card displayed on the Kanban board.static enumStatus of a test on the Kanban board. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendAttachment(String testId, String attachmentType, String attachmentName, String contentType, byte[] content) Appends an attachment (screenshot, API response, etc.) to a test card.static voidappendConsoleLog(String testId, String message) Appends a console log line to the buffer for the currently active test.static voidappendStep(String testId, String stepName, String stepStatus) Appends a step entry to the test card.static StringbuildTestId(String className, String methodName) Builds a stable unique identifier for a test from its fully-qualified class name and method name.static StringclassNameToFilePath(String qualifiedClassName) Converts a fully-qualified class name into a relative source-file path.static voidClears the current thread-bound test identifier.static StringReturns the current test identifier bound to the active thread.static voidinitialize(String runSuiteName) Initialises the real-time report for a new test run.static booleanReturnstrueif the server is currently running and serving requests.static booleanDetects common CI/CD environment variables.static voidCalled when the execution finishes.static voidonTestFinished(String testId, RealtimeReporter.TestStatus status, Throwable throwable) Moves a test from the "In Progress" lane to the "Done" lane with the given status.static voidRegisters all tests that are planned to run in the current suite.static voidonTestStarted(String testId) Moves a test from the "Todo" lane to the "In Progress" lane.static voidsetCurrentTestId(String testId) Sets the current test identifier for the active execution thread.static booleanDetermines whether the real-time report should be launched.static voidForcefully stops the HTTP server and clears all state.
-
Method Details
-
initialize
Initialises the real-time report for a new test run.If the feature is disabled or the execution is in CI, this method is a no-op.
- Parameters:
runSuiteName- the name to display as the run title on the dashboard
-
onTestsPlanned
Registers all tests that are planned to run in the current suite. These are placed in the "Todo" swim lane.- Parameters:
cards- list ofRealtimeReporter.TestCardobjects representing planned tests
-
onTestStarted
Moves a test from the "Todo" lane to the "In Progress" lane.- Parameters:
testId- the unique identifier of the test (seebuildTestId(String, String))
-
onTestFinished
public static void onTestFinished(String testId, RealtimeReporter.TestStatus status, Throwable throwable) Moves a test from the "In Progress" lane to the "Done" lane with the given status.- Parameters:
testId- the unique identifier of the teststatus- the final status (PASSED / FAILED / BROKEN / SKIPPED)throwable- the failure throwable, ornullfor passing/skipped tests
-
appendConsoleLog
Appends a console log line to the buffer for the currently active test. The line is forwarded to all SSE clients watching the test details page.- Parameters:
testId- the unique identifier of the test (may benullif no test is active)message- the log line to append (ANSI codes are stripped before storage)
-
appendStep
-
appendAttachment
public static void appendAttachment(String testId, String attachmentType, String attachmentName, String contentType, byte[] content) Appends an attachment (screenshot, API response, etc.) to a test card. The raw bytes are stored in memory and served via/api/attachment/<id>.- Parameters:
testId- the unique identifier of the testattachmentType- type label (e.g. "Screenshot", "API Response Body")attachmentName- human-readable file namecontentType- MIME type (e.g. "image/png", "text/json")content- the raw bytes of the attachment
-
onExecutionFinished
public static void onExecutionFinished()Called when the execution finishes. Closes the server if the Allure auto-open flag is enabled; otherwise the server remains running so the user can review the final state. -
stopServer
public static void stopServer()Forcefully stops the HTTP server and clears all state. Safe to call even if the server is not running. -
isRunning
public static boolean isRunning()Returnstrueif the server is currently running and serving requests. -
shouldLaunch
public static boolean shouldLaunch()Determines whether the real-time report should be launched. The report launches when the flag is enabled, not running in CI, and not executing locally in headless mode.- Returns:
truewhen launch conditions are satisfied
-
setCurrentTestId
Sets the current test identifier for the active execution thread. This allows framework-agnostic forwarding of logs/steps/attachments.- Parameters:
testId- the test id generated viabuildTestId(String, String)
-
getCurrentTestId
Returns the current test identifier bound to the active thread.- Returns:
- current test id or
nullwhen none is bound
-
clearCurrentTestId
public static void clearCurrentTestId()Clears the current thread-bound test identifier. -
isRunningInCI
public static boolean isRunningInCI()Detects common CI/CD environment variables.- Returns:
trueif any known CI marker is present in the environment
-
buildTestId
Builds a stable unique identifier for a test from its fully-qualified class name and method name. Safe to call from both TestNG and JUnit listener hooks.- Parameters:
className- fully-qualified class name (e.g.com.example.MyTest)methodName- the test method name- Returns:
- identifier string in the form
className#methodName
-
classNameToFilePath
-