diff --git a/UI/Headless/Application.cpp b/UI/Headless/Application.cpp index c8e90154078..c2e2e81a5fa 100644 --- a/UI/Headless/Application.cpp +++ b/UI/Headless/Application.cpp @@ -32,6 +32,7 @@ Application::~Application() void Application::create_platform_arguments(Core::ArgsParser& args_parser) { args_parser.add_option(screenshot_timeout, "Take a screenshot after [n] seconds (default: 1)", "screenshot", 's', "n"); + args_parser.add_option(screenshot_path, "Path the save the screenshot (default: 'output.png')", "screenshot-path", 'p', "path"); args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd'); args_parser.add_option(dump_text, "Dump text and exit", "dump-text", 'T'); args_parser.add_option(test_concurrency, "Maximum number of tests to run at once", "test-concurrency", 'j', "jobs"); diff --git a/UI/Headless/Application.h b/UI/Headless/Application.h index 83babf8cc9a..279cb179c27 100644 --- a/UI/Headless/Application.h +++ b/UI/Headless/Application.h @@ -49,6 +49,7 @@ public: static constexpr u8 VERBOSITY_LEVEL_LOG_SKIPPED_TESTS = 3; int screenshot_timeout { 1 }; + ByteString screenshot_path { "output.png"sv }; ByteString resources_folder; bool dump_failed_ref_tests { false }; bool dump_layout_tree { false }; diff --git a/UI/Headless/main.cpp b/UI/Headless/main.cpp index fcce214238a..76ecc566bfc 100644 --- a/UI/Headless/main.cpp +++ b/UI/Headless/main.cpp @@ -26,13 +26,10 @@ #include #include -static ErrorOr> load_page_for_screenshot_and_exit(Core::EventLoop& event_loop, Ladybird::HeadlessWebView& view, URL::URL const& url, int screenshot_timeout) +static ErrorOr> load_page_for_screenshot_and_exit(Core::EventLoop& event_loop, Ladybird::HeadlessWebView& view, URL::URL const& url, int screenshot_timeout, ByteString const& screenshot_path) { - // FIXME: Allow passing the output path as an argument. - static constexpr auto output_file_path = "output.png"sv; - - if (FileSystem::exists(output_file_path)) - TRY(FileSystem::remove(output_file_path, FileSystem::RecursionMode::Disallowed)); + if (FileSystem::exists(screenshot_path)) + TRY(FileSystem::remove(screenshot_path, FileSystem::RecursionMode::Disallowed)); outln("Taking screenshot after {} seconds", screenshot_timeout); @@ -42,9 +39,9 @@ static ErrorOr> load_page_for_screenshot_and_exit(Cor auto promise = view.take_screenshot(); if (auto screenshot = MUST(promise->await())) { - outln("Saving screenshot to {}", output_file_path); + outln("Saving screenshot to {}", screenshot_path); - auto output_file = MUST(Core::File::open(output_file_path, Core::File::OpenMode::Write)); + auto output_file = MUST(Core::File::open(screenshot_path, Core::File::OpenMode::Write)); auto image_buffer = MUST(Gfx::PNGWriter::encode(*screenshot)); MUST(output_file->write_until_depleted(image_buffer.bytes())); } else { @@ -96,7 +93,7 @@ ErrorOr serenity_main(Main::Arguments arguments) RefPtr timer; if (!WebView::Application::browser_options().webdriver_content_ipc_path.has_value()) - timer = TRY(load_page_for_screenshot_and_exit(Core::EventLoop::current(), view, url, app->screenshot_timeout)); + timer = TRY(load_page_for_screenshot_and_exit(Core::EventLoop::current(), view, url, app->screenshot_timeout, app->screenshot_path)); return app->execute(); }