feat: add --extension, --chrome-profile, --profile-directory options to test command#3317
Draft
shivamgupta021 wants to merge 2 commits into
Draft
Conversation
…to test command Three new web-only CLI options on `maestro test`: - `--extension <path>` (repeatable) loads an unpacked Chrome extension via Chrome's `--load-extension` - `--chrome-profile <path>` launches Chrome with a pre-existing user data directory (maps to Chrome's `--user-data-dir`) - `--profile-directory <name>` selects a profile within the user data directory (e.g. `Default`, `Profile 1`); requires `--chrome-profile` Together these enable testing browser extensions and authenticated web apps without doing the OAuth dance inside every flow. Implementation notes: - `CdpWebDriver.createSeleniumDriver()`'s inline `ChromeOptions` block is extracted into `internal fun buildChromeOptions(): ChromeOptions` so tests can inspect args via `options.asMap()` without launching a real `ChromeDriver`. - `TestCommand.call()` validates dependencies before session creation (mirroring the existing `screenSize` regex check). `--profile-directory` requires `--chrome-profile`; `--extension` paths cannot contain commas (Chrome uses `,` as a path separator with no escape mechanism). - All new params default to `null`; behavior with flags unset is byte-identical to upstream. - 11 unit tests in new `CdpWebDriverTest`, 6 new validation tests in `TestCommandTest`, CHANGELOG entry under `## Unreleased`. Addresses mobile-dev-inc#2798
…ension-and-profile-flags # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three new web-only CLI options to
maestro test:--extension <path>--load-extension--chrome-profile <path>--user-data-dir--profile-directory <name>--profile-directory--chrome-profile)Together these enable testing browser extensions and authenticated web apps without doing the OAuth dance inside every flow.
Addresses #2798 (which asked for
--user-data-direxposure in containerized environments). Same underlying gap — no way to configure ChromeOptions from the CLI — surfaces in both use cases.Example
Changes
Production code (4 files, +109/-30 LOC)
maestro-cli/.../TestCommand.kt— three new@Options +internal fun validateChromeProfileOptions()called fromcall()(mirrors the existingscreenSizevalidation pattern).maestro-cli/.../MaestroSessionManager.kt— threads the three params throughnewSession()→createMaestro()→ bothPlatform.WEBbranches ofpickWebDevice().maestro-client/.../Maestro.kt—Maestro.web()accepts and forwards the three params (all defaultnull).maestro-client/.../CdpWebDriver.kt— accepts the three new constructor params; extracted the inlineChromeOptionsconfiguration intointernal fun buildChromeOptions(): ChromeOptionsso unit tests can inspect args without launching a realChromeDriver. Empty-string flag values are treated as null.Touched-but-trivial (2 files)
maestro-client/.../DeviceService.kt— 1-line comment noting that the existingCdpWebDriver()call site relies on default-null params for the new options. No behavior change.maestro-web/.../ChromeSeleniumFactory.kt— non-goal comment explaining that the legacy Selenium driver intentionally does not receive these flags. No behavior change.Tests (2 files, 17 new test cases)
maestro-client/.../CdpWebDriverTest.kt(new) — 11 unit tests forbuildChromeOptions(): arg presence per flag, ordering when combined, empty-string handling, omitted---profile-directorycase.maestro-cli/.../TestCommandTest.kt— 6 new tests forvalidateChromeProfileOptions(): throws when--profile-directoryset without--chrome-profile, throws when--extensionpath contains a comma (Chrome uses,as path separator with no escape), passes otherwise.Docs
CHANGELOG.md— three bullets under## Unreleased.Validation rules
--profile-directoryrequires--chrome-profile→CliError("--profile-directory requires --chrome-profile to be specified.")--extension <path>rejected if path contains,→CliError("--extension path cannot contain commas (Chrome's --load-extension uses ',' as the path separator): <path>")Both fire in
TestCommand.call()before session creation, matching the existing--screen-sizeformat check.Compatibility
null/ unset; behavior with flags unset is byte-identical to upstreammain.Maestro.web(),MaestroSessionManager.newSession(), andCdpWebDriver(...)continue to compile and behave identically.maestro-android/,maestro-ios/,maestro-orchestra/,maestro-studio/, ormaestro-ai/modules.Test plan
./gradlew :maestro-client:test --tests "maestro.drivers.CdpWebDriverTest"passes (11/11)./gradlew :maestro-cli:test --tests "maestro.cli.command.TestCommandTest"passes (incl. 6 new)./gradlew :maestro-cli:installDistbuilds cleanlymaestro test --helplists all three flags with(Web only)prefix;--profile-directoryincludes "Requires --chrome-profile"Happy to iterate on flag naming, validation edge cases, or scope.