Mobile Automation Using Appium
Mobile Automation Using Appium
Mobile Automation Using Appium
Introduction to Appium
Appium is an open-source tool for automating native, mobile web, and hybrid applications
on iOS and Android platforms. Native apps are those written using the iOS or Android
SDKs.Mobile web apps are web apps accessed using a mobile browser (Appium supports
Safari on iOS and Chrome or the built-in 'Browser' app on Android). Hybrid apps have a
wrapper around a "webview" -- a native control that enables interaction with web content.
Importantly, Appium is "cross-platform": it allows you to write tests against multiple
platforms (iOS, Android), using the same API. This enables code reuse between iOS and
Android test suites.
Appium Concepts
Client/Server Architecture
Appium is at its heart a webserver that exposes a REST API. It receives
connections from a client, listens for commands, executes those commands on a
mobile device, and responds with an HTTP response representing the result of
the command execution. The fact that we have client/server architecture opens
up a lot of possibilities: we can write our test code in any language that has a
http client API, but it is easier to use one of the Appium client libraries. We can
put the server on a different machine than our tests are running on. We can write
test code and rely on a cloud service like Sauce Labs to receive and interpret
the commands.
Session
Automation is always performed in the context of a session. Clients initiate a
session with a server in ways specific to each library, but they all end up sending
a POST /session request to the server, with a JSON object called the 'desired
capabilities' object. At this point the server will start up the automation session
and respond with a session ID which is used for sending further commands.
Desired Capabilities
Desired capabilities are a set of keys and values (i.e., a map or hash) sent to the
Appium server to tell the server what kind of automation session we're
interested in starting up. There are also various capabilities which can modify
the behavior of the server during automation. For example, we might set
the platformName capability to iOS to tell Appium that we want an iOS session,
rather than an Android one. Or we might set the safariAllowPopups capability
to true in order to ensure that, during a Safari automation session, we're allowed
to use JavaScript to open up new windows. See the capabilities doc for the
complete list of capabilities available for Appium.
Appium Server
Appium is a server written in Node.js. It can be built and installed from source or
installed directly from NPM.
Appium Clients
There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which
support Appium's extensions to the WebDriver protocol. When using Appium, you
want to use these client libraries instead of your regular WebDriver client. You
can view the full list of libraries here.
Appium.app, Appium.exe
There exist GUI wrappers around the Appium server that can be downloaded.
These come bundled with everything required to run the Appium server, so you
don't need to worry about Node. They also come with an Inspector, which
enables you to check out the hierarchy of your app. This can come in handy when
writing tests.
Appiums Architecture
Appium is an HTTP server written in node.js which creates and handles multiple
WebDriver sessions for different platforms like iOS and Android.
Appium starts a test case on the device that spawns a server and listens for
proxied commands from the main Appium server. It is almost same as Selenium
server which perceives http requests from selenium client libraries and it
handles those requests in different ways depending upon the platforms. Each
vendor like iOS and Android has a different way and mechanism to run a test
case on the device so Appium kind of hacks in to it and run this testcase after
listening commands from appium server.
1) Launch Appium application in Mac, Select Apple radio button if you are
running automation scripts for iOS. The default port the appium uses is
4723.
2) Use DesiredCapabilities as given below for running automation scripts for
mobile web app on IPad simulator:
1) Launch Appium application in Mac, Select Apple radio button if you are
running automation scripts for iOS. The default port the appium uses is
4723.
2) Use DesiredCapabilities as given below for running automation scripts for
hybrid app on IPad simulator:
----Tried automating mobile web apps in Android using Appium Getting some
issues-Need to update this sections------
1) Launch Appium application in Mac, Select Android radio button if you are
running automation scripts for Native app on Android. The default port the
appium uses is 4723.
2) Use DesiredCapabilities as given below for running automation scripts for
Native app on Android simulator:
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "4.4.2");
capabilities.setCapability("deviceName","Emulator");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability ("appActivity","com.android.calculator2.Calculator"); // This is Launcher
activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server
//It will launch the Calculator App in Android Device using the configurations specified in Desired
Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
I suggest you to use adb (Android Debug Bridge) tool (part of Android
SDK). So, install application under test on target Android device or
emulator. And you should run application to get current activity and
package name. So, after running app execute the following commands
from command line (android-sdk/platform-tools/adb):
adb shell dumpsys window windows | grep -E 'mCurrentFocus|FocusedApp'
And you will get something like this:
mCurrentFocus=Window{43270790 u0
com.estrongs.android.pop/com.estrongs.android.pop.view.FileExplorerActivity}
mFocusedApp=AppWindowToken{44d67b88 token=Token{435e5990 ActivityRecord{434ee320 u0
com.estrongs.android.pop/.view.FileExplorerActivity t133
So, current activity
is com.estrongs.android.pop/.view.FileExplorerActivity and application
package name is com.estrongs.android.pop is this case.
Steps:
1. Install apk on device or emulator
2. Run application
3. Execute adb shell from command line
4. Execute command to get current activity from device(shell) shell:
dumpsys window windows | grep -E 'mCurrentFocus|FocusedApp'
I hope it helps you.
Source :- http://sqa.stackexchange.com/questions/12373/android-app-testing-with-
appium/12382#12382