Need help automatically launching Android emulator when kicking off tests on default stock browser

3,116 views
Skip to first unread message

Mario

unread,
May 5, 2014, 2:09:45 PM5/5/14
to appium-...@googlegroups.com
Hi all,

First post here. First off, love the Appium product, so thank you all for building this wonderful free application.

The technologies I'm using: Windows 7 PC, Visual Studio 2012, C#, NUnit, Selenium WebDriver, Android Emulator 4.4.2 (Google APIs x86 (Google Inc.) - API Level 19) , Appium

I have been able to figure out most things and am able to run my NUnit tests on the Emulator via Appium if I perform the following steps:
  1. Launch the AVD of my choice
  2. Open up command prompt and type in appium
  3. right-click on tests in Visual Studio (or use NUnit command line or GUI) to kick off a test
Capabilities in my C# code:
                        DesiredCapabilities appiumStockAndroidCapabilities = new DesiredCapabilities();
                        appiumStockAndroidCapabilities.SetCapability("browserName", "android");
                        appiumStockAndroidCapabilities.SetCapability("platform", "Linux");
                        appiumStockAndroidCapabilities.SetCapability("device", "Android");
                        appiumStockAndroidCapabilities.SetCapability("app", "browser");
                        appiumStockAndroidCapabilities.SetCapability("app-package", "com.android.browser");
                        appiumStockAndroidCapabilities.SetCapability("app-activity", "com.android.browser.BrowserActivity");
                        appiumStockAndroidCapabilities.SetCapability("version", "4.0");

                        Driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), appiumStockAndroidCapabilities);


The above works manually, however, I would now like my AVD to startup automatically when I kick off NUnit tests. Keep in mind that I prefer testing on the default Android browser much like the manual way provides me with.

I have downloaded multiple Appium versions in an attempt to pass it arguments to launch the AVD of my choice whenever a test pings Appium to kick off.

I may be off base but from the research I gathered there are two issues:
  1. Appium older versions require all switches defining what exactly is to be launched when the AVD starts, such as: appium --pre-launch --app "browser" --app-activity "com.android.browser.BrowserActivity" --app-pkg "com.android.browser" --avd myx86Emulator
  2. Appium recent versions will work with just --avd myx86Emulator but a lot of our Selenium tests do not pass because it returns an error regarding an invalid use of CssSelector (I believe versions 17.6+)
For this reason I would prefer to use Appium 15.0 if I can figure out how to get bullet point 1 to work or use the newer versions if I can get it to play with all of my tests.

Also, my Capabilities defined in my C# code may not be accurate so please correct me if any of them do not make sense or should be deleted, tweaked, etc. I Frankenstein'd them until they worked. In addition I do not know what the exact values should be when passing all the switches required in bullet point 1 above--I simply extracted what I had from my C# code and applied it to the switches.


Thanks in advance,
Mario 


Mario

unread,
May 7, 2014, 5:48:30 PM5/7/14
to appium-...@googlegroups.com
OK,

So I am now using Appium 1.0 but I can't figure out how to get the Android emulator to auto-launch upon kicking off tests if ONLY using the "browserName" capability set to "Browser". I can however get the Android emulator to auto-launch upon kicking off tests if NOT using the "browserName" cap but instead using the following caps:
            appiumStockAndroidCapabilities.SetCapability("app", "Browser.apk");
            appiumStockAndroidCapabilities.SetCapability("appPackage", "com.android.browser");
            appiumStockAndroidCapabilities.SetCapability("appActivity", "com.android.browser.BrowserActivity");

All of the Selenium tests I'm running require the Selenium Driver.Navigate().GoToUrl("someurl") in order to work and if I auto-launch the emulator via the app, appPackage, and appActivity caps then I get a "Method not implemented" error in the Appium console because I believe it is trying to use the new AppiumDriver.Navigate() method.

