Add --wait-selector, --wait-script and --wait-script-file options to fetch

These new optional parameter run AFTER --wait-until, allowing the (imo) useful
combination of `--wait-until load --wait-script "report.complete === true"`.
However, if `--wait-until` IS NOT specified but `--wait-selector/script` IS,
then there is no default wait and it'll just check the selector/script. If
neither `--wait-selector` or `--wait-script/--wait-script-file` are specified
 then  `--wait-until` continues to default to `done`.

These waiters were added to the Runner, and the existing Action.waitForSelector
now uses the runner's version. Selector querying has been split into distinct
parse and query functions, so that we can parse once, and query on every tick.

We could potentially optimize --wait-script to compile the script once and call
it on each tick, but we'd have to detect page navigation to recompile the script
in the new context. Something I'd rather optimize separately.
This commit is contained in:
Karl Seguin
2026-03-31 12:22:51 +08:00
parent 47afdc003a
commit ab6c63b24b
14 changed files with 290 additions and 90 deletions

View File

@@ -452,8 +452,10 @@ fn runWebApiTest(test_file: [:0]const u8) !void {
}
}
// Used by a few CDP tests - wouldn't be sad to see this go.
pub fn pageTest(comptime test_file: []const u8) !*Page {
const PageTestOpts = struct {
wait_until_done: bool = true,
};
pub fn pageTest(comptime test_file: []const u8, opts: PageTestOpts) !*Page {
const page = try test_session.createPage();
errdefer test_session.removePage();
@@ -466,7 +468,9 @@ pub fn pageTest(comptime test_file: []const u8) !*Page {
try page.navigate(url, .{});
var runner = try test_session.runner(.{});
try runner.wait(.{ .ms = 2000 });
if (opts.wait_until_done) {
try runner.wait(.{ .ms = 2000 });
}
return page;
}