Skip to content

Commit 2aa4b10

Browse files
committed
Add --width/--height options to record command
Allow configuring the viewport for motus record by adding --width and --height CLI options (defaults 1024x768). The RecordCommand now accepts these options and uses their values when creating the recording page's ContextOptions.Viewport. Documentation updated to mention the configurable viewport and new flags in the options table.
1 parent 7eae747 commit 2aa4b10

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

docs/guides/recording-and-codegen.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Motus ships two CLI commands that eliminate the need to write browser test boile
1010

1111
### How it works
1212

13-
1. **Browser launch.** A headed browser instance is launched (or an existing one is attached to via `--connect`). A new page is opened at the viewport size 1024x768.
13+
1. **Browser launch.** A headed browser instance is launched (or an existing one is attached to via `--connect`). A new page is opened at the configured viewport size (default 1024x768, adjustable with `--width` and `--height`).
1414
2. **Script injection.** The `ActionCaptureEngine` registers a DOM binding and injects the recorder script via `AddInitScript` so that the listener survives page navigations automatically. The script is also evaluated immediately on the current page if one is already loaded.
1515
3. **Event capture.** The `InputStateMachine` receives raw DOM events (mouse, keyboard, form changes) through the binding callback and the CDP session. Navigation events are captured via the `FrameNavigated` page event. Dialog open/close state is tracked across the `Dialog` page event and the `Page.javascriptDialogClosed` CDP event. File chooser activations are captured via the `FileChooser` page event.
1616
4. **Selector inference.** For actions that target a specific element (click, fill, select, check, file upload), the `SelectorInferenceEngine` resolves the element and walks registered selector strategies in priority order until it finds a selector that matches exactly one node in the DOM.
@@ -29,6 +29,8 @@ Motus ships two CLI commands that eliminate the need to write browser test boile
2929
| `--method-name` | `RecordedScenario` | Name of the generated test method |
3030
| `--namespace` | `Motus.Generated` | Namespace for the generated file |
3131
| `--preserve-timing` | `false` | Emit `Task.Delay` calls between actions matching the original timing gaps (gaps shorter than 250 ms are omitted) |
32+
| `--width` | `1024` | Viewport width in pixels |
33+
| `--height` | `768` | Viewport height in pixels |
3234

3335
When `--connect` is not provided, the command always launches a headed browser regardless of any other flags. There is no `--headless` option for `motus record`.
3436

src/Motus.Cli/Commands/RecordCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public static Command Build()
1818
var methodNameOpt = new Option<string>("--method-name") { Description = "Generated test method name", DefaultValueFactory = _ => "RecordedScenario" };
1919
var namespaceOpt = new Option<string>("--namespace") { Description = "Generated test namespace", DefaultValueFactory = _ => "Motus.Generated" };
2020
var preserveTimingOpt = new Option<bool>("--preserve-timing") { Description = "Emit delays between actions matching the original user timing" };
21+
var widthOpt = new Option<int>("--width") { Description = "Viewport width in pixels", DefaultValueFactory = _ => 1024 };
22+
var heightOpt = new Option<int>("--height") { Description = "Viewport height in pixels", DefaultValueFactory = _ => 768 };
2123

2224
var cmd = new Command("record", "Record browser interactions and generate test code")
2325
{
@@ -30,6 +32,8 @@ public static Command Build()
3032
methodNameOpt,
3133
namespaceOpt,
3234
preserveTimingOpt,
35+
widthOpt,
36+
heightOpt,
3337
};
3438

3539
cmd.SetAction(async (parseResult, ct) =>
@@ -42,6 +46,8 @@ public static Command Build()
4246
var methodName = parseResult.GetValue(methodNameOpt)!;
4347
var ns = parseResult.GetValue(namespaceOpt)!;
4448
var preserveTiming = parseResult.GetValue(preserveTimingOpt);
49+
var width = parseResult.GetValue(widthOpt);
50+
var height = parseResult.GetValue(heightOpt);
4551

4652
IBrowser browser;
4753
if (connect is not null)
@@ -63,7 +69,7 @@ public static Command Build()
6369
{
6470
var page = await browser.NewPageAsync(new ContextOptions
6571
{
66-
Viewport = new ViewportSize(1024, 768),
72+
Viewport = new ViewportSize(width, height),
6773
});
6874
var engine = new ActionCaptureEngine();
6975
await engine.StartAsync(page, ct);

0 commit comments

Comments
 (0)