My question is how can I auto-launch my Android AVD of choice and run tests only on "Browser" without needing to specify app, appPackage, and appActivity capabilities? (My emulator's name is "myx86Emulator".)

Jonathan Lipps

unread,
May 8, 2014, 9:04:50 AM5/8/14
to Mario, appium-...@googlegroups.com
You can't automate the browser app with versions less than 4.4. And anyway you want these caps:

platformName: Android
platformVersion: 4.4
deviceName: Android Emulator
browserName: Browser

--
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/d/optout.

Mario

unread,
May 8, 2014, 6:17:11 PM5/8/14
to appium-...@googlegroups.com, Mario
Hi Jonathan,

Thanks for the reply! I am using an emulator that is version 4.4, I was just hesitant to change my caps when I wasn't sure what I was doing. I am now using the above mentioned caps with Appium 1.0 and these work great if the Android emulator is already launched, however, these caps do not launch the Android emulator for me automatically upon running the tests, much like declaring "app" would.

I'm wondering if you could provide insight in the matter because at this point I'm wondering if:
  1. When using only the "browserName" cap then Appium 1.0 will not automatically kick off the AVD because this has not been implemented?
  2. If the AVD will only start with the "app" cap then should I instead be using an app such as "android-server.x..apk" ? (I believe that is the WebDriver app or is this Selendroid? I get a little confused, please feel free to correct me.)

I appreciate your response! Thanks.

Mario

unread,
May 9, 2014, 3:26:18 PM5/9/14
to appium-...@googlegroups.com, Mario
I read more of your documentation on your Appium github and had an epiphany...I think I've been going at this from a wrong angle. I realize now that Appium is for driving and automating apps.

I've been attempting to mix Appium capabilities with RemoteWebDriver. Anyways, disregard my above posts as they are not relevant to what I was attempting to do.

There is only one question that I now have and that is: Can Appium 1.0 automatically launch an Android Emulator and its native Browser if the "browserName" cap is set (much like it does if "app" + "appPackage" + "appActivity" are set)?

(Switching to discuss the iPhone Simulator method to compare to Android Emulator on Windows)
I really like the feature that Appium does on Macs when it kicks off a test (NUnit in my case) and talks to my Appium server (via "appium" in command window) and then launches the iPhone Simulator, kicks off the tests, and then closes the simulator. Would love to have that capability for Android Emulator testing its native web browser on a Windows box. Is this in the works or is this already implemented?


Thanks!

Jonathan Lipps

unread,
May 12, 2014, 10:23:45 AM5/12/14
to Mario, appium-...@googlegroups.com
yes, check out the --avd-name flag / avdName cap

Mario

unread,
May 12, 2014, 1:58:07 PM5/12/14
to appium-...@googlegroups.com, Mario
Hmm. I do not see the the "avdName" cap  or the server arg of "--avd-name" on either of these pages (the only server arg I know of is "--avd" and this one does not autolaunch the emulator if only using "browserName" cap:

or


I tried winging it by doing the below but an emulator did not auto-launch when I kicked off my NUnit test:


I'm running appium 1.0 in the command line on Windows 7 as this:
"appium"

Then my caps I defined are the following:
                        DesiredCapabilities appiumStockAndroidCapabilities = new DesiredCapabilities();
                        appiumStockAndroidCapabilities.SetCapability("platformName", "Android");
                        appiumStockAndroidCapabilities.SetCapability("platformVersion", "4.4");
                        appiumStockAndroidCapabilities.SetCapability("deviceName", "Android Emulator");
                        appiumStockAndroidCapabilities.SetCapability("browserName", "Browser");
                        appiumStockAndroidCapabilities.SetCapability("avdName", "myx86Emulator");

                        Driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), appiumStockAndroidCapabilities);

Jonathan Lipps

unread,
May 12, 2014, 4:01:14 PM5/12/14
to Mario, appium-...@googlegroups.com
Hmm it's probably the --avd flag then.

Mario

unread,
May 12, 2014, 4:08:33 PM5/12/14
to appium-...@googlegroups.com, Mario
Bummer then, because that doesn't work for me :(

If I launch Appium server in command line like this:
appium --avd myx86Emulator

Then I kick off my tests with these caps:
                        DesiredCapabilities appiumStockAndroidCapabilities = new DesiredCapabilities();
                        appiumStockAndroidCapabilities.SetCapability("platformName", "Android");
                        appiumStockAndroidCapabilities.SetCapability("platformVersion", "4.4");
                        appiumStockAndroidCapabilities.SetCapability("deviceName", "Android Emulator");
                        appiumStockAndroidCapabilities.SetCapability("browserName", "Browser");
                        appiumStockAndroidCapabilities.SetCapability("avdName", "myx86Emulator");

Then all I get is the Appium log attempting to launch the AVD but then bombs out saying:
"error: Failed to start an Appium session, err was: Error: Could not find a connected Android device."

