Is there any way to do the following process in android Automation using Appium with android driver?
Press home button from some specific screen. Put app in backgrou
driver.runAppInBackground(Duration.ofSeconds(10));
Here it is how it works.
Code for Running the App in back ground
((AppiumDriver)driver).runAppInBackground(Duration.ofSeconds(10));
Get back back to the current activity again
((StartsActivity)driver).currentActivity();
appium_lib
ruby client allows you to do this with
background_app 5
where 5 is the number of seconds you want the app to be in background. This will automatically, resume the application in the same screen.
You can use this snippet of code
((AppiumDriver)driver).runAppInBackground(Duration.ofSeconds(10));
((StartsActivity)driver).currentActivity();
If it is not working then please update your appium
with the latest version and try with the same snippet of code.
Thanks
Put App in background:
((AndroidDriver)driver).runAppInBackground(Duration.ofSeconds(20));
To start App from background:
driver.activateApp("app package name");
Works for me: ((Appium 1.10, Android 8.1))
2 options:
1st solution:
driver.runAppInBackground(Duration.ofMillis(300));
After you close your popUp, you use this line and your app will go to background and back and you will get back the focus to your app.
2nd solution: better one :)
Add this line to settings:
capability.setCapability("noReset", true);
From now your app will start like normal app, without setting reset what means without pop-ups and you will not have problem with focus at all.
I hope it will work also for you! :)