appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 758 forks source link

Appium 2.0 - deeplink not working #1955

Open dipakkumar1225 opened 1 year ago

dipakkumar1225 commented 1 year ago

Description

Not Able to navigate to deeplink, where the same code was working proper in Appium1.x I am using mobile command mobile: deepLink for deepLink navigation and below is the code

Environment

Details

Also tried below two approaches, with these also not able to navigate to the screen.

Approach - 2

  protected void navigateToScreenUsingDeepLink_2(final String argsDeepLink, final String argsPkgName) {
    Map<String, Object> args = new HashMap<>();
        args.put("command", "am");
        args.put("args", "start -W -a android.intent.action.VIEW -d \"" + argsDeepLink + "\" " + argsPkgName + "");
        args.put("timeout", 30000);
        args.put("includeStderr", true);
        Map<String, Object> result = (Map<String, Object>) getBaseDriver().executeScript("mobile: shell", args);
        log.info("DEEP-LINK STATUS " + result);
 }

### Approach - 3

protected void navigateToScreenUsingDeepLink_2(final String argsDeepLink, final String argsPkgName) {
    try {
            Process process = Runtime.getRuntime().exec("cmd /c adb shell am start -W -a android.intent.action.VIEW -d \"" + argsDeepLink + "\" " + argsPkgName + "");
            int processComplete = process.waitFor();
            if (processComplete != 0) {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                String strError;
                while ((strError = bufferedReader.readLine()) != null) {
                    log.error("Error: " + strError);
                }
            }
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
 }

Code To Reproduce Issue [ Good To Have ]

 protected void navigateToScreenUsingDeepLink_1(final String argsDeepLink, final String argsPkgName) {
    HashMap<String, Object> map = new HashMap<>();
    map.put("url", argsDeepLink);
    map.put("package", argsPkgName);
    map.put("waitForLaunch", true);
    Map<String, Object> result = (Map<String, Object>) getBaseDriver().executeScript("mobile: deepLink", map);
    log.info("DEEP LINK RESULT " + result);
 }

Exception Stacktraces

2023-06-30 08:56:46:077 [HTTP] {"script":"mobile: deepLink","args":[{"url":"https://rblDemo.page.link/qL6j","waitForLaunch":true,"package":"com.app.demo.uat"}]}
2023-06-30 08:56:46:078 [AndroidUiautomator2Driver@f92c (e7aed20b)] Calling AppiumDriver.execute() with args: ["mobile: deepLink",[{"url":"https://rblDemo.page.link/qL6j","waitForLaunch":true,"package":"com.app.demo.uat"}],"e7aed20b-2a49-48b7-9481-1bb0914b53d4"]
2023-06-30 08:56:46:078 [AppiumDriver@e57e] Plugins which can handle cmd 'execute': images
2023-06-30 08:56:46:078 [AppiumDriver@e57e] Plugin images is now handling cmd 'execute'
2023-06-30 08:56:46:079 [AppiumDriver@e57e] Executing default handling behavior for command 'execute'
2023-06-30 08:56:46:079 [AndroidUiautomator2Driver@f92c (e7aed20b)] Executing native command 'mobile: deepLink'
2023-06-30 08:56:46:080 [ADB] Running 'D:\Software_Installed\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZD2222ZKDN shell am start -W -a android.intent.action.VIEW -d https://rblDemo.page.link/qL6j com.app.demo.uat'
2023-06-30 08:56:46:631 [AndroidUiautomator2Driver@f92c (e7aed20b)] Responding to client with driver.execute() result: null
2023-06-30 08:56:46:632 [HTTP] <-- POST /wd/hub/session/e7aed20b-2a49-48b7-9481-1bb0914b53d4/execute/sync 200 555 ms - 14

Link To Appium Logs

Detailed Log: https://gist.github.com/dipakkumar1225/850f4334ce61cda6a5fbc68fb8972fd6

Higgens75 commented 1 year ago

i use "driver.get(URL);" for opening a deeplink in appium 2.0

mykola-mokhnach commented 1 year ago

Not sure what UIA2 driver has to do with that. It simply generated adb command to execute. If this command does not work even being executed manually then the issue must be either in the app under test or Android itself.

Higgens75 commented 1 year ago

oh android :) there i open it this way and it works with rc3

Map<String, Object> deeplink = ImmutableMap.of( "url", URL, "package", packageName ); driver.executeScript("mobile: deepLink", deeplink);

dipakkumar1225 commented 1 year ago

Not sure what UIA2 driver has to do with that. It simply generated adb command to execute. If this command does not work even being executed manually then the issue must be either in the app under test or Android itself.

Manually I am able to navigate properly

dipakkumar1225 commented 1 year ago

oh android :) there i open it this way and it works with rc3

Map<String, Object> deeplink = ImmutableMap.of( "url", URL, "package", packageName ); driver.executeScript("mobile: deepLink", deeplink);

I also using the same, but still not able to navigate.

 protected void navigateToScreenUsingDeepLink_1(final String argsDeepLink, final String argsPkgName) {
    HashMap<String, Object> map = new HashMap<>();
    map.put("url", argsDeepLink);
    map.put("package", argsPkgName);
    map.put("waitForLaunch", true);
    Map<String, Object> result = (Map<String, Object>) getBaseDriver().executeScript("mobile: deepLink", map);
    log.info("DEEP LINK RESULT " + result);
 }
mykola-mokhnach commented 1 year ago

Manually I am able to navigate properly

Then simply compare the actual adb command you enter manually with the one generated by the driver and find out what the difference is