The only time this works is if the AVD is already launched and running (but I'm trying to get the AVD to launch upon kicking off the tests).

Rubén González

unread,
May 13, 2014, 7:46:32 AM5/13/14
to appium-...@googlegroups.com, Mario
Now --avd option only works with app.
I just sent a pull request to fix it: https://github.com/appium/appium/pull/2557

Anand Jayaram

unread,
May 13, 2014, 8:29:15 AM5/13/14
to appium-...@googlegroups.com, Mario
Sorry to hijack this thread. This post was the closest I could see on how to test on android stock browser. 
Here is my question:

I am using JAVA, windows 7, Appium 1.0, Android Emulator Version 4.4.2

DesiredCapabilities appiumStockAndroidCapabilities = new DesiredCapabilities();
appiumStockAndroidCapabilities.setCapability("platformName", "Android");
appiumStockAndroidCapabilities.setCapability("deviceName", "AndroidEmulator");
appiumStockAndroidCapabilities.setCapability("platformVersion", "4.4");
appiumStockAndroidCapabilities.setCapability("browserName", "Browser");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), appiumStockAndroidCapabilities);

When I run this program after starting appium server, Appium tries to find android devices and it fails. I have an emulator open. 

Here is the appium log:

 ERROR: debug: Appium request initiated at /wd/hub/session
> info: Looks like we want chrome on android
> ERROR: debug: Request received with params: {"desiredCapabilities":{"platformVersion":"4.4","platformName":"Android","deviceName":"AndroidEmulator","browserName":"Browser"}}

info: Creating new appium session af0a24a1-2375-4dda-b913-3cd5d47f1745
> ERROR: debug: executing: adb devices
> info: Trying to find a connected android device
> info: [ADB] Getting connected devices...
> warn:  killed=false, code=1, signal=null
> info: Could not find devices, restarting adb server...


Regards,
Anand

Mario

unread,
May 13, 2014, 1:14:35 PM5/13/14
to appium-...@googlegroups.com, Mario
Hi Ruben!

Thanks for following this through to add this ability into Appium. I'm not very familiar with github so I'm unsure when I will be able to benefit from this fix. Would you happen to know when this fix will be available to the public?

bootstrap online

unread,
May 13, 2014, 1:28:09 PM5/13/14
to Mario, appium-...@googlegroups.com
If you run appium from source, you can use the fix now. It'll also be
in the next release.

Mario

unread,
May 14, 2014, 5:16:55 PM5/14/14
to appium-...@googlegroups.com, Mario
I'm not too familiar with pulling down from source. I may have to look into this later but I appreciate all of you coming up with a fix so quickly.

Mario

unread,
May 14, 2014, 5:17:13 PM5/14/14
to appium-...@googlegroups.com, Mario
@Anand,

I'm not going to pretend I know Java much but from reading your posts I have a couple of suggestions that may work:

Your capability "deviceName" does not have a space between "AndroidEmulator" (look at my above posts and notice I have a space inbetween the two words).

Your defining RemoteWebDriver is using "URL" where mine in C# is using "Uri"

When you have your emulator open and running, be sure to open up a command prompt and type in "adb devices" and the state of your running emulator should be listed as something like "emulator-5554 device".

Lastly, if you would like your code to speak to the already up-and-running emulator and using its stock browser then be sure to start up Appium in the command window like so:
appium --avd NameOfYourAVD

