java-client icon indicating copy to clipboard operation
java-client copied to clipboard

Need altenate method for AppiumDriver.launchApp() in new java client version 8.x

Open dipikachowdhary07 opened this issue 2 years ago • 7 comments

I am upgrading my current project from appium.java-client.version 6.1.0 to 8.1.1 My previous code base was using AppiumDriver.launchApp() method to go to home screen, but I couldnot find any alternate method in version 8.1.1 I also went through https://github.com/appium/appium/issues/15807 but couldnot find any relevant information. Can anyone please help on this?

dipikachowdhary07 avatar Mar 21 '23 11:03 dipikachowdhary07

I also have the same question. I have a suite where each test should start from Login screen (Home). So basically what I do in io.appium:java-client:7.6.0 is to call in @BeforeMethod (Test) TestNG:

  • driver.terminateApp(appBundleId)
  • driver.launchApp() This eventually makes fast app restart and back user to Login screen. For both iOS and Android devices. Moreover test only knows application bundle ID (package in Android). Application is pre-installed by CI tool before actually test begins.

diebold2000 avatar Apr 13 '23 18:04 diebold2000

ok. It seems there is a workaround (Kotlin):

(driver as InteractsWithApps).activateApp(appBundleId) (driver as InteractsWithApps).terminateApp(appBundleId)

diebold2000 avatar Apr 14 '23 08:04 diebold2000

@diebold2000 @dipikachowdhary07 @mykola-mokhnach any update on the same question (how to make fast app restart and back user to Login screen / Home screen in the absence of driver.launchApp())

deepakarorawins avatar Sep 25 '23 04:09 deepakarorawins

Hello @deepakarorawins with client 8.3.0 and server 2.0.1 the following statements work perfectly for me (Kotlin):

fun restartMobileApplication() { if (driver != null) { (driver as InteractsWithApps).terminateApp(Configuration.appBundleId) (driver as InteractsWithApps).activateApp(Configuration.appBundleId) } }

This code is executed under @BeforeMethod and gets user to Login screen every time.

diebold2000 avatar Sep 25 '23 09:09 diebold2000

Hello @deepakarorawins with client 8.3.0 and server 2.0.1 the following statements work perfectly for me (Kotlin):

fun restartMobileApplication() { if (driver != null) { (driver as InteractsWithApps).terminateApp(Configuration.appBundleId) (driver as InteractsWithApps).activateApp(Configuration.appBundleId) } }

This code is executed under @BeforeMethod and gets user to Login screen every time.

Thanks @diebold2000, however it is not working for me using java, earlier we use to see logged out state after using launchApp() method, but now it keeps us logged in. So all our test which are expected to start with login, are failing because app is already logged in.

@mykola-mokhnach any suggestion from your side please?

deepakarorawins avatar Sep 25 '23 16:09 deepakarorawins

Check https://github.com/appium/appium/issues/19203#issuecomment-1734056230

mykola-mokhnach avatar Sep 25 '23 17:09 mykola-mokhnach

For iOS, uninstall the app, then install it again does the same thing. (launchApp endpoint did it the same) This is not Android, but for Android, you could use https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-clearapp

Thank you @mykola-mokhnach

Check appium/appium#19203 (comment)

Thank you @mykola-mokhnach for the help, however my observation is that removeApp then installApp and then launchApp/ActivateApp takes more time in comparison to just old launchApp() method, is this expected?

For our iOS app Old launchApp() is taking: 21 seconds approximately. getDriver().launchApp();

For our iOS app New removeApp-->installApp-->launchApp is taking 28 seconds approximately. String bundleId = getDriver().getCapabilities().getCapability("bundleId").toString(); String app = getDriver().getCapabilities().getCapability("app").toString(); Map<String, Object> args = new HashMap<>(); args.put("bundleId", bundleId); args.put("app", app); getDriver().executeScript("mobile: removeApp", args); getDriver().executeScript("mobile: installApp", args); getDriver().executeScript("mobile: launchApp", args);

deepakarorawins avatar Sep 26 '23 02:09 deepakarorawins