Skip to main content

Executing appium tests on android mobile app


Back to Appium Tutorial Index

Having learned how to execute appium tests on android mobile web now is the time to learn how appium tests can be executed on mobile app. Lets begin with installing app on emulator or device -

Installing app on emulator/device: Following are the steps to install app on emulator or device on various operating systems -


Windows:
  1. Start the console (Windows XP), Run -> type cmd, and move to the platform-tools folder of SDK directory.
  2. Paste the APK file in the 'android-sdk\tools' or 'platform-tools' folder.
  3. Then type the following command.
  4. adb install [.apk path]
  5. Example:
  6. adb install C:\Users\Name\MyProject\build\Jorgesys.apk
Linux:
  1. Copy the apk file to platform-tools in android-sdk linux folder.
  2. Open Terminal and navigate to platform-tools folder in android-sdk.
  3. Then Execute this command -
  4. ./adb install FileName.apk
  5. If the operation is successful (the result is displayed on the screen), then you will find your file in the launcher of your emulator.
Mac:
PATH=$PATH:~/Library/Android/sdk/platform-tools
Example : PATH=$PATH:/users/jorgesys/eclipse/android-sdk-mac_64/tools
Then run adb.
Mac:
1.Run the emulator,
2.then copy your .apk file and paste into /Users/your_system_username/Library/Android/sdk/platform-tools,
2.1. if you are not able to find sdk path in your mac system, do the following steps,Open finder->select Go option on top menu -> select Go to Folder option -> it will popup a window with a textfield: /Users/your_system_username/Library/Android/sdk/ -> now open platform-tools folder and paste your copied .apk file,
  1. Now open terminal and type the following: cd Library/Android/sdk/platform-tools
  2. execute the following in your terminal: ./adb install yourapkfilename.apk
4.1. if you get the following error message: error: no devices found - waiting for device - follow the step 5.
  1. Run your emulator from Android Studio, once emulator active then repeat step 4, you will see the success message on your terminal.


Analyzing app element locators -
You can use uiautomatorviewer to identify app elements and use them in tests


Finding app package and app activity - 
You need to know app package and app activity to be able to run test on mobile app.


  • If app is already installed on device/emulator then you can find name of app package and app activity from catlog, start -
adb catlog
Launch app on emulator/device
Find the appPackage and appActivity from cat log, for ex following are the appPackage and appActivity for calculator app on my android emulator -





  • You can also find app package and app activity from within appium app. Click android icon on appium app > select App Path checkbox > Choose apk file. After a while you will see Package and Launch Activity (app activity) on Android Settings window -


Screen Shot 2016-05-31 at 13.28.32.png


  • You can also use an app called apkinfo to find out app package and app activity for an app installed on device

Example app test -




And this test can be executed from testng.xml file.

Popular posts from this blog

Appium and android mobile app automation

Next appium and Android mobile app automation video tutoria l is live. If you are new to appium then please check - appium-tutorial This video tutorial covers - Start vysor (Just for this session and not mobile automation :)) Start appium and start appium inspector Desired Capabilities platformName - Android deviceName - L2N0219828001013 (as seen on "adb devices") Saved Capability Sets Start Session Scan app elements using appium inspector Get appPackage and appActivity using "APK info" app Install "APK info" app and open app whose appPackage and appActivity are required i.e. calculator Check top section of app icon com.android.calculator2 is app package com.android.calculator2.Calculator is app activity testng.xml file settings for running Android app tests Test details com.seleniumtests.tests.mobile.AndroidAppTest and CalculatorScreen class View beautiful STF test report  

Return only first or last element from webelements collection

Note: If you are new to java and selenium then start with selenium java training videos .     We often come across situation when there are multiple elements on a page and we probably like to exercise only a few of them using selenium webdriver. May be just first and last element. For example on a search result page we may like to click on only first and last link and not all. This is when Iterables API comes handy. (By the way I am assuming that you have already completed watching selenium training videos :)). Once we have collection of web element then we can use Iterables to get only first or last element as following - Consider that we fetch collection of element as - List< WebElement > webElements = getDriver().findElements(By. id ( "htmlID" ));   Now we can get the first web element from this collection as -  WebElement firstElement = Iterables. getFirst (webElements,  getDriver().findElement(By. id ( "defaultElement" )));   Herein second

Using chrome console to test xPath and css selectors

Note: If you are new to java and selenium then start with selenium java training videos .       Since the advent of selenium there have been many plugin to test xPath / css selectors but you don’t need any of them if you have chrome browser. Using Chrome console you can test both xPath and css selectors. Launch website to be tested in chrome browser and hit F-12 and you would see chrome console opened in lower pane of application - Hit escape key and console would open another pane to write element locators - And now you can start writing xPath or css selectors in chrome console and test them - The syntax for writing css id - $$(“ ”) And hit the enter key. If your expression is right then html snippet of the application element corresponding to the css selector would be displayed - If you mouse over the html snippet in chrome console then it would highlight the corresponding element in application - If you want to clean console of previously wri