1

Scenarios to automate is:

I installed an application and logged in successfully. There is an "App Lock" feature which closes the application. I clicked on App Lock and application is closed. Now, I need to open application again without installing and login.

In short scenario is like:
1. Install and login to application.
2. Close the application.
3. Reopen the application.

Expected result:
Application should be opened and post login screen should be displayed

Actual:
Used below capability but application is reinstalled and Sign-Up (prelogin) screen is displayed

I search for answer and found below capability but it didn't worked.

    File appDir = new File(appDirr);
    File app = new File(appDir, "appName");
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("deviceName", "Samsung Galaxy S8");
    caps.setCapability("appPackage", "appPackageName");
    caps.setCapability("appActivity", "appActivityName");
    caps.setCapability("platformName", "Android");
    caps.setCapability("app", app.getAbsolutePath());
    appiumDriver = new AppiumDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);

Please let me know how can I automate this scenario.
Thanks!

Dhanesh
  • 63
  • 1
  • 13

5 Answers5

0
capabilities.setCapability("noReset", "true");

Use this capability. Your app is not installed every test.

If you want to close the app when run the test so you should driver.closeApp(). And open the app again use to driver.launchApp() method.

Android
  • 1,420
  • 4
  • 13
  • 23
Ahmet
  • 1
  • 1
  • Thanks for suggestion but capabilities.setCapability("noReset", true); this capability didn't worked – Dhanesh Aug 29 '19 at 07:16
0

Remove following capability:

caps.setCapability("app", app.getAbsolutePath());//This installs the application

Use this method:

appiumDriver.activateApp(appPackage);

You should know your application appPackage and appActivityName.

appPackage and appActivityName

frianH
  • 7,295
  • 6
  • 20
  • 45
  • "startActivity" is throwing error at my end. Error is "The method startActivity(Activity) is undefined for the type AppiumDriver" and java client version is 7.0.0 – Dhanesh Aug 29 '19 at 07:44
  • Updated the answer, please use the capability and just call `.launch_app()` – frianH Aug 29 '19 at 07:50
  • caps.setCapability("app", app.getAbsolutePath()) still deteled. – frianH Aug 29 '19 at 07:53
  • I tried adding these 4 lines DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("appPackage", appPackage); caps.setCapability("appActivity", appActivity); appiumDriver.launchApp(); but still it took me on signup screen – Dhanesh Aug 29 '19 at 07:57
  • `.launchApp();` it will bring to main activity (home your app), I think you want back to the last activity, it will achieve by `startActivity` – frianH Aug 29 '19 at 08:04
  • can we use .startActivity in Java Client 7.0.0 because it is throwing error for me "The method startActivity(Activity) is undefined for the type AppiumDriver" – Dhanesh Aug 29 '19 at 08:10
  • is it possible that your driver's initials have been changed? if yes, then try change `AppiumDriver appiumDriver` to `AndroidDriver appiumDriver;` – frianH Aug 29 '19 at 08:44
  • hey frianH, simply this appiumDriver.activateApp(appPackage); one like code worked for me. Thanks for your efforts! – Dhanesh Aug 29 '19 at 09:23
0

If you don't want Appium to do anything with the application you can consider setting autoLaunch Desired Capability to false

autoLaunch - Initializing the app under test automatically. Appium does not install/launch the app under test if this is false. Defaults to true

When you want to kick off the application you can use AndroidDriver.launchApp() function

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

You can use this following approach

1. Install the application and login successfully. lock app using "App Lock"  

2. Open application again without installing by using adb command to launch the activity like below example 

adb shell am start -n com.example.package(Put your package name here)/.MainActivity (Activity to be launched )

krishna chetan
  • 659
  • 1
  • 10
  • 20
0

this work for me

{
  "platformName": "Android",
  "deviceName": "Android",
  "automationName": "Appium",
  "appPackage": "com.bla.automation",
  "appActivity": "com.bla.splash.SplashScreenActivity",
  "noReset": true,
  "fullReset": false,
  "dontStopAppOnReset": false,
  "autoLaunch": false
}
El David
  • 616
  • 8
  • 17