add --screenshot-after option and fix test app document access

- Add --screenshot-after CLI option to capture screenshot after playback
- Fix sandbox test app to cache document reference for onclick handlers
- Add getDocument() helper that works with RmlUi Lua proxy objects

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 10:36:14 +01:00
parent a583ef64a1
commit 02db0d849c
2 changed files with 62 additions and 8 deletions

View File

@@ -262,6 +262,9 @@ int main(int argc, char* argv[]) {
} else if (arg == "--playback" && i + 1 < argc) { } else if (arg == "--playback" && i + 1 < argc) {
g_test_mode = TestMode::Playback; g_test_mode = TestMode::Playback;
g_test_input_path = argv[++i]; g_test_input_path = argv[++i];
} else if (arg == "--screenshot-after" && i + 1 < argc) {
// Capture screenshot after playback completes (used with --playback)
g_test_output_path = argv[++i];
} else if (arg == "--screenshot" && i + 1 < argc) { } else if (arg == "--screenshot" && i + 1 < argc) {
g_test_mode = TestMode::Screenshot; g_test_mode = TestMode::Screenshot;
g_test_output_path = argv[++i]; g_test_output_path = argv[++i];
@@ -515,7 +518,20 @@ int main(int argc, char* argv[]) {
// Check if playback finished // Check if playback finished
if (g_action_player->IsFinished()) { if (g_action_player->IsFinished()) {
std::cout << "Playback complete" << std::endl; std::cout << "Playback complete" << std::endl;
// Optionally exit after playback
// Capture screenshot if --screenshot-after was specified
if (!g_test_output_path.empty()) {
int fb_width, fb_height;
glfwGetFramebufferSize(g_window, &fb_width, &fb_height);
mosis::testing::VisualCapture capture(fb_width, fb_height);
if (capture.CaptureScreenshot(g_test_output_path)) {
std::cout << "Screenshot saved to: " << g_test_output_path << std::endl;
} else {
std::cerr << "Failed to save screenshot" << std::endl;
}
}
// Exit after playback
glfwSetWindowShouldClose(g_window, GLFW_TRUE); glfwSetWindowShouldClose(g_window, GLFW_TRUE);
} }
} }

View File

@@ -3,13 +3,41 @@
local results = {} local results = {}
local logCounter = 0 local logCounter = 0
local currentDocument = nil -- Cache the document reference
-- Helper to get document (try multiple methods)
local function getDocument()
-- First try the cached document
if currentDocument then
return currentDocument
end
-- Try the global document
if document then
currentDocument = document
return document
end
-- Try to get from RmlUi context
if rmlui and rmlui.contexts and rmlui.contexts.main then
local ctx = rmlui.contexts.main
-- documents is a proxy, iterate to get first doc
if ctx.documents then
for i, doc in ipairs(ctx.documents) do
if doc then
currentDocument = doc
return currentDocument
end
end
end
end
return nil
end
local function log(msg) local function log(msg)
logCounter = logCounter + 1 logCounter = logCounter + 1
table.insert(results, string.format("[%03d] %s", logCounter, msg)) table.insert(results, string.format("[%03d] %s", logCounter, msg))
-- document may not be available during initial script load local doc = getDocument()
if document then if doc then
local el = document:GetElementById("results") local el = doc:GetElementById("results")
if el then if el then
el.inner_rml = table.concat(results, "\n") el.inner_rml = table.concat(results, "\n")
end end
@@ -26,20 +54,26 @@ function goBack()
end end
local function setStatus(id, status, success) local function setStatus(id, status, success)
-- document may not be available during initial script load local doc = getDocument()
if not document then return end if not doc then
local el = document:GetElementById(id) print("[LUA] ERROR: document not available!")
return
end
local el = doc:GetElementById(id)
if el then if el then
if success then if success then
el.inner_rml = "&#x2713; " .. status el.inner_rml = "&#x2713; " .. status
else else
el.inner_rml = "&#x2717; " .. status el.inner_rml = "&#x2717; " .. status
end end
else
print("[LUA] ERROR: element not found: " .. id)
end end
end end
-- Timer test -- Timer test
function testTimer() function testTimer()
print("[LUA] testTimer called!")
setStatus("timer-status", "Running...", true) setStatus("timer-status", "Running...", true)
log("Starting timer test...") log("Starting timer test...")
@@ -206,6 +240,10 @@ function testStorage()
end end
end end
-- Initialize -- Initialize: cache the document when script loads
if document then
currentDocument = document
print("[LUA] Document cached on load")
end
log("Sandbox Test App loaded") log("Sandbox Test App loaded")
log("Lua version: " .. (_VERSION or "unknown")) log("Lua version: " .. (_VERSION or "unknown"))