问题
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 background. Open the app from same screen after some time interval.
Please help if anybody knows.
回答1:
Both iOS and Android support the following methods :
(AppiumDriver)driver.runAppInBackground(10);//put app in background for 10 seconds
(AppiumDriver)driver.launchApp();//launch the app again
Hope it helps!
回答2:
Try to focus on the current activity you were in :
(AppiumDriver)driver.runAppInBackground(10); (AppiumDriver)driver.currentActivity();
or
Try to start the same activity you were in :
(AppiumDriver)driver.runAppInBackground(10);
(AppiumDriver)driver.startActivity("appPackage","com.example.android.apis", null, null);
回答3:
driver.runAppInBackground(Duration.ofSeconds(10));
回答4:
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.
回答5:
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();
回答6:
public static void minimizeMaximize() {
try {
driver.runAppInBackground(10);
((AndroidDriver) driver).startActivity("appPackage", "appActivity");
} catch (Exception e) {
e.printStackTrace();
}
}
You have to enter your app package name and activity name to maximize the app. For Eg:
public static void minimizeMaximize() {
try {
driver.runAppInBackground(10);
((AndroidDriver) driver).startActivity("com.example.test", "com.example.LaunchApp");
} catch (Exception e) {
e.printStackTrace();
}
}
This will definitely work.
回答7:
Put App in background:
((AndroidDriver)driver).runAppInBackground(Duration.ofSeconds(20));
To start App from background:
driver.activateApp("app package name");
回答8:
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! :)
回答9:
This will navigate to the Gmail App while executing your Appium script. You Just Change the package name & activity of your app.
Activity activity = new Activity("com.google.android.gm", "com.google.android.gm.ConversationListActivityGmail");
activity.setStopApp(false);
((AndroidDriver<MobileElement>) driver).startActivity(activity);
来源:https://stackoverflow.com/questions/37191358/how-to-push-app-in-background-and-launch-from-same-screen-in-appium-with-seleniu