Appium Tutorials

Automate Mobile native applications using Appium/Selenium

Appium

Today in this post you will get the complete information about how you can automate native application using Appium

 

In previous, article we have already discussed installation and running tests on mobile chrome browser so before reading this article it is must to complete the previous post.

 

Once you are done you need to download the apk file which you want to test.

In Android application extension is .apk file.

In IOS application extension is .ipa file. 

 

I have uploaded the same tutorial on YouTube

 

 

 Steps to Automate Native application using Appium

 

  • Download .apk file for android device
  • Install in your device using ADB
  • Set .apk file in Appium and get the details about application which is required to run your test.
  • Write a test to launch the application on real device
  • Perform some action on application. (We will perform sendkeys i.e typing)

 

 

Download .apk file Appium

 

I have found an easy application which contains almost all kind of web elements.

Visit http://selendroid.io/setup.html and download .apk  file.

 

Download apk file for testing

 

 

Make sure Appium server is off.

Click on Android ICON.

 

Check the checkbox before application path

Browse the .apk file which we downloaded at 1st step.

 

Run the Appium server

Click on Android ICON.

Copy Package and Launch activity.

 

Appium-Settings

 

 

We need to deploy application in our local device as well.

Open cmd

Type  > adb devices

This will display the device which is connected.

 

Type > adb install give-apk-file-path-with-application

 

Application_deployed

 

 

Once it is deployed to your  device you will get a success message.

 

Android-App

 

 

 Program to automate Native application using Appium

 

package demo;

import io.appium.java_client.android.AndroidDriver;

import java.io.File;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.concurrent.TimeUnit;



import org.openqa.selenium.By;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;



public class StartApplication {

                             
// create global variable

private static AndroidDriver driver;

public static void main(String[] args) throws MalformedURLException, InterruptedException 
{


 // Create object of DesiredCapabilities class                             

DesiredCapabilities capabilities = new DesiredCapabilities();



// Optional

capabilities.setCapability(CapabilityType.BROWSER_NAME, "");


// Specify the device name (any name)

capabilities.setCapability("deviceName", "My New Phone");


// Platform version

capabilities.setCapability("platformVersion", "4.4.2");


// platform name

capabilities.setCapability("platformName", "Android");


// specify the application package that we copied from appium                

capabilities.setCapability("appPackage", "io.selendroid.testapp");


// specify the application activity that we copied from appium                   

capabilities.setCapability("appActivity", ".HomeScreenActivity");

 
// Start android driver I used 4727 port by default it will be 4723

driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);



// Specify the implicit wait of 5 second

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);



// Enter the text in textbox

driver.findElement(By.xpath("//android.widget.EditText[@content-desc='my_text_fieldCD']")).sendKeys("Mukesh Selenium Appium");


// click on registration button  
                                   
driver.findElement(By.id("io.selendroid.testapp:id/startUserRegistration")).click();



// Wait for 10 second

Thread.sleep(10000);



// close the application
 driver.quit();



                }



}

 

 

Run the program and enjoy the native test automation.

 

This is just a small program just to make sure everything is up and running.

I took very basic application to automate Native application using Appium but you can take any application and perform the same step.

 

In next article I will cover how you can perform other activity on application using xpath and other ways.

If you liked this article then please share with your friends or team.

 

Feel free to comment in case any issue.

 

You can like our Facebook Page for more updates Learn Automation Page
Join our facebook group for any query Selenium Group Discussion

 

 

 

 

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