If you are using the Appium GUI then click on the Android button near top left and then check the box near "Launch AVD" and choose your AVD (although I'm not familiar with this as much as the command line way).

Marina

unread,
May 28, 2014, 2:40:09 PM5/28/14
to appium-...@googlegroups.com, Mario

Hi Jonathan,

I have an android 4.4 tablet and I am trying to run my appium tests on the android stock browser. I am running on a real device

1. I have given the capabilities as you have mentioned 
          capabilities.setCapability("platformName", "Android");
          capabilities.setCapability("platformVersion", "4.4");
          capabilities.setCapability("deviceName", "Android");
          capabilities.setCapability("browserName", "Browser"); 


However, I am getting the following error although the android stock browser is present on the device. It came along with the device, I did not install it

error: Chromedriver create session did not work. Status was 200 and body was {"s
essionId":"7cec072032480621e154fb955f360919","status":13,"value":{"message":"unk
nown error: com.android.browser is not installed on device 3204556b707cb005\n  (
Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)"}}
info: Cleaning up appium session

When I tried to find the app-package, the app-package is actually com.sec.android.app.sbrowser and com.android.browser is not present on the device because of which it is failing


2.  I tried launching the browser app directly using the following capabilities

          capabilities.setCapability("app-package", "com.sec.android.app.sbrowser");
          capabilities.setCapability("app-activity",  ".SBrowserMainActivity");   
          capabilities.setCapability("platformName", "Android");
          capabilities.setCapability("platformVersion", "4.4");
          capabilities.setCapability("deviceName", "Android");


However I am getting the following error

debug: Request received with params: {"ms":60000,"type":"page load"}
info: Responding to client with error: {"status":9,"value":{"message":"The reque
sted resource could not be found, or a request was received using an HTTP method
 that is not supported by the mapped resource. (Original error: Invalid timeout
'page load')","origValue":"Invalid timeout 'page load'"},"sessionId":"c3c49665-7
995-401d-a9ac-2a8f1e7e39ac"}
POST /wd/hub/session/c3c49665-7995-401d-a9ac-2a8f1e7e39ac/timeouts 500 3ms - 337
b


Can you please let me know how I can resolve these errors and run my automation on the android stock browser

Thanks!

Marina

Marina

unread,
May 28, 2014, 2:45:11 PM5/28/14
to appium-...@googlegroups.com, Mario

Also I forgot to mention in point 2, the android stock browser did launch. However after launching it did not run my test . It just opened the browser and failed with the error

shamili swamy

unread,
Jun 13, 2014, 5:19:42 AM6/13/14
to appium-...@googlegroups.com, mario.j...@gmail.com
Hi Jonathan,

Have been working on Appium past few weeks and your solutions works wonders. Thanks first of all. 
I have a query. Is it possible to run in the native browser on android real device. I'm using Galaxy S4.
Below are the capabilities given,

capabilities.setCapability("device","android");
capabilities.setCapability("app", "browser");

I get the below exception,
info: Welcome to Appium v1.0.0 (REV f0a00fab2335fa88cb355ab4dc43a9cd3f3236c0)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: socket.io started
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"newCommandTimeout"
:7200,"app":"browser","device":"android"}}
info: Looks like we want chrome on android
info: Creating new appium session df0ee744-3a39-4112-b80c-631e98c417de
info: Trying to find a connected android device
info: [ADB] Getting connected devices...
debug: executing: adb devices
info: [ADB] 1 device(s) connected
info: Setting device id to 4d006716dc8d40fd
debug: Pushing unlock helper app to device...
debug: executing: adb -s 4d006716dc8d40fd install "C:\Users\Shamili VK\AppData\R
oaming\npm\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
debug: executing: adb -s 4d006716dc8d40fd shell "dumpsys window"
info: Writing dumpsys output to C:\Users\Shamili VK\AppData\Roaming\npm\node_mod
ules\appium\.dumpsys.log
debug: Screen already unlocked, continuing.
info: Creating Chrome session
info: Ensuring Chromedriver exists
info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (
`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST
/FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /
PID %b))
info: No old chromedrivers seemed to exist
info: Spawning chromedriver with: C:\Users\Shamili VK\AppData\Roaming\npm\node_m
odules\appium\build\chromedriver\windows\chromedriver.exe
info: [CHROMEDRIVER] Starting ChromeDriver (v2.9.248315) on port 9515
info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/sessio
n","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOption
s":{"androidPackage":"com.android.browser","androidActivity":"com.android.browse
r.BrowserActivity","androidDeviceSerial":"4d006716dc8d40fd"}}}}
error: Chromedriver create session did not work. Status was 200 and body was {"s
essionId":"868e8b5b154b8038dd6a15e7cc9b1a4c","status":13,"value":{"message":"unk
nown error: com.android.browser is not installed on device 4d006716dc8d40fd\n  (
Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)"}}
info: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Did not get session re
direct from Chromedriver
info: Error: Did not get session redirect from Chromedriver
    at null.<anonymous> (C:\Users\Shamili VK\AppData\Roaming\npm\node_modules\ap
pium\lib\devices\android\chromedriver.js:195:12)
    at Request._callback (C:\Users\Shamili VK\AppData\Roaming\npm\node_modules\a
ppium\lib\devices\common.js:104:5)
    at Request.self.callback (C:\Users\Shamili VK\AppData\Roaming\npm\node_modul
es\appium\node_modules\request\request.js:121:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (C:\Users\Shamili VK\AppData\Roaming\npm\node_modules
\appium\node_modules\request\request.js:978:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (C:\Users\Shamili VK\AppData\Roaming\npm\node
_modules\appium\node_modules\request\request.js:929:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:919:16
    at process._tickCallback (node.js:419:13)
info: Responding to client with error: {"status":33,"value":{"message":"A new se
ssion could not be created. (Original error: Did not get session redirect from C
hromedriver)","origValue":"Did not get session redirect from Chromedriver"},"ses
sionId":null}
POST /wd/hub/session 500 9460ms - 242b

Looking for your reply.

Thanks,
Shamili

Marina Roche

unread,
Jun 13, 2014, 6:01:19 PM6/13/14
to shamili swamy, appium-...@googlegroups.com, mario.j...@gmail.com


--
http://appium.io
---
You received this message because you are subscribed to a topic in the Google Groups "Appium-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/appium-discuss/MhtRoE4qj_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages