appium / java-client

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

How to start an Activity using mobile: startActivity with OptionalIntentArguments? #2127

Closed cmccarthyIrl closed 7 months ago

cmccarthyIrl commented 7 months ago

Description

After updating my Appium dependency to version 9.1.0, I am no longer able to use ((AndroidDriver) driver).startActivty(activity)

Environment

Details

With Appium version 8.5.1, I was able to start my Android Activity using the following approach:

Activity activity = new Activity("com.android.settings", ".applications.InstalledAppDetails") .setOptionalIntentArguments("package:com.android.chrome"); ((AndroidDriver) DriverManager.getDriver()).startActivity(activity);

How can I launch the package:com.android.chrome activity using mobile: startActivity ?

valfirst commented 7 months ago

@cmccarthyIrl please check https://github.com/appium/java-client/blob/master/docs/v8-to-v9-migration-guide.md#removed-previously-deprecated-items

mmajcherczyk commented 7 months ago

in kotlin

        fun startActivity() {
            androidDriver!!.executeScript(
                "mobile: startActivity",
                mapOf(
                    "intent" to APP_PACKAGE + "/" + APP_ACTIVITY,
                    "stop" to "true"
                )
            )
        }
eglitise commented 7 months ago

You can also find example usage for any mobile extension command for UiAutomator2 in its readme here.

cmccarthyIrl commented 7 months ago

Thanks @valfirst , @eglitise - I'm following those examples but I'm not able to open the Chrome package in Settings. I can get the Settings app to open on the device but not the Settings > Apps > Chrome package as expected

Approach 1

      String[][] arrayOfArrays = {
          {"s", "package", "com.android.chrome"}
      };

      driver.executeScript("mobile: startActivity",
          ImmutableMap.of("intent", "com.android.settings/.applications.InstalledAppDetails", "wait", true, "extras", arrayOfArrays));

Approach 2

      driver.executeScript("mobile: startActivity", ImmutableMap.of("intent", 
            "com.android.settings/.applications.InstalledAppDetails", "wait", true,"package", "com.android.chrome"));
mykola-mokhnach commented 7 months ago

https://stackoverflow.com/questions/18589910/android-launch-app-info-dialog-via-adb-shell-am

cmccarthyIrl commented 7 months ago

Thanks @mykola-mokhnach, I got it working with the following

driver.executeScript("mobile: startActivity",
          ImmutableMap.of( "action", "android.settings.APPLICATION_DETAILS_SETTINGS", "uri",
              "package:com.android.chrome"));