Android: bring application into foreground after backgrounding

5,266 views
Skip to first unread message

Vic Wong

unread,
Jul 2, 2013, 9:08:21 PM7/2/13
to appium-...@googlegroups.com
I'm trying to write a test that backgrounds the app for some time then foregrounds it. This can be done on iOS easily with executeScript: au.backgroundApp(seconds). However with Android it doesn't seem to be as trivial.

To background, I'm sending the home button using mobile: keyevent 3, but to bring the app back I'm not sure about the best approach.

I can execute a console adb command such as:

adb shell am start -n com.myApp.android/.Main

but I was wondering if there was a cleaner way to do it, such as tapping into appium's app launching mechanism to make things more consistent.

Jonathan Lipps

unread,
Jul 2, 2013, 11:42:45 PM7/2/13
to Vic Wong, appium-...@googlegroups.com
Appium's app launching mechanism simply calls adb shell am start under the hood, so it'd be equivalent :-)

You could also use uiautomator to find your app icon on the home screen and tap it!

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ritika Mishra

unread,
Jul 3, 2013, 7:01:23 AM7/3/13
to appium-...@googlegroups.com
Hi,

I too am trying to achieve the same, but how to execute this command "adb shell am start -n com.myApp.android/.Main" as, if i try to execute through javascript method i am getting the "method not implemented" exception. Is there some other way to execute this...?

Thanks in advance :)

--ritika

Aniket Gadre

unread,
Jul 3, 2013, 7:15:44 AM7/3/13
to Ritika Mishra, appium-...@googlegroups.com
adb needs to run on your machine...not on device


--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Best Regards,
Aniket Gadre
Test Automation Lead
Amdocs , Pune.
E-add: aniket...@amdocs.com

Vic Wong

unread,
Jul 3, 2013, 5:18:06 PM7/3/13
to appium-...@googlegroups.com, Vic Wong
Appium also keeps track of things like the current avd, android_home path, capabilities and things that I would have to rewrite if I want to create my own methods to rum adb commands.

What do you think about having an execute script that can run arbitrary adb commands? Not sure where it would live, but perhaps it could look something like this (forgive the inconsistent syntax):

driver.executeScript("mobile: adb", {"command : shell am start -n com.myApp.android/.Main"})

-v

bootstrap online

unread,
Jul 3, 2013, 5:19:41 PM7/3/13
to Vic Wong, appium-...@googlegroups.com
Other than the obvious security issue, I think that'd be useful.

Jonathan Lipps

unread,
Jul 3, 2013, 5:25:22 PM7/3/13
to bootstrap online, Vic Wong, appium-...@googlegroups.com
Yeah I'm not sure arbitrary adb is a good idea. If you want to make use of Appium's state, this won't be possible with "mobile: adb" anyway.

If what you want is to restart the app, what about a command like "mobile: restart" instead?

I mean, the best thing would probably just be to implement backgroundApp for android, no? We could do it pretty easily in appium.

Vic Wong

unread,
Jul 3, 2013, 5:42:07 PM7/3/13
to appium-...@googlegroups.com, bootstrap online, Vic Wong
Agreed that it makes more sense to implement mobile: restart / backgroundApp for android in this particular case
 
But I can think of other situations where I'd want to run adb commands. Like launching a landing URL in a browser to ensure it opens my application (adb am start -a android.intent.action.VIEW -t text/html -d <url>), dumping an adb log to my test report on failure (adb logcat -d), getting device properties (adb shell getprop <property>), toggling airplane mode (adb am start -a android.settings.AIRPLANE_MODE_SETTINGS)

On the other hand, I didn't realize the security concern. I can definitely come up with another solution if that can't be avoided.

-v

Jonathan Lipps

unread,
Jul 3, 2013, 6:45:54 PM7/3/13
to Vic Wong, appium-...@googlegroups.com, bootstrap online
These all sound like useful things that should be accessible via Appium's own API somehow.

LOKESH L R

unread,
Jan 30, 2014, 6:51:53 AM1/30/14
to appium-...@googlegroups.com
Hi All,
Please any help me out how to click on back button in appium ,for testing i am using lenovo k900 mobile .

Thanks in Advance
LOKESH L R


On Wednesday, July 3, 2013 6:38:21 AM UTC+5:30, Vic Wong wrote:

Neha Rathore

unread,
Aug 12, 2014, 2:31:40 AM8/12/14
to appium-...@googlegroups.com
Hello , I am testing android device i want to launch bring back app to foreground ,When i tried to do it with adb shell am start -n com.myApp.android/.Main i got a security exception .Later on i thought to start app by searching it on the launcher and tapping it but failed to implement both.Please help.....
Reply all
Reply to author
Forward
0 new messages