29 thoughts on “Automate Mobile native applications using Appium/Selenium

  1. Roshni D. says:

    Hi Mukesh,

    Thanks for your videos,
    Can you please help how to hit the mobile application via Proxy ? I need a help to implement the proxy for Mobile App.

    1. Hi Roshni, you can use Proxy class from Selenium and then use the same for AppiumDriver.

  2. Akash says:

    Hi Mukesh, I am referring your tutorial in 2019, can you do one more video on mobile testing with latest android version, latest appium version and NOX android emulator.

  3. rajatouseef says:

    videos are awesome
    waiting for next video how you get x path and id
    in native app.
    thanks mukesh

    1. Hi there,

      Very soon I’ll post it.

  4. Pradeep B B says:

    In Appium framework, Package and Launch activity is blank even though I checked d check box, can you please help me, bt sample selendroid.apk is installed in my device

  5. thulashi says:

    Thank you Mukesh, its really helpful

  6. jayesh says:

    Thanks

  7. jayesh says:

    Hi Mukesh…Thanks for your excellent tutorial & documention…I have been following this for long time. I need your suggestion in one place where I stuck..I alreday posted the issue in slack and some forums –[http://stackoverflow.com/questions/40643411/appium-webview-switch-not-working-in-ubuntu] can you please this link and help

    1. No idea about Linux 🙁

  8. Anjali Kashyap says:

    Hi mukesh,
    While running the program you mentioned in your post, I got below error:
    Failed to start an Appium session, err was: Error: ‘java -version’ failed. Error: spawn ENOENT

    1. Hi Anjali,

      Is this fixed? Kindly update appium to latest version and run the same code again.

  9. Richa Shrivastava says:

    Hi Mukesh,

    I am using windows machine currently
    If I want to test on my app on iphone then can I simply change something in above script and run it? OR I have to setup everything on Mac machine?

    1. Hi Richa,

      You need mac machine in order to run or test IOS app.

      Below video will help

      If you dont have MAC then check below video

  10. Lokesh says:

    Hi Mukesh,
    I have been following you on youtube videos and they are good.I like the way you have explained it and the communication is the key.

    I am at automation engineer been working on Appium, I am stuck with doing scroll on Mobile Apps for both iOS and Android, will be helpful if you could link me to those videos on how to do it, or give me an example for any app which it is implemented and working fine.

    Or else if you could help me i can share you the .apk/.ipa file of the App which i am working on.

    Look forward to hear back from you.

    Regards,
    Lokesh

    1. Hi Lokesh,

      Note- Kindly use java-client jar less than 4.0 version then only below post will help.

      Below post will work

      https://vistasadprojects.com/mukeshotwani-blogs-v2/scroll-in-appium-for-android-and-ios/

  11. Ankur Gupta says:

    Hi Mukesh,

    I would like to say thank you for the all videos you have uploaded till now. Videos are totally awesome. You have explained small to small very clearly.
    Please upload some more videos on Appium tool. This is my request to you.

    1. Hey Ankur,

      Thanks 🙂 yes Appium videos are in pipeline so will upload soon

  12. santosh singh says:

    Hi Mukesh,
    i am new in appium and learn lot of concept from your site ,some confusion i am craeate script for mobile Automation but some time i am my appium server is not start so what can i do and i am wriing all functionality code but some time it works and some time it fails.
    package gotuktuk;

    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;

    import io.appium.java_client.android.AndroidDriver;

    public class StartApplication {

    private static RemoteWebDriver driver;

    public static String phoneNum = “9926895346”;
    public static String pickUpAdd = “Corporate House, Rabindranath Tagore Marg, Chhoti Gwaltoli, Indore, Madhya Pradesh”;
    public static String dropAdd = “301/4 Nehru Nagar, Patni Pura Indore, Madhya Pradesh 452001”;

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
    System.out.println(“**************************start***********************************”);
    File classpathRoot = new File(System.getProperty(“user.dir”));
    System.out.println(“USER DIR : “+System.getProperty(“user.dir”));
    File appDir = new File(classpathRoot, “/Android/data/”);
    File app = new File(appDir, “RIDER.apk”);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, ” “);
    capabilities.setCapability(“deviceName”, “Galaxy j5(2016)”);
    capabilities.setCapability(“platformVersion”, “6.0.1”);
    capabilities.setCapability(“platformName”, “Android”);
    capabilities.setCapability(“app”, app.getAbsolutePath());
    capabilities.setCapability(“appPackage”, “in.gotuktuk.rider”);
    //capabilities.setCapability(“appActivity”, “com.tuktuk.corelib.ui.activity.LogoSplashActivity”);
    driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

    //Thread.sleep(4000);
    setPhoneNumber(phoneNum);
    Thread.sleep(20000);
    getMenu();
    // Thread.sleep(20000);
    // getHistory();
    // Thread.sleep(5000);
    // getRateCard();

    //setCurrentPickupLocation(pickUpAdd);
    //seeRateCard(dropAdd);

    // driver.quit();
    System.out.println(“**********************************End***********************************”);
    }

    private static void setPhoneNumber(String phoneNum2) {
    // TODO Auto-generated method stub
    System.out.println(“==>Entering phone number ..”);
    driver.findElement(By.id(“in.gotuktuk.rider:id/phoneNumberEditText”)).sendKeys(phoneNum2);
    driver.findElement(By.id(“in.gotuktuk.rider:id/verifySMSButton”)).click();
    System.out.println(“==>Clicked on Button ..”);
    }

    private static void seeRateCard(String dropAdd2) throws InterruptedException {
    // TODO Auto-generated method stub
    System.out.println(“==>Entering drop address ..”);
    driver.findElement(By.className(“android.widget.RelativeLayout”)).findElements(By.id(“0”));
    Thread.sleep(5000);
    driver.findElement(By.id(“in.gotuktuk.rider:id/staticComponentDropAddressTextView”)).getAttribute(dropAdd2);
    System.out.println(“==>Clicked on Rate Card Button ..”);
    }

    private static void setCurrentPickupLocation(String pickUpAdd2) throws InterruptedException {
    // TODO Auto-generated method stub
    System.out.println(“==>Setting current address ..”);
    driver.findElement(By.id(“in.gotuktuk.rider:id/myLocationImageView”)).click();
    Thread.sleep(2000);
    //driver.findElement(By.id(“in.gotuktuk.rider:id/bookingButtonActionEnableTextView”)).click();
    System.out.println(“==>Clicked on Button ..”);
    }

    private static void getMenu() throws InterruptedException {
    // TODO Auto-generated method stub
    //Thread.sleep(3000);
    System.out.println(“==>in get menu ..”);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    Thread.sleep(7000);
    System.out.println(“==>Clicking on History ..”);
    driver.findElement(By.name(“HISTORY”)).click();
    Thread.sleep(3000);
    driver.findElement(By.className(“android.support.v7.app.ActionBar$Tab”)).click();
    Thread.sleep(5000);
    System.out.println(“==>Back button from history ..”);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    Thread.sleep(5000);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    Thread.sleep(5000);
    System.out.println(“==>Clicking on tCash ..”);
    driver.findElement(By.name(“tCASH”)).click();
    System.out.println(“==>Clicking on SHARE REFERRAL CODE ..”);
    Thread.sleep(3000);
    //driver.findElement(By.id(“in.gotuktuk.rider:id/tCashSocialMediaShareView”)).click();
    System.out.println(“==>Back button from refereal code ..”);
    driver.findElement(By.className(“android.widget.ImageButton”)).click();
    //driver.findElement(By.className(“android.widget.ImageButton”)).click();
    driver.findElement(By.className(“in.gotuktuk.rider:id/menu_row_name”)).click();
    }

    private static void getHistory() {
    // TODO Auto-generated method stub
    driver.findElement(By.id(“in.gotuktuk.rider:id/menu_row_icon”)).click();
    }

    private static void getRateCard() {
    // TODO Auto-generated method stub
    driver.findElement(By.className(“in.gotuktuk.rider:id/menu_row_icon”)).click();
    }
    private static void Notification() {
    // TODO Auto-generated method stub
    System.out.println(“==>Back button from refereal code ..”);

    driver.findElement(By.className(“in.gotuktuk.rider:id/menu_row_name”)).click();
    driver.quit();
    }
    }
    so can you share me this type of solution

    1. Hey Santosh,

      We need to find out the pattern and then we need to make changes. Run multiple time and when it fails try to collect logs, then only we can make the changes.

  13. cg says:

    Hello! Awesome tutorials! I was wondering how to integrate appium with jenkins? Also what if you don’t have a local jenkins server? Thanks!

    1. Hi CG,

      Thanks for nice feedback.

      Process to integrate with jenkins will be same.

      Kindly refer below link

      https://vistasadprojects.com/mukeshotwani-blogs-v2/selenium-integration-with-jenkins/

      If Jenkins is on server then you need to create slave on local machine then you can trigger the test.

  14. Suresh Shaw says:

    Gr8 article Mukesh. Thanks. Plz tell me how to take xpath in mobile native app

  15. Nil says:

    Can you tell me how to use Appium inspector in windows 7

    1. Hi Nil,

      I use UIAutomateViewer to inspect the elements.

  16. Yuval says:

    Thank you for sharing this information, I also shared this with your links and name at http://www.qatestingtools.com/testing-tool-article/Automate%20Mobile%20native%20application
    will be happy to share of your articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.