Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open deep link with launch arguments #2192

Open
winghouchan opened this issue Dec 14, 2024 · 4 comments
Open

Open deep link with launch arguments #2192

winghouchan opened this issue Dec 14, 2024 · 4 comments
Labels

Comments

@winghouchan
Copy link

Use case

It is currently possible to launch the app with launch arguments using the launchApp command:

- launchApp:
    arguments:
      key: value

And open a deep link using the openLink command:

- openLink:
    url: scheme://path/to/screen

However, as far as I can tell, it's not possible to do both.

I am currently exploring migrating from Detox which does offer such an API (device.launchApp):

await device.launchApp({
  url: 'scheme://path/to/screen',
  launchArgs: {
    key: 'value',
  },
})

An example use case for this is using launch arguments to put the app in a certain state and testing a flow performs as expected when started from a deep link.

Proposal

The launchApp command could be updated to include a url field that accepts a URL to the screen.

- launchApp:
    url: scheme://path/to/screen
    arguments:
      key: value

Anything else?

No response

Copy link

linear bot commented Dec 14, 2024

@winghouchan
Copy link
Author

Research notes

How does Maestro launch apps?

Maestro launches the Android app by calling Context.startActivity with a launch intent; and the iOS app by running xcrun simctl launch <device> <app bundle identifer> [<arg 1> ... <arg n>].

Trace

How does Maestro open links?

Maestro opens links on Android by starting an activity with a view action and the URL; and on iOS by running xcrun simctl openurl <device> <url>.

Trace

How could Maestro be updated?

For Android, the driver could be updated to launch an activity with a view action and the URL.

Unfortunately, for iOS, there's no interface to open a deep link AND provide launch arguments. xcrun simctl launch accepts launch arguments but does not accept a URL (only an app bundle identifier) while xcrun simctl openurl accepts a URL but does not accept launch arguments. There does not seem to be an alternative to using xcrun.

As a result, the proposal would not work.

How does Detox implement this?

On Android, Detox starts an activity with the URL. On iOS, the URL is passed to the app via a launch argument called detoxURLOverride which is handled by an app delegate proxy. This is possible because Detox gets integrated within the app itself (reference).

Trace

Workaround

For my use case of setting some app state with launch arguments, it is possible to work around the issue by launching the app with the launch arguments followed by waiting for animations to end (a proxy for the state being applied), stopping the app then opening the deep link. Example flow configuration below:

- launchApp:
    clearState: true
    arguments:
      key: value
- waitForAnimationToEnd:
    timeout: 5000
- stopApp
- openLink:
    link: scheme://path/to/screen

Open to hearing some thoughts before closing the issue.

@herval herval added the Maestro label Dec 30, 2024 — with Linear
@Fishbowler
Copy link
Contributor

Nice workaround!

Is the stopApp actually required here?

@winghouchan
Copy link
Author

@Fishbowler: I haven't tested if stopApp is required or if the workaround works without it but I suppose it may also depend on if the test should cover opening a deep link from a cold start or if warm/hot start is sufficient. I'm assuming a cold start will better represent how a user will typically open a deep link. But for others, warm/hot start may be sufficient.

An aside: I'm actually no longer loading app state via launch arguments. I've decided to move to writing data to the iOS app's data container and the Android emulator's filesystem instead. It better represents how the app would actually behave but it has a bit more complexity since a custom script is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants