leancodepl / patrol

Flutter-first UI testing framework. Ready for action!
https://patrol.leancode.co
Apache License 2.0
832 stars 119 forks source link

Testing deep linking #556

Closed SebastianKlaiber closed 1 month ago

SebastianKlaiber commented 1 year ago

Hi,

is there a way to test deep links with patrol? I've only found the open App method, but I want to specify a URL and check if my app opens and navigates to the correct page.

e.g.: await $.native.openLink(link: 'http://www.example.com/passwordrest');

bartekpacia commented 1 year ago

Hi Sebastian, thanks for creating this issue! Looks like a cool feature to have.

Let me clarify a bit: what would the openLink() method do? Would it call adb? Like this:

$ adb shell am start -a android.intent.action.VIEW -d "example://gizmos" com.my.app

Or maybe you have another idea on how this could work? If yes I'd be happy if you shared them:)

Also, the solution has to be cross-platform solution (both Android and iOS).

SebastianKlaiber commented 1 year ago

Yes, exactly it should call adb for android and for ios simctl openurl booted "example://gizmos"

bartekpacia commented 1 year ago

Here's how Maestro does this – the openLink() method:

Docs.

bartekpacia commented 1 year ago

Dear testers: @jBorkowska, @fylyppo, @Kendru98, @zoskar, and our dear external user @lmlikota – please chip in :)

The simplest version could be:

class HostAutomator {
  Future<void> openLink(String url);
}

So await $.host.openLink("example://gizmos") would result in adb shell am start -d "example://gizmos". But that's kinda limiting because, as you could see in a comment above, adb supports more options (docs here)

Screenshot 2022-11-17 at 1 12 10 PM

bartekpacia commented 1 year ago

@SebastianKlaiber

Yes, exactly it should call adb for android and for ios simctl openurl booted "example://gizmos"

And what about physical iOS devices? Do you have some idea?

jBorkowska commented 1 year ago

If we're talking about e2e testing, I don't see a use case for that - user never provides a literal link as a deeplink. If we're talking about cases, when we can't perform the action that opens a deeplink (eg. it requires real payment), then I understand - but again, I don't know how those links work, but if providing a link is sufficient from technical perspective, so is for us.

Most common cases:

bartekpacia commented 1 year ago

It should be possible to run ActivityManager from Java/Kotlin code within the app.

lhimo commented 1 year ago

We would need to add this to adb shell commands in order to test dynamic links:

-W -a android.intent.action.VIEW
Sevastyan commented 1 year ago

The proper way to test it for Android via adb:

adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://your.domain.com/path?param1=1%26param2=2"

The above tries to open some app to show the content of the link. It may be some app that is already installed on a device, or it may be a browser, or it may be an Instant App.

So, in general, the feature should simulate OS's action for following a link on a device under test. Is this something in scope for patrol even?

@jBorkowska There is definitely a test case for e2e testing in regards to deep links. Or, I should rather refer to them as "App Links" (in Android lingo). The test case is:

  1. Open default email client on a mobile device (let's say Gmail app).
  2. Open the latest email that contains the link (let's say it's invitation for onboarding to the product under test).
  3. Click the link in that email.
  4. Check that the user sees a screen from the Instant App, or full installable app (or a webpage even).

Granted, the journey doesn't start within the app under test, I can see why this may be outside of scope for patrol though. But damn it would be so nice to have.

There is another example "somewhat from within the app":

  1. Have the app under test open in the background.
  2. Click the link in your email.
  3. Ensure that the app under test comes back to foreground and displays a correct screen that corresponds to the link.
PawlikMichal25 commented 8 months ago

My 2 cents: Of course we can already write tests by passing a link directly to App in Dart, but being able to write E2E tests would be much better because that would also cover:

Sevastyan commented 5 months ago

@bartekpacia I'd like to inquire about bringing back host functionality, so that I can run $.host.runProcess('adb shell...'). Is it in the plans? Having the ability to test deep links is crucial for my project.

bartekpacia commented 4 months ago

Hi @Sevastyan – I no longer work on Patrol, so I can't answer. But if such functionality was re-introduced, it would only work in places where you can directly run patrol_cli. This excludes "device farm" services like Firebase Test Lab, emulator.wtf, or BrowserStack. You'd have to use a "full-blown" CI service like GitHub Actions or CircleCI. Ultimately it's all about tradeoffs.

